cancel
Showing results for 
Search instead for 
Did you mean: 

Scripting in SCP Workflow Cloud Foundry

vbalko-claimate
Active Participant
0 Kudos

Hello,

I am manipulating data in a script task in SCP Workflow on Cloud Foundry.

I got object stored in the context

$.context.myObj = {
                    key1: val1,
                    key2: val2,
                    key3: val3
};

Now I try to handle that object as a standard JS object

Object.keys($.context.myObj).forEach(.....)

I got an error

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

Where can I find the specification of that special kind of object and how to handle them? Is there some specification, documentation or at least some information (beside that standard docu)

Accepted Solutions (1)

Accepted Solutions (1)

tobias_breyer
Contributor

Hi Vladimir,

unfortunately, we inherit a bug from the underlying JavaScript engine that makes Object.keys fail on our kind of context objects.

Fortunately, there is a workaround that is quite simple in most cases. It just lacks the functional approach you have with forEach.

You can use the for-in loop:

for(var key in $.context.myObj) { 
// use key for something
}

The help pages are basically our specification. Due to restrictions and bugs of the underlying engine, it is more a "specification by example". For reading the context, see here:

https://help.sap.com/viewer/e157c391253b4ecd93647bf232d18a83/Cloud/en-US/36fa9a00893f42939fa17516a33...

I'll take care that the work-around is documented.

Thanks for bringing this up.

Best regards,

Tobias

vbalko-claimate
Active Participant
0 Kudos

Thank you tobias.breyer it is exactly what I needed.

Please put that info to the documentation, it is really worth it.

And just out of curiosity - what is that engine, which does not contains Object.keys prototype? And why it does not have it?

0 Kudos

Hi Tobias.

I have tried with you suggested method to iterate over keys in context object and to delete any that includes specific text, but the returned error says key.includes is not a function. Is that also some limitation?

for(var keyin$.context.myObj){
if(key.includes("string") {
delete $.context[key]
}
}
tobias_breyer
Contributor
0 Kudos

Hi Shanir,

Array.includes is ES6, but we only support ES5.1

See

https://help.sap.com/viewer/e157c391253b4ecd93647bf232d18a83/Cloud/en-US/ca9a4381628a40908ffe1f74bde...

You can use indexOf which has slightly different behavior, but usually can do most of the same tasks. See for example:

https://betterprogramming.pub/array-includes-method-in-javascript-38d919b59c41

Regards,

Tobias

Answers (2)

Answers (2)

tobias_breyer
Contributor
0 Kudos

Hi Vladimir,

I cannot share implementation details, because then people start relying on it. It is not too difficult to guess, but guessing is a different thing from SAP documenting it and then being bound to that.

The engine does have Object.keys, but it only works on native JS objects, but not on the special objects that come out of our context API.

Regards,

Tobias

yogananda
Product and Topic Expert
Product and Topic Expert
0 Kudos
vbalko-claimate
Active Participant
0 Kudos

Thanks yoganandamuthaiah,

I checked the links, but I would probably need more guiding in these.

I didnt found anything usefull in github link - just error in ancient nodejs version, which was corrected. But no goodies for me.

Stackoverflow - as usually - is full of guidance, but in this case, all solutions seems to me overcomplicated - to create huge function just to access objects members?

It has to be better way. It is pitty, that try fail method in this case is extremly time consuming. For every try I have to build, deploy and start wf again. 3 - 5 minutes per cycle. Also no console - just helper variables in context.

Does anybody know how to polish scripts in WF?