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

  • So you can write you own (in Appian). Here's some initial guidance:

    • use a!keys() on your first record instance to extract the record attributes
    • for each extracted attribute, test if recordA[fv!item] = recordB[fv!item]  - if it does, it's a match. If it doesn't then it's not (you could out put the actual values in either or both cases if you wished
    • either way, you can generate a map() with attributes that contain the result, and the values from each record's corresponding attribute 
    • because you can define an expression with rule inputs of 'Any Type' then you could pass in your record instances of any type into that expression and you'd have the generic solution you're looking for

    Out of curiosity, what is the use case here? Are you looking to provide an audit solution that compares two different versions of the data between two rows of data (read into Appian as records)? If so, there's still a missing piece of the puzzle. You will need to be able to map each record/attribute's technical name to a name a business auditor would recognize so that you can present this to an end-user.

  • 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
        )
      )
    )

  • 0
    Certified Lead Developer

    For what purpose? What do you want to achieve with the results?