Auto populate watchlist through UI action

Rachael12
Tera Contributor

Hello,

 

I have requirement that whenever 'Start Microsoft Teams Chat' UI action is clicked on Change form, all the assignees of the associated change tasks should be part of Recommended in the chat that is about to open. As of now, in OOB functionality only that particular Change's assignment group member appear in the Recommended.

 

Now, I found that all the members of watchlist too appear automatically in Recommended. 
I would require help in how to add users automatically when the 'Start Microsoft Teams Chat' is clicked.

As an alternative, I have written a client script which maps Change Task assignees whenever they are changed but the best solution would be if I could have the assignees when the button is clicked.

I tried writing in the client script of UI action but it does seem to work.

UI Action : Start Microsoft Teams Chat

Workspace Client Script:
function
onClick(g_form) {
var ID = g_form.getValue('change_request');
var usr = g_form.getValue('assigned_to');

    var gr = new GlideAjax('assigneeList');
    gr.addParam('sysparm_name', 'assigneeList');
    gr.addParam('sysparm_id', ID);
    gr.addParam('sysparm_cList', usr);
    gr.getXMLWait();
 
var ga = new GlideAjax('sn_tcm_collab_hook.MSTeamsChatAjaxProcessor');
    ga.addParam('sysparm_name', 'isLoggedInUserHasValidEmail');
    ga.getXMLAnswer(function(answer) {
---usual OOB code-------
 
I am able to fetch the assignee list just need assistance from where do I need to call the script include in UI action.
 
Thanks in advance
8 REPLIES 8

@Rachael12 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello Ankur,

Thank you for the response!
I am handling it through 'OnChange' client script to populate/remove the assignees from watchlist of change and its working fine.
Just need one suggestion, suppose I have 25 CTask open in a change and 10 are assigned to same Assignee. Now, instead of adding the assignee 10 times in watchlist, I am checking if the sys_id of user already exists then it should not add again in watchlist but the issue is if this assignee is removed from any of the 10 CTAsks then he will be altogether get removed from the watchlist.
Can you suggest what would be the best solution here, should I have the assignee added 10 times in watchlist or is there any solution which can be implied. 

Thanks in advance!

On adding/removing an assignee, you should do an update to the watchlist (look up all tasks and set the new watchlist with all users just in there once). That way the new assignee gets added and the one removed only gets removed if he is no longer assigned to any task.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

@Rachael12 

since 10 Ctask can be assigned to same person, you need to populate that only 1 time in watch list as it's the same user (same sysId).

Ideally if you remove that assignee even from 1 task you need to check if this user is still an assignee on at least 1 task, if yes then keep that person. If not then remove it from watch list.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader