- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2019 01:04 PM
I'm using the "AddApproverComments" Script Include (found here in the community) in one of my workflows, along with the code in the advanced section of the Catalog Task, to show the comments from the approval in the Catalog Task.
This works perfectly if the approval is sent via email, but the script include doesn't run if the comments are added to the Approval as accessed through the Related Lists section of the RITM or in the list of approvals found in My Approvals.
I've marked the script with a gs.log statement to test when it runs, and have established that it only runs when approvals are received via email.
Here's the code (Client Callable is checked, and it's in the Global app):
var AddApproverComments = Class.create();
AddApproverComments.prototype = {
initialize: function() {
},
addComments: function(id) {
var comments='';
var gr= new GlideRecord('sc_req_item');
gr.get(id);
var apv = new GlideRecord('sysapproval_approver');
var qc=apv.addQuery('sysapproval',gr.getValue('request'));
qc.addOrCondition('sysapproval', gr.getValue('sys_id'));
apv.addQuery('comments','!=',''); // add this to only find approvals that have comments on them
apv.query();
while (apv.next()) { // change if to while so it will go through all approvals with comments
comments += "\nApproval Comments: from " + apv.approver.name + "\n" + apv.comments.getJournalEntry(-1); // add approver name here
gs.log('this is the approval comments: '+comments);
}
return comments;
},
type: 'AddApproverComments'
};
Here is the line that is added to the Catalog Task:
task.comments= new AddApproverComments().addComments(current.getValue('sys_id'));
Can you think of any reason this would only work only when the approval is emailed?
Thanks!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2019 08:01 AM
Here's the answer:
The Script Include, Business Rule, and workflow activity all work. When the comments are added manually, however, the task is created too quickly for the comments to be populated properly. This is not an issue when the comments come in via email.
I added a 5 second timer to the workflow right after the approval and it is working both for manual approvals and email approvals now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2019 01:22 PM
Instead you can try writing BR before insert it would have served the purpose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2019 02:00 PM
Yes - that is working for me. It's a good solution, thank you.
I would still like to know if anyone can tell me why a Script Include will trigger on an inbound email but not when the comments are manually added.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2019 08:01 AM
Here's the answer:
The Script Include, Business Rule, and workflow activity all work. When the comments are added manually, however, the task is created too quickly for the comments to be populated properly. This is not an issue when the comments come in via email.
I added a 5 second timer to the workflow right after the approval and it is working both for manual approvals and email approvals now.