cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Property access in SAP Workflow Service (neo)

aparr
Participant
0 Kudos

Hi all,
is it possible to dynamically access object properties in a script task in SAP Workflow Service (Neo)?

Lets assume the following JSON Context for the workflow instance

{ 
  "myObject":{}
}

And I like to create a new property for that object, whereas the name of the property needs to be dynamic. In pure JS I would do something like Object[varsSomeProperty].

var sMyProperty = "SomeProperty";
myObject[sMyProperty] = {};

When I try to do this in the Workflow Service I get the following error:

TypeError: [object ContextObject] is not an Object in <eval> at line number 17
drvup
Contributor

Hi Alexander,

can you please copy & paste more context. I assume, you're doing this in a script task of your workflow... ?

As you're accessing the context via $.context.myObject, you can of course add objects behind or create an array afterwards...

tobias_breyer
Contributor

Hi Alexander,

I guess there is something special in the parts that you left out (e. g. how the variable myObject is defined - the context does not seem to be precise enough). I tried a few variants of what you might have implemented and they all work for me.

The error message you get is usually coming when you apply a standard function like Object.keys on the context objects. Due to a limitation of the underlying JavaScript engine, some functions don't work, but looking at your description, I see none of them.

See also

https://answers.sap.com/questions/13140957/scripting-in-scp-workflow-cloud-foundry.html

Regards,

Tobias

Accepted Solutions (0)

Answers (0)