Use Case : I will be uploading multiple documents for a single question - Document to questions (many to one relationship )
I have a CDT for Question and another CDT for documents.(Questions and documents are two different tables in database.) Since, I need to populate the document id in the document table based on the questionaries entry - For now, I am getting the primary key of question table first (after making an entry in the database)and then trying to pass the value to document table for multiple rows.
I am making an entry in the Question table via the process model using write to data store entity smart service, then using a script task I get the ID (Primary Key) of the newly inserted Questions and save it against a new process variable. Then, there is another write to data store entity smart service and in the input node I have mapped the newly created Questions ID against the particular column. When there are multiple attachments, only the first row gets updated with newly created Question ID in the respective column and all other rows are updated with null value.
In short - Multiple value update is not working - Is there a way to update the newly created Questions ID against a particular column for all the rows present in array? Please elucidate.
Discussion posts and replies are publicly visible
You should use a!forEach() and a!update() to iterate over the list of rows and update the corresponding field in your script task. Here's an expression snippet as an example:
a!localVariables( local!data: { a!map(id: 1, foreignKey: null, name: "Test One"), a!map(id: 2, foreignKey: null, name: "Test Two"), a!map(id: 3, foreignKey: null, name: "Test Three"), }, a!forEach( items: local!data, expression: a!update( fv!item, "foreignKey", 123 ) ) )
As there are a few ways to do this, one I regularly use is a script task output to update that specific ID value in your CDT via fn!repeat(), which creates a list of your IDs.
fn!repeat(count(pv!YOUR_CDT),pv!ID_VALUE)
Save this into the field you would like to update in the Questions CDT.
Peter Lewis Thank you. It worked.
ChrisThank you for your reply. I tried using fn!repeat() and I got the below error.
Expression evaluation error at function fn!repeat: Cannot repeat list type
So, I tried a!forEach() as mentioned by Peter and it worked for me.
Glad you have a solution! To note on fn!repeat(), if the single value you are looking to repeat is stored in an array for some reason, you will want to convert it to a single value such as:
fn!repeat(count(pv!YOUR_CDT),index(pv!ID_VALUE,1,null))