Is there any way to compare two record values of same record type to find the difference?

Certified Senior Developer

I have the requirement to find the difference between two record values of a record type like we do in case of cdts using cdtdifference(). I have the previous value of record type and then new value, I need to populate Audit table using these difference values.

Any function like cdtdifference() or any workaround to do this?

  Discussion posts and replies are publicly visible

Parents Reply
  • 0
    Certified Lead Developer
    in reply to sreesudhakasibatla

    There is no purpose built function but it's pretty easy to do with code:

    a!localVariables(
      local!oldEntity: a!map(
        firstName: "John",
        lastName: "Smith",
        age: "23"
      ),
      local!newEntity: a!map(
        firstName: "Jane",
        lastName: "Smith",
        age: "24"
      ),
      reject(
        a!isNullOrEmpty,
        a!forEach(
          items: a!keys(local!oldEntity),
          expression: a!localVariables(
            local!oldValue: index(local!oldEntity, fv!item, null),
            local!newValue: index(local!newEntity, fv!item, null),
            if(local!oldValue <> local!newValue,
              {
                fieldName: fv!item,
                oldValue: local!oldValue,
                newValue: local!newValue
              },
              null
            )
          )
        )
      ) 
    )

Children