Workflow: how to print Object value ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 10:28 AM
Hello,
I'm in progress with ITOM training: https://developer.servicenow.com/app.do#!/training/article/app_store_learn_orchestration_istanbul_c_...
In workflow I've "Log Message" activity - 'cause I'd like to print ${data} object itself. So JSON.stringify(${data}) doesn't work: system logs say that
Information | JSON.stringify([object com.glideapp.workflow.element.WorkflowDatabus]) |
Gyazo - ec69249a1ab0d896003bda65cb8dec96.png
So what is the best way to easily "print" object value ?
Thanks in advance
- Labels:
-
Event Management
-
Orchestration (ITOM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 11:17 AM
I think you will have to print each property of ${data} individually like ${data.get(3).distance} , ${data.get(3).duration}
JSON.stringify can take in javascript object and converts in JSON string. As ${data} is an object of WorkflowDatabus, so JSON.stringify could not evaluate it to JSON string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 12:08 PM
${data.get(3).distance} , ${data.get(3).duration} are not the cases.
I would like to "debug" and see ALL DATA which comes from response. How can I do that?
Is there any loop through all elements of this JSON object?
Thanks for reply.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2017 05:10 PM
You can't stringify a non JavaScript object like com.glideapp.workflow.element.WorkflowDatabus. That is probably a Java object. You would have to use a script activity to create a JavaScript object then iterate through all the properties of the Java object and add them to the JavaScript object. Then you could use JSON.stringify to convert it to a JSON encoded string. Here is a small example using GlideRecord as the source:
var gr = new GlideRecord('incident');
gr.initialize();
var JSobj = {};
for (var prop in gr) {
try{ JSobj[prop] = String(gr[prop] ); } catch (ex) { gs.log(ex); }
}
var str = JSON.stringify( JSobj );//{'prop1':'Hello','prop2':'World'}
gs.log(str);//server side log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2017 05:56 PM
You can try the following code in a Run Script activity:
var maxActivityCount = 100;
for (var i = 0; i < maxActivityCount; i++) {
try {
var databus = data.get(i);
workflow.info("[" + i + "] " + JSON.stringify(databus));
} catch (err) {
// workflow.info(err.message);
}
}