on ‎2020 Sep 15 4:49 PM
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)
Request clarification before answering.
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:
I'll take care that the work-around is documented.
Thanks for bringing this up.
Best regards,
Tobias
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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]
}
}
Hi Shanir,
Array.includes is ES6, but we only support ES5.1
See
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
| User | Count |
|---|---|
| 9 | |
| 8 | |
| 5 | |
| 4 | |
| 4 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.