Requesting for logic

Certified Associate Developer

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.

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    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.

  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    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 | @harshit bump

Reply
  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    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 | @harshit bump

Children