Skip to main content
June 14, 2025
Question

foreach record update record field with index

  • June 14, 2025
  • 5 replies
  • 0 views

I wanted to update record field with fv!index.

I have

Recrod type

filed1,

field2,

field3

field3 should update with foreach index

    5 replies

    stefanhelzle0001
    June 14, 2025

    I do not understand what you want to achieve. Please describe in more detail.

    mymilestonec978127
    June 15, 2025

    If you're looping through records using a foreach, you can use an index to update field3 like this:

    int index = 0;
    foreach (var record in records)
    {
    record.field3 = index;
    index++;
    }
     

    This way, field3 will hold the index value for each record. Let me know if you're using a different language or structure cuz i told you what i understood

    mymilestonec978127
    June 15, 2025

    If you're looping through records using a foreach, you can use an index to update field3 like this:

    int index = 0;  
    foreach (var record in records)  
    {  
        record.field3 = index;  
        index++;  
    }
    

    This way, field3 will hold the index value for each record. 

    shubhama926776
    June 16, 2025

    Do you want to update records in a record type where field3 should contain each record's position/index in the list?

    varuntejg243705
    June 16, 2025

    Hi [mention:9db259808ae24c388bcfc9ab2f9a484c:e9ed411860ed4f2ba0265705b8793d05] ,

    if you are referring to update a single field of a record type in a!foreach() using fv!index,this could be possible.



    You need to write saveInto to rule input inorder to pass data from interface to PM if using action.

    a!localVariables(
      local!data: index(
        rule!HDS_getRequestData(returnData: true()),  /*use your rule*/
        enumerate(5) + 1
      ),
      a!forEach(
        items: { 1, 2, 3, 4, 5 },
        expression: a!update(
          local!data,
          recordtype!HDS Request.assetId,   /*use field*/
          fv!index
        )
      )
    )