Appian Community and Appian Academy are being upgraded. As a part of the upgrade, Appian Community is currently in read-only mode, and user registration is disabled until August 3. We apologize for any inconvenience this may cause, but a more secure, stable, and performant Community experience is coming soon!

The new Appian Community launches August 3, followed by Appian Academy on August 7. During the migration, Appian Community Edition, Appian Academy, Documentation, Certifications, Instructor-led Customer Training, Partner Sales Training & Accreditation, and Forum (for Appian Partners and Customers only) will remain available.

How to find different property of two objects.

I have two objects they all the same type. I want to compare the two objects and extract which properties are different. Besides using a loop to iterate, is there a better way?

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    Without Loop is not possible.
    No built-in way to dynamically index multiple properties without iteration.

    a!localVariables(
      local!employee1: {
        name: "John",
        age: 30,
        dept: "IT",
        salary: 50000
      },
      local!employee2: {
        name: "John",
        age: 35,
        dept: "IT", 
        salary: 55000
      },
    
      /* Get all property names */
      local!allKeys: a!keys(local!employee1),
    
      /* Check which properties are different */
      local!areEqual: a!forEach(
        local!allKeys,
        index(local!employee1, fv!item) = index(local!employee2, fv!item)
      ),
    
      /* Find properties with different values */
      local!differentProps: index(
        local!allKeys,
        wherecontains(false, local!areEqual),
        null
      ),
    
      /* Show results */
      {
        differentProperties: local!differentProps,
    
        oldValues: a!forEach(
          local!differentProps,
          index(local!employee1, fv!item, null)
        ),
        /* Output: {30, 50000} */
    
        newValues: a!forEach(
          local!differentProps,
          index(local!employee2, fv!item, null)
        )
        /* Output: {35, 55000} */
      }
    )

Reply
  • +1
    Certified Lead Developer

    Without Loop is not possible.
    No built-in way to dynamically index multiple properties without iteration.

    a!localVariables(
      local!employee1: {
        name: "John",
        age: 30,
        dept: "IT",
        salary: 50000
      },
      local!employee2: {
        name: "John",
        age: 35,
        dept: "IT", 
        salary: 55000
      },
    
      /* Get all property names */
      local!allKeys: a!keys(local!employee1),
    
      /* Check which properties are different */
      local!areEqual: a!forEach(
        local!allKeys,
        index(local!employee1, fv!item) = index(local!employee2, fv!item)
      ),
    
      /* Find properties with different values */
      local!differentProps: index(
        local!allKeys,
        wherecontains(false, local!areEqual),
        null
      ),
    
      /* Show results */
      {
        differentProperties: local!differentProps,
    
        oldValues: a!forEach(
          local!differentProps,
          index(local!employee1, fv!item, null)
        ),
        /* Output: {30, 50000} */
    
        newValues: a!forEach(
          local!differentProps,
          index(local!employee2, fv!item, null)
        )
        /* Output: {35, 55000} */
      }
    )

Children