Add one user to watchlist of Request and it should reflect on watchlist of RITM, SCTASK. can anyone help me on this how to achieve it.

SP22
Mega Sage
Mega Sage

Add one user to watchlist of Request and it should reflect on watchlist of RITM, SCTASK. can anyone help me on this how to achieve it.

1 ACCEPTED SOLUTION

Change the business rule as below

After  -  Insert and Update

condition -  Watchlist in Not Empty

View solution in original post

10 REPLIES 10

SumanthDosapati
Mega Sage
Mega Sage

Hi,

Write an after business rule on sc_request table

find_real_file.png

 

find_real_file.png

 

(function executeRule(current, previous /*null when async*/) {

	var ritm = new GlideRecord('sc_req_item');
	ritm.addQuery('request',current.sys_id);
	ritm.query();
	while(ritm.next())
		{
			
			var sc = new GlideRecord('sc_task');
			sc.addQuery('request_item',ritm.sys_id);
			sc.query();
			while(sc.next())
				{
					sc.watch_list = current.watch_list;
					sc.update();
				}
			
			ritm.watch_list = current.watch_list;
			ritm.update();
		}

})(current, previous);

 

Mark as correct or helpful if it works.

Regards,

Sumanth

I have tried this but if a user added in watchlist of request automatically. can it reflect on RITM & SCTASK. Please help me on this.

It will still work even if watchlist users are added automatically unless if the users are added using any script that uses "setWorkflow(false)".

If that is the case then write an onLoad client script on RITM and sc task tables and make an ajax call to a script include and set the watchlist.

 

Mark as correct or helpful if it works.

Regards,

Sumanth

Change the business rule as below

After  -  Insert and Update

condition -  Watchlist in Not Empty

tanuja3
Kilo Explorer

We can achieve it by writtting the After Business rule on sc_request table defining the filter condition as whenever Watchlist  changes.

 

(function executeRule(current, previous /*null when async*/) {

	var ritm = new GlideRecord('sc_req_item');
	ritm.addQuery('request',current.sys_id);
	ritm.query();
	while(ritm.next())
		{
			
			var sc = new GlideRecord('sc_task');
			sc.addQuery('request_item',ritm.sys_id);
			sc.query();
			while(sc.next())
				{
					sc.watch_list = current.watch_list;
					sc.update();
				}
			
			ritm.watch_list = current.watch_list;
			ritm.update();
		}

})(current, previous);