Skip to main content
shukurs2366
May 29, 2023
Solved

Requesting for logic

  • May 29, 2023
  • 4 replies
  • 0 views

I have two values consider type is CDT: 

local!oldData: {
customer: "oldCustomer",
location:"Hyd",
supplier: "ABC"
},

local!updatedData: {
customer: "newCustomer",
location: "Hyd",
supplier: "DEF"
}

I want to give response only the updated values like follows:

fieldName: customer
oldValue: oldCustomer,
newValue: newCustomer,

fieldName: supplier,
oldValue: ABC,
newValue: DEF

Can anyone please help me to build logic for it.

    Best answer by stefanhelzle0001

    The a!keys() function gives you the list of keys in your dictionary. Use a foreach to loop on that list and compare the two values from each dictionary. Pretty straight forward...

    Give it a try and come back when you have something working.

    4 replies

    stefanhelzle0001
    May 29, 2023

    The a!keys() function gives you the list of keys in your dictionary. Use a foreach to loop on that list and compare the two values from each dictionary. Pretty straight forward...

    Give it a try and come back when you have something working.

    shukurs2366
    May 29, 2023

    a!localVariables(
      local!oldCargo: cast(
        typeof(
          'type!{urn:com:appian:types:peg:car}PEG_CAR_Cargo'()
        ),
        rule!PEG_CAR_QRY_getCargo(cargoIds: ri!cargoId)
      ),
      local!newCargo: cast(
        typeof(
          'type!{urn:com:appian:types:peg:car}PEG_CAR_Cargo'()
        ),
        index(ri!formattedData, "Cargo", null)
      ),
      local!updatedFields: a!keys(local!newCargo),
      a!forEach(
        local!updatedFields,
        a!localVariables(
          local!field: fv!item,
          local!oldValue: local!oldCargo[local!field],
          local!newValue: local!newCargo[local!field],
          if(
            local!oldValue <> local!newValue,
            a!map(
              "fieldName": local!field,
              "oldValue": local!oldValue,
              "newValue": local!newValue
            ),
            null
          )
        )
      )
    )


    Thank you [mention:126a676c85024855948336691b0a7b92:e9ed411860ed4f2ba0265705b8793d05] | @harshit bump

    harshitb6843
    May 29, 2023

    Glad to help @Shukur Shake :)

    harshitb6843
    May 29, 2023