Returning object from script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 11:56 PM
I just have a small problem in retrieving the returned value, i'm calling a business rule on change request form to retrieve the 'assigned_to' of the two change tasks. I'm able to fetch the value of the assigned_to but unable to return it. i have a screenshot of the code below.
Business Rule:
I'm getting undefined when i display the answer.
Script Include:
When i use logs it displays the obj values as required, so there is some problem in encoding or decoding the values.
And i need one more help, when the values are sent back it should be added to the eventQueue as parameters as you can see in the business rule.
So when the event is fired a notification will run.
When to send:
Who will receive:
i have to send it to three users, opened by and the two assigned_to of the tasks, so I have checked the two parameters as receivers, so is this enough to send notification email to all three or is there anything else i need to do.
This is my first time working on notifications so i don't have much idea how this works, please point out if i need to make any changes.
Many Thanks!!
- Jayanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 01:46 AM
What if you don't use JSON, just something like :
var obj = new Object();
if .... {
var assigned = gra.assigned_to.toString();
obj[one] = assigned;
}
else if ... {
var assigned = gra.assigned_to.toString();
obj[two] = assigned;
}
...
return obj;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 12:20 AM
I think the problem is your line 29: answer = answer,evalJSON();
I tried using the method in Xplore but it seems not to be defined (and I never heard of it).
Try using the decode method from the JSON-Library.
var json = new JSON();
var oAnswer = json.decode(answer);
BTW, why do you encode/decode the result in JSON? If you only call the method getAssignedTo() from the BR, you can pass the JavaScript-Object instead of the JSON-String;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 01:25 AM
Hi Sebastian, thank you for responding,
I initialized a new JSON variable and used decode but still not working. when i pass the javascript obj get the same result, undefined.
The answer will show as [object][object] but after decoding it becomes undefined.
i even tried using stringify and parse but no luck.
I referred this site but it is for client script.
https://fruitionpartners.eu/blog/2015/11/17/glideajax-return-multiple-values-using-json/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 01:44 AM
Based on your two snippets can you try the following:
1) You use obj.one and obj.two, but can you be sure both values are set?. Maybe you can initialize it the following way to prevent undefined errors.
var obj = {one: '', two: ''};
2) Does the method getAssignedTo() returns the correct result? (Log the returned answer directly, between line 28-29).
var answer = SI.getAssignedTo();
gs.log("Assigned to: " + answer);
3) If it returns something like "{"one":"sys_id1","two":"sys_id2"}" the following should work.
var json = new JSON();
var oAnswer = json.decode(answer);
gs.log("Assigned to - one: " + oAnswer.one);
4) Also make sure that everything is spelled correctly (Upper/Lower-Case etc.)