I would like to store array values into a cdt

I would like to store array values  into a cdt. For example, I would like to store array values :{{"first name1","Last name1",1},{"first name2","Last name2",2},{"first name5","Last name5",5}} to a cdt  with values

{FirstName:"first name1", LastName:"Last name1",UserNumber:1}, {FirstName:"first name2", LastName:"Last name2",UserNumber:2}, {FirstName:"first nam5", LastName:"Last name5",UserNumber:5}.

 

How can I write function to store a array values of multiple type and store value in a cdt? 


Thanks

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    I assume you mean you're starting with an array of arrays, where every position in the top-level array is a set of data, and every bottom-level array will be [1]: first name, [2]: last name, and [3]: user number.

    You need to be careful since Appian often refuses to allow easy handling of array-of-arrays, instead treating them as flat arrays, but never really allowing you to see when it's doing one versus the other.  So what I'm about to say may or may not work, depending on how the array-of-arrays is being created / passed in.

    Create a function rule!processUsers:

    {
      FirstName: ri!array[1],
      LastName: ri!array[2],
      UserNumber: ri!array[3]
    }

    Then you call this from elsewhere, when you have your array-of-arrays as above:

    apply(
      rule!processUsers( array: _ ),
      local!myArrayOfArrays
    )

    This should hopefully return an array of 'Dictionary' matching / mapping to the CDT properties you are wanting.

  • thanks for your help ..
    but i faced :
    Expression evaluation error at function 'apply' [line 4]: Invalid usage of keywords and non-keyword arguments in partial function evaluation. The number of inputs cannot exceed the number of blanks to fill when keywords are used in the partial function.
  • 0
    Certified Lead Developer
    in reply to aamayouf
    My guess is that there's an issue with the array then (or just my code, but not sure); can you give a little more detail regarding how you end up with your initial array of arrays of data?