Help with Expression Rules

Hi All,

Am new to Appian and have been stuck with an expression rule for past couple of days with no luck. Following is what am planning to do and pasting my code as well for your expert advise.

My intend:

(a) there are two CDT arrays, one with BEFORE data and another with AFTER change data. I want to compare the field 5 on BEFORE and AFTER to pick the CHANGED ones

(b) need to save these into a new CDT array which has a different layout from inputCDTArray (BEFORE and AFTER)

Here the expression rule is not returning the new CDT array. How do I get the expression rule return the CDT array, so i can use it to WRITEINTO data entity ?

My code is below:

load(
local!counter: 1,
local!finalCDTArray:cast(typeof({'type!{urn:com:appian:types}FTDM_finalCDTArray'()}),ri!finalCDTArray),
{
a!forEach(
items: ri!inputCDTArrayBefore,
expression: {
if(not(exact(fv!item.field5,ri!inputCDTArrayAfter[fv!index].field5)),
{
a!save(ri!finalCDTArray[local!counter].fieldid1,fv!item.field1),
a!save(ri!finalCDTArray[local!counter].field2,fv!item.field2),
a!save(ri!finalCDTArray[local!counter].producttypecode,fv!item.field3),
a!save(ri!finalCDTArray[local!counter].productfunctionaltype,fv!item.field4),
a!save(ri!finalCDTArray[local!counter].field5,fv!item.field5),
a!save(ri!finalCDTArray[local!counter].field6,0),
a!save(ri!finalCDTArray[local!counter].fielduser7,ri!processInitiator),
a!save(ri!finalCDTArray[local!counter].fielddate8,now()),

a!save(local!counter,local!counter+1),

a!save(ri!finalCDTArray[local!counter].field2,ri!inputCDTArrayAfter[fv!index].field2),
a!save(ri!finalCDTArray[local!counter].field3,ri!inputCDTArrayAfter[fv!index].field3),
a!save(ri!finalCDTArray[local!counter].field4,ri!inputCDTArrayAfter[fv!index].field4),
a!save(ri!finalCDTArray[local!counter].field5,ri!inputCDTArrayAfter[fv!index].field5),
a!save(ri!finalCDTArray[local!counter].field6,1),
a!save(ri!finalCDTArray[local!counter].field7,ri!processInitiator),
a!save(ri!finalCDTArray[local!counter].fielddate8,now())

},
{})
}
)
}
)

  • Hi

    As per your code I think You want to pick that index from the array who's value has been changed and save it into a different cdt

    Instead of casting it directly, try assigning values to each field of the cdt.

    load(
      
      local!beforeCdt: {{field1:"Test1",field2:"abc",field5:"123"},{field1:"Test2",field2:"def",field5:"456"},{field1:"Test3",field2:"ghi",field5:"789"}},
      local!afterCdt: {{field11:"Test1",field2:"abc",field5:"1023"},{field1:"Test12",field2:"def",field5:"4056"},{field1:"Test13",field2:"ghi",field5:"789"}},
      local!finalCdt:
      a!forEach(local!beforeCdt,
        'type!{http://www.test.com./TEST/}CM_CLAIM_TYPE'(
          PHASE:fv!item.field1,
          PROJ_CONTRACT: fv!item.field2,
          DESIGN_TYPE: if(exact(fv!item.field5,local!afterCdt.field5[fv!index]),fv!item.field5,local!afterCdt.field5[fv!index])
        )
      ),
      local!changedCdt:
      a!forEach(local!beforeCdt,
        
          if(
            exact(fv!item.field5,local!afterCdt.field5[fv!index]),
            {},
            'type!{http://www.test.com/TEST/}CM_CLAIM_TYPE'(
            PHASE:fv!item.field1,
            PROJ_CONTRACT: fv!item.field2,
            DESIGN_TYPE: local!afterCdt.field5[fv!index]
            
          )
          
        )
      ),
      local!changedCdt
    )

 Discussion posts and replies are publicly visible