cancel
Showing results for 
Search instead for 
Did you mean: 

Add string to a list String property in pure Studio/automation

Benjamin_Jalon1
Elite Collaborator
Elite Collaborator

Hi,

I would like to add string into a property defined into a document type without new operation definition.

We can't easily add the item as:

  • the object returned by Document.getProperty("mySchema:myField") is a String[]
  • the set property operation manage only scalar values

Thanks

1 REPLY 1

Benjamin_Jalon1
Elite Collaborator
Elite Collaborator

The following solution is not the most maintainable one (it uses prefixed java classes, even if it is quite stable packages)but works and is 100% Studio

Here is how I did it:


  • Fetch > something

I get the document that stores the list


  • Execution Context > Set Context Variable

parameters:

name: listOfSringTmp
Value: @{new java.util.ArrayList()}

Temporary variable where the list of all elements will be stored.


  • Scripting > Run Script

parameters:

script: java.util.Collections.addAll(Context["listOfSringTmp"], Document.getProperty("mySchema:myField"))

We add values stored into your document


  • Scripting > Run Script

parameters:

script: Context["listOfSringTmp"].add("MyNewValue")

And we add the new value


  • Scripting > Run Script

parameters:

script: Document.doc.setPropertyValue("mySchema:myField", Context["listOfSringTmp"].toArray())

And we set back the list into the document


  • Document > Save

I save my modification.