Skip to main content
November 23, 2022
Question

how to save array of values in CDT in process model

  • November 23, 2022
  • 8 replies
  • 0 views

For example, I have process variables arrays

        name : {"a","b","c","d"},

        age : {1,2,3,4},

        email : {"@e","@r","@t","@w"}

and I have a CDT which has {name,age,email} 
How can I save those array values in my CDT  in process model? bcz when I try to use script task to save the array values in CDT and write in the db using cdt  then only first row is getting written in db.

8 replies

November 23, 2022

Did you check about the Multiple checkbox is checked for the data input you would have created?

November 23, 2022

yes

amans0009
November 23, 2022

when you have arrays of value(CDT) and you want to write all to rows in database then you have to config this in "write to data store entity node"  below name and type there is a checkbox multiple(for your data input) , try to select it and then try writing to the data store entity

November 23, 2022

Multiple checkbox is greyed out



amans0009
November 23, 2022

you are writing the data (param3) right? were you able to store multiple data in it ? from your process instance photo it shows only one set of data(first values).

if thats the case then - 
check if you variable param3 can have multiple values

and try storing the data into the variable like this 

a!localVariables(
  local!name:{1,2,3,4},
  local!age:{"10","20","30","40"},
  local!param3:  a!forEach(
    items:local!name,
    expression:'type!{urn:com:appian:types:CP}CP_uiDataBase'(
      test_int: local!name[fv!index],
      test_text: local!age[fv!index],
      test_date: null
    ) 
  ),
  local!param3
)

vinays024987
November 23, 2022

You should first cast this data to your CDT.

Check this out:

a!localVariables(
  local!data:{
    name : {"a","b","c","d"},

    age : {1,2,3,4},

    email : {"@e","@r","@t","@w"}
  },
  a!forEach(
    items: local!data.name,
    expression: type!<>(
      name: fv!item,
      age: index(local!data.age,fv!index,{}),
      email:index(local!data.email,fv!index,{})
    )
  )
)
 

This is not the most appropriate way, But it will work.

greg.wheeler
November 23, 2022

It is not performant or considered best practice to have a single field contain an array of items. I would recommend you go back to your initial interface and update the rule input to be an array. Check out this pattern on Appian Documentation https://docs.appian.com/suite/help/22.4/recipe-add-edit-and-remove-data-in-an-inline-editable-grid.html and look at how local!employees (line 11) is creating a list of arrays. Once you have reviewed the pattern to see how new employees are added to the local variable, you can reconstruct your interface to allow the same behavior. Eventually, you can pass that array of items into the process where the Write to DSE node will see that each array should represent a row in the db.