Skip to main content
madhup0003
January 21, 2025
Question

Save only updated data from a given array

  • January 21, 2025
  • 10 replies
  • 0 views

Hi All,

I have a query if we have two array one is local!finalGridData and second one is local!origionalData.

In the local!finalgridData i have updated data 

local!finalGridData containing data like-

1. id:1, enddate: 21/01/2025 , 

 id:1, endDate: 20/01/2025,

id: 1, endDate: 19/01/2025

2. id:2, enddDate: 17/01/2025,

id:2,enddate:15/01/2025

local!origionalData containing data like-

local!finalGridData containing data like-

1. id:1, enddate: 15/01/2025 , 

 id:1, endDate: 16/01/2025,

id: 1, endDate: 14/01/2025

2. id:2, enddDate: 17/01/2025,

id:2,enddate:15/01/2025

now we can see in local!finalGridData i have some updated data with endDate , but it also have data for id:2 which is not updated.

so i want to fetch only updated data from local!finalGridData .

 in this scenario id:2 data is not updated but in some cases it will update if user updated the date from UI .

if both ids data updated then it's ok to send all the data but if not for all ids then i have to send only updated data in submit button.

so please anyone can help me on this.Thanks in advance

    10 replies

    stefanhelzle0001
    January 21, 2025

    What did you try so far? I mean, this is not more than a foreach() on the your final data, and a condition to either include or exclude the data from the resulting list.

    madhup0003
    January 21, 2025

    Hi stefanhelzle0001,

    i have tried this, but it's not working 

    a!save(local!test,
    a!forEach(
    items: local!finalgridData,
    expression: if(
    fv!item.endDate=index(local!originalData.data,
    wherecontains(touniformstring(fv!item.endDate),
    touniformstring(local!originalData.data.endDate)),{}).endDate,
    remove(fv!item, index(local!originalData,
    wherecontains(touniformstring(fv!item.referenceNumber),touniformstring(local!originalData.data.referenceNumber), ),{})),
    fv!item

    )),



    )

    stefanhelzle0001
    January 21, 2025

    jayaprakashr0001
    January 21, 2025

    HI [mention:29737913d085458190bfc861db9c1d95:e9ed411860ed4f2ba0265705b8793d05] ,

     As per my understanding you need only the data that is modified to store. You can use the difference() to get the modified data.

    The below code might help.

    a!localVariables(
      local!options:{"Yes","No"},
      local!originalGridData:a!refreshVariable(
        value: {
          a!map(id:"1",date:date(2025,1,15)),
          a!map(id:"1",date:date(2025,1,16)),
          a!map(id:"1",date:date(2025,1,14)),
          a!map(id:"2",date:date(2025,1,17)),
          a!map(id:"2",date:date(2025,1,15)),
        },
        refreshOnReferencedVarChange: false()
      ),
      local!changedData,
      local!finaldata:local!originalGridData,
      {
      a!gridLayout(
        headerCells: {
          a!gridLayoutHeaderCell(label:"Id"),
          a!gridLayoutHeaderCell(label:"Date"),
        },
        columnConfigs: {
          a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
          a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
        },
        rows: a!forEach(
          items: local!finaldata,
          expression: a!gridRowLayout(
            contents: {
             a!textField(
               value: fv!item.id,
               saveInto: fv!item.id
             ),
             a!dateField(
               value: fv!item.date,
               saveInto: fv!item.date
             )
            }
          )
        ),
      ),
      a!buttonArrayLayout(
        buttons: {
          a!buttonWidget(
            label:"Save",
            saveInto: {
              a!save(local!changedData,difference(local!finaldata,local!originalGridData))
            }
          )
        }
      ),
      /*Changed data*/
      a!gridField(
        data: local!changedData,
        columns: {
          a!gridColumn(
            label:"Id",
            value: fv!row.id
          ),
          a!gridColumn(
            label:"Date",
            value: fv!row.date
          )
        },
        borderStyle: "STANDARD"
      )
      }
    )

    madhup0003
    January 21, 2025

    thanks jayaprakashr0001

    yes i need only that data which is modified in local!finalGirddata, but i can't use grid for that even difference  will not work

    jayaprakashr0001
    January 21, 2025

    Can  you elaborate your scenario some more  and you are trying it in interface or expression rule.

    difference will work