- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2017 01:23 AM
Hi,
I've two requirements to complete:
1 - push comments left in catalogue tasks to the request item so a requester can view them from the self service portal, and
2 - push comments left by the requester back into the associated catalougue tasks.
Using some answers on these forums, I've achieved point 1 using the following business rule:
Before Update, condition = current.comments.changes()
var gr = new GlideRecord('sc_req_item');
gr.get(current.request_item);
gr.comments = current.comments;
gr.update();
This worked exactly as it should until i came to point #2.
To try to achieve the second point I've used the following business rule:
Before Update (I've also tried After Update) condition = current.comments.changes()
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item',current.sys_id);
gr.query();
while(gr.next()) {
gr.comments = current.comments;
gr.update();
The eagle-eyed among you will have spotted that these two BR's cause a comments loop; anything left by the requester posts into the tasks and then back into the RITM, and vice versa. It's also posting everyone's RITM comments back to the tasks and not just the requester, so I tried adding '&& gs.getUserID()==current.sc_req_item.request.requested_for' to the condition to match the current user to the user in the RITM's requested for field and only run when the two users match, however this prevents comments getting to the task, so I'm assuming that my syntax is wrong here.
So, my question is; would anyone be able to help me with achieving these two commenting requirements without them triggering each other, and also limit the flow of comments from the RITM to the tasks to just those left by the requester?
Thanks in advance
Mike
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2017 06:11 AM
Sure - below are our two scripts:
Task to RITM:
(function executeRule(current, previous /*null when async*/) {
str = current.comments;
var pos = str.search('Update from Requested Item');
if(pos == -1){
//gs.info('The push from Task to RITM will trigger now: ' + current.comments);
var gr = new GlideRecord('sc_req_item');
gr.get(current.request_item);
gr.comments = 'Update from Task "' + current.short_description + '": ' + current.comments;
gr.update();
}
else{
//gs.info('I will not push this comment from Task to RITM: ' + current.comments);
}
})(current, previous);
RITM to TASK (we also push to approvals, so this includes a little more than you need):
(function executeRule(current, previous /*null when async*/) {
str = current.comments;
var pos = str.search('Update from Task');
var pos1 = str.search('Update from Approval');
if(pos == -1){
//gs.info('The push from RITM to Task will trigger now: ' + current.comments);
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item',current.sys_id);
gr.addQuery('active',true);
gr.query();
while(gr.next()){
gr.comments = 'Update from Requested Item: ' + current.comments;
gr.update();
}
}
else{
//gs.info('I will not push this comment from RITM to Task: ' + current.comments);
}
if(pos1 == -1){
//gs.info('The push from RITM to Approval will trigger now: ' + current.comments);
var app = new GlideRecord('sysapproval_approver');
app.addQuery('sysapproval',current.sys_id);
app.addQuery('state','requested');
app.query();
while(app.next()){
app.comments = 'Update from Requested Item: ' + current.comments;
app.update();
}
}
else{
//gs.info('I will not push this comment from RITM to Approval: ' + current.comments);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2017 10:57 AM
Preface the comment from each with something like: "Comment from RITM" and "Comment from TASK" when writing to the other record. Then, include in your script to check where the comment came from (indexOf) to determine if it should be pushed to the other record. For example, on your ritm, if the comment has an index of "Comment from TASK", you wouldn't push to tasks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2017 11:51 AM
Hi
you can add String before the comments like from taks and from ritm and use indeOf() in if condition before updating work notes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2017 03:32 AM
Thanks for your reply. I had a go at doing when you've suggested but my JavaScript skills are still pretty rudimentary. Would you mind posting an example of how this would be written please?
Many Thanks
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2017 06:11 AM
Sure - below are our two scripts:
Task to RITM:
(function executeRule(current, previous /*null when async*/) {
str = current.comments;
var pos = str.search('Update from Requested Item');
if(pos == -1){
//gs.info('The push from Task to RITM will trigger now: ' + current.comments);
var gr = new GlideRecord('sc_req_item');
gr.get(current.request_item);
gr.comments = 'Update from Task "' + current.short_description + '": ' + current.comments;
gr.update();
}
else{
//gs.info('I will not push this comment from Task to RITM: ' + current.comments);
}
})(current, previous);
RITM to TASK (we also push to approvals, so this includes a little more than you need):
(function executeRule(current, previous /*null when async*/) {
str = current.comments;
var pos = str.search('Update from Task');
var pos1 = str.search('Update from Approval');
if(pos == -1){
//gs.info('The push from RITM to Task will trigger now: ' + current.comments);
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item',current.sys_id);
gr.addQuery('active',true);
gr.query();
while(gr.next()){
gr.comments = 'Update from Requested Item: ' + current.comments;
gr.update();
}
}
else{
//gs.info('I will not push this comment from RITM to Task: ' + current.comments);
}
if(pos1 == -1){
//gs.info('The push from RITM to Approval will trigger now: ' + current.comments);
var app = new GlideRecord('sysapproval_approver');
app.addQuery('sysapproval',current.sys_id);
app.addQuery('state','requested');
app.query();
while(app.next()){
app.comments = 'Update from Requested Item: ' + current.comments;
app.update();
}
}
else{
//gs.info('I will not push this comment from RITM to Approval: ' + current.comments);
}
})(current, previous);