Assistance: copy the watchlist from the RITM or from a Variable to CHG watch_list

Joel O
Mega Sage

Good day everyone, 

 

I currently am using a UI Action to convert a RITM to a CHG. Within this UI Action, I have a few data fields that get copied over to the CHG ticket, of those variables is the Watch List. 

 

Below is a sample of my current script that I am currently copying over fields from RITM > CHG and a few of them are just OOTB. I've tried to copy over the "watch_list" field that is on the RITM to no avail. The one highlighted in blue, I tried creating a variable on the form that gathers the watch list and tried to copy that to the CHG (similar to others). I know I am missing something and would like your second/third set of eyes to understand where I am going wrong. 

 

var changeRequest = ChangeRequest.newNormal();
    changeRequest.setValue("short_description", current.variables.short_description);
    changeRequest.setValue("cmdb_ci", current.variables.cmdb_ci);
    changeRequest.setValue("u_client", current.variables.client);
    changeRequest.setValue("u_environment", current.variables.environment);
    if (changeRequest.hasValidChoice('priority', current.priority))
        changeRequest.setValue("priority", current.priority);
    changeRequest.setValue("sys_domain", current.sys_domain);
    changeRequest.setValue("company", current.company);
    changeRequest.setValue("risk_impact_analysis", current.variables.risk_and_impact_analysis);
    changeRequest.setValue("justification", current.variables.justification);
    changeRequest.setValue("start_date", current.variables.planned_start_date_ci);
    changeRequest.setValue("requested_by", current.request.requested_for);
    changeRequest.setValue("watch_list", current.variables.watchlist);
    changeRequest.setValue("parent", current.sys_id);
 
Thank you all and appreciate your feedback. 
1 ACCEPTED SOLUTION

James Chun
Kilo Patron

Hi @Joel O,

 

I am not sure if you are talking about the watch_list field on the RITM. If so, the code should be the following:

 

    changeRequest.setValue("watch_list", current.getValue('watch_list'));

 

 If you are using a variable, can you share its configuration as well?

 

Cheers

View solution in original post

4 REPLIES 4

VarunS
Kilo Sage

@Joel O Try the below script.

var changeRequest = new ChangeRequest();
changeRequest.setValue("short_description", current.variables.short_description);
changeRequest.setValue("cmdb_ci", current.variables.cmdb_ci);
changeRequest.setValue("u_client", current.variables.client);
changeRequest.setValue("u_environment", current.variables.environment);
if (changeRequest.hasValidChoice('priority', current.priority))
    changeRequest.setValue("priority", current.priority);
changeRequest.setValue("sys_domain", current.sys_domain);
changeRequest.setValue("company", current.company);
changeRequest.setValue("risk_impact_analysis", current.variables.risk_and_impact_analysis);
changeRequest.setValue("justification", current.variables.justification);
changeRequest.setValue("start_date", current.variables.planned_start_date_ci);
changeRequest.setValue("requested_by", current.request.requested_for);
changeRequest.setValue("parent", current.sys_id);

// Copy the watch list from RITM to CHG
var watchList = new GlideList();
watchList.setTableName("sys_user");
watchList.addQuery("user_name", "IN", current.variables.watch_list.toString());
watchList.query();
var watchListSysIDs = [];
while (watchList.next()) {
    watchListSysIDs.push(watchList.getValue("sys_id"));
}
changeRequest.setValue("watch_list", watchListSysIDs);

Thanks @VarunS I'll test this out but appreciate your reply. 

James Chun
Kilo Patron

Hi @Joel O,

 

I am not sure if you are talking about the watch_list field on the RITM. If so, the code should be the following:

 

    changeRequest.setValue("watch_list", current.getValue('watch_list'));

 

 If you are using a variable, can you share its configuration as well?

 

Cheers

Thanks @James Chun this is what I was looking to accomplish with using the existing field on the RITM. I tried to go down the route of using variables but this is simpler and easy to add.