1

In the Expression Builder for the Workplace Process Designer, I have an attachment variable of type String[] (array of strings). I'd like to add some elements to it using the Expression Builder, but I can't work out the syntax. Has anyone done this? Is it even possible to add elements to an existing array in Expression Builder?

WiredCoder
  • 916
  • 1
  • 11
  • 39
user1071914
  • 3,295
  • 11
  • 50
  • 76

3 Answers3

2

The arraytostring solution only works if there is only one element the array. Assign the additional value with the following expression:

stringarray[elementcount(stringarray) + 1] = value

The expected 'array out of bound exception' and the resizing of the array is handled during the assignment.

tannerli
  • 594
  • 9
  • 33
Tekcins
  • 134
  • 8
1

I originally thought that it is not possible that we had to resort to have a custom java component to do the job, however I had run a small experiment that should serve as a workaround for your case.

Suppose you have String[] arrayType={"string1, string2"}, you can use the following expression as a value for your updated array:

{(arraytostring(arrayType,  " ", " ,", ","))+"string3"}

What I did was that,

  • First, I used arraytostring function to convert the array to a string separated by comma with a comma left at the end. My output is similar to string1,string2,
  • Second, I appended the string that I want to add to the end of the string, so that my output is string1,string2,string3
  • Lastly, I assigned the value above to my array, using the array expression format {}, so my final evaluated string is {string1,string2,string3}

For more information about array functions, please follow the link below:

https://www.ibm.com/support/knowledgecenter/SSNW2F_5.2.1/com.ibm.p8.pe.user.doc/bpfe003.htm

WiredCoder
  • 916
  • 1
  • 11
  • 39
  • Hi, First two steps worked fine but the 3rd step is not converting properly its converting into an array with single value in the arrray with complete merged string, is there anything missing for the 3rd step. – Vinay Feb 21 '17 at 03:26
  • Hi @Vinay, No other steps, make sure that there are no extra commas, or any ASCII comma issues and it should work like charm – WiredCoder Feb 27 '17 at 11:09
  • Hi @WiredC0der, I have given the details steps on what I am trying to do in the below, could you please check and let me know if there is anything I am missing during the assignment of the constructed string – Vinay Feb 28 '17 at 00:16
0

I had a case like this, here is what I did:

  1. I get the array from the attachment using the CE-Operation and store in an array property on the workflow

  2. Then I used the following to

    {(arraytostring(workflowArray,  " ", " ,", ","))+workflowStringProp}
    
  3. using the CE-Operation again to set the array in the attachment with the workflowArray.

abarisone
  • 3,707
  • 11
  • 35
  • 54