Comparison for two rows of same record data

Certified Senior Developer

We have a requirement for comparison of same record type data and get the difference of the data & columns. We are aware of "CDT Diff Utilities" which does the same operation and gives the expected output. However we are looking for similar way of plugin availability or workaround to achieve the desired functionality.

Note: We are not looking for manual comparison of the record fields and the data, as we need to perform the comparison across all record types in the application and it will be become very tedious process to achieve by manual comparison.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    We are using a similar approach. Have a look at it.
    I am not sure about your use case, but I hope this helps with what you are expecting.
    Happy to discuss your use case if this is not what you are looking for.
    We created reusable expression.
    Inputs:
    1) oldRecord (Define ri! as AnyType)
    2) newRecord (Define ri! as AnyType)

    a!localVariables(
      local!allFields: union(
        a!keys(ri!oldRecord),
        a!keys(ri!newRecord)
      ),
      local!differences: reject(
        a!isNullOrEmpty,
        a!forEach(
          items: local!allFields,
          expression: a!localVariables(
            local!fieldName: fv!item,
            local!oldValue: index(ri!oldRecord, local!fieldName, null),
            local!newValue: index(ri!newRecord, local!fieldName, null),
            local!oldText: if(
              isnull(local!oldValue),
              "",
              tostring(local!oldValue)
            ),
            local!newText: if(
              isnull(local!newValue),
              "",
              tostring(local!newValue)
            ),
            local!isDifferent: if(
              and(
                isnull(local!oldValue),
                isnull(local!newValue)
              ),
              false,
              if(
                or(
                  isnull(local!oldValue),
                  isnull(local!newValue)
                ),
                true,
                not(exact(local!oldText, local!newText))
              )
            ),
            if(
              local!isDifferent,
              a!map(
                fieldName: local!fieldName,
                oldValue: if(
                  isnull(local!oldValue),
                  null,
                  local!oldValue
                ),
                newValue: if(
                  isnull(local!newValue),
                  null,
                  local!newValue
                ),
                changeType: if(
                  and(
                    isnull(local!oldValue),
                    not(isnull(local!newValue))
                  ),
                  "ADDED",
                  and(
                    not(isnull(local!oldValue)),
                    isnull(local!newValue)
                  ),
                  "REMOVED",
                  "MODIFIED"
                ),
                dataType: typeof(local!newValue)
              ),
              null
            )
          )
        )
      ),
      /* Count changes manually */
      local!addedCount: length(
        where(
          a!forEach(
            items: local!differences,
            expression: index(fv!item, "changeType", "") = "ADDED"
          )
        )
      ),
      local!modifiedCount: length(
        where(
          a!forEach(
            items: local!differences,
            expression: index(fv!item, "changeType", "") = "MODIFIED"
          )
        )
      ),
      local!removedCount: length(
        where(
          a!forEach(
            items: local!differences,
            expression: index(fv!item, "changeType", "") = "REMOVED"
          )
        )
      ),
      a!map(
        recordType: typeof(ri!oldRecord),
        hasChanges: length(local!differences) > 0,
        totalChanges: length(local!differences),
        differences: local!differences,
        totalFields: length(local!allFields),
        summary: a!map(
          fieldsAdded: local!addedCount,
          fieldsModified: local!modifiedCount,
          fieldsRemoved: local!removedCount
        )
      )
    )

Reply
  • 0
    Certified Lead Developer

    We are using a similar approach. Have a look at it.
    I am not sure about your use case, but I hope this helps with what you are expecting.
    Happy to discuss your use case if this is not what you are looking for.
    We created reusable expression.
    Inputs:
    1) oldRecord (Define ri! as AnyType)
    2) newRecord (Define ri! as AnyType)

    a!localVariables(
      local!allFields: union(
        a!keys(ri!oldRecord),
        a!keys(ri!newRecord)
      ),
      local!differences: reject(
        a!isNullOrEmpty,
        a!forEach(
          items: local!allFields,
          expression: a!localVariables(
            local!fieldName: fv!item,
            local!oldValue: index(ri!oldRecord, local!fieldName, null),
            local!newValue: index(ri!newRecord, local!fieldName, null),
            local!oldText: if(
              isnull(local!oldValue),
              "",
              tostring(local!oldValue)
            ),
            local!newText: if(
              isnull(local!newValue),
              "",
              tostring(local!newValue)
            ),
            local!isDifferent: if(
              and(
                isnull(local!oldValue),
                isnull(local!newValue)
              ),
              false,
              if(
                or(
                  isnull(local!oldValue),
                  isnull(local!newValue)
                ),
                true,
                not(exact(local!oldText, local!newText))
              )
            ),
            if(
              local!isDifferent,
              a!map(
                fieldName: local!fieldName,
                oldValue: if(
                  isnull(local!oldValue),
                  null,
                  local!oldValue
                ),
                newValue: if(
                  isnull(local!newValue),
                  null,
                  local!newValue
                ),
                changeType: if(
                  and(
                    isnull(local!oldValue),
                    not(isnull(local!newValue))
                  ),
                  "ADDED",
                  and(
                    not(isnull(local!oldValue)),
                    isnull(local!newValue)
                  ),
                  "REMOVED",
                  "MODIFIED"
                ),
                dataType: typeof(local!newValue)
              ),
              null
            )
          )
        )
      ),
      /* Count changes manually */
      local!addedCount: length(
        where(
          a!forEach(
            items: local!differences,
            expression: index(fv!item, "changeType", "") = "ADDED"
          )
        )
      ),
      local!modifiedCount: length(
        where(
          a!forEach(
            items: local!differences,
            expression: index(fv!item, "changeType", "") = "MODIFIED"
          )
        )
      ),
      local!removedCount: length(
        where(
          a!forEach(
            items: local!differences,
            expression: index(fv!item, "changeType", "") = "REMOVED"
          )
        )
      ),
      a!map(
        recordType: typeof(ri!oldRecord),
        hasChanges: length(local!differences) > 0,
        totalChanges: length(local!differences),
        differences: local!differences,
        totalFields: length(local!allFields),
        summary: a!map(
          fieldsAdded: local!addedCount,
          fieldsModified: local!modifiedCount,
          fieldsRemoved: local!removedCount
        )
      )
    )

Children
No Data