Make comments left by a requester visible a request item's tasks

Mike Insley
Kilo Expert

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

1 ACCEPTED SOLUTION

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);


View solution in original post

12 REPLIES 12

Thanks Kristen, yours also worked perfectly.


Were exactly can i paste these codes ? 

i am not a  developer but i am facing the same issue that any description mentioned by the user will not be inherited automatically each time i have to open the ritm variables and copy it in the REQ and SCTA also it is not inherted in all the pages  😞 

The scripts are in business rules.

pratik_kumar
Giga Expert

Hi Mike,



To stop looping i have added a text before the comments or work notes that are getting copied from task to item or item to task.



For this i have created 2 business rules:-


1. This business rule is on catalog task table and it is a before business rule.



find_real_file.png


2. Second Business rule is on request item table and it also a before business rule.



find_real_file.png


Hi Mike,



I facing some issue while replying on community post. So i have added the screenshots of the business rules.



If you want the code let me know your email id.