Skip to main content
September 12, 2023
Question

How to avoid appending empty rows in array record type

  • September 12, 2023
  • 2 replies
  • 0 views

Hi Team,

I have a requirement for creating an audit table in that i need compare the existing data and updated data and need to add only changed field values. for this 1st I'm querying the existing data in a local var, then after changing some fields in the UI, I'm performing a save into operation which involves a!foreach which compares the queried data & UI rule input fields so when there is a difference I'm appending one row for that changed field in audit record type rule input(array). but if there is no change I no need empty- row in audit table. but some how my code appending empty rows for fields with no changes. 

Kindly provide suggestion it'll be helpful.

Thanks in advance



here I didn't change anything in one field but it gets adding null value

    2 replies

    stefanhelzle0001
    Brainy
    September 12, 2023

    Appian Expressions follows a functional approach in which you cannot update a variable. You try to do that in your foreach.

    One of my job interview questions is: "In which cases do you use an append() inside a foreach?" Answer: "Never!"

    Remove the append() from that foreach and let it just create a list of records. Then wrap it into a reject(isnull(_), <FOREACH>) to get rid of the null values.

    September 12, 2023
    • Thanks a lot stefan