local variable

Certified Associate Developer

hi, 

I have a local variable "array of object" ,

I need to update value "seenBy" for one field in all array objects,

 a!flatten(a!forEach(
            items:  local!msg,
            expression: {
                a!save(fv!item.id,fv!item.id),
                a!save(fv!item.isDeleted,fv!item.isDeleted),
                a!save(fv!item.createdBy,fv!item.createdBy),
                a!save(fv!item.messageText,fv!item.messageText),
                a!save(fv!item.convId,fv!item.convId),
                a!save(fv!item.createdOn,fv!item.createdOn),
                a!save(fv!item.seenby,concat(fv!item.seenBy, concat(tostring(loggedInUser()) , ",") ),
                ),

            }
          )

          ),
a!startProcess(
  processModel: cons!COM_Write_AllMsg_SeenBy,
  processParameters: {
    allmsg: ri!allmsg,
    
  }
),

but the issue is :- 

"An error occurred while trying to write to the data store [chatDS]. No values have been written. Details: Could not execute JDBC batch update (APNX-1-4208-004)"

I think its because the expression send empty object to the process model:-

" [id=, convId=, messageText=, createdOn=, createdBy=, isDeleted=, seenBy=]   ",

 I need something to send the same array of object with same data  and just update in "seenBy" field

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    There's a fairly tedious solution, which makes a good bit of code, but it's reliable and works with Appian right out of the box.  You use type! constructor in a forEach.

    a!forEach(

    items: yourArray,

    expression: type!<yourCDTsName>(

    field1: fv!item.field1,

    field2: fv!item.field2,

    field3: fv!item.field3,

    /*The only thing you actually wanted to change*/

    field4: ri!newValue,

    field5: fv!item.field5,

    and so on.....

    )

    We all actually have the same idea about the forEach.  The reason yours isn't working is because you're attempting to use the save! function.  That only works in an interface component's saveInto block.  It's designed to not work unless a user has actively clicked on a thing.  It won't work outside a saveInto by design. 

    The plugin works, if you want to deal with the plugin, but this version also works too.  You build a NEW CTD exactly like the old one in every detail, except for the one detail you want changed.  This method also allows you to alter multiple details as you see fit simultaneously.

  • 0
    Certified Lead Developer
    in reply to Dave Lewis

     That's a good solution. But the only problem which accompanies this solution is a change in the CDT structure in the future.

    Let's say at first we have 10 fields in the CDT and we use this type! constructor solution in 5 places. After 6 months, we add 2 more fields to the CDT due to business requirements. Now again, we need to revisit all the above 5 places to add those two fields in our logic. Hence futuristic code change is a considerable factor for this solution.

    Whereas the update dictionary function performs multiple field value updates and it does not have any impact based on CDT change.

Reply
  • 0
    Certified Lead Developer
    in reply to Dave Lewis

     That's a good solution. But the only problem which accompanies this solution is a change in the CDT structure in the future.

    Let's say at first we have 10 fields in the CDT and we use this type! constructor solution in 5 places. After 6 months, we add 2 more fields to the CDT due to business requirements. Now again, we need to revisit all the above 5 places to add those two fields in our logic. Hence futuristic code change is a considerable factor for this solution.

    Whereas the update dictionary function performs multiple field value updates and it does not have any impact based on CDT change.

Children
No Data