Creating Change Request via Service Request

pradeepshokeen
Giga Contributor

Hello Everybody,

We would like to create a Change Request using a SR, is there a way to set change request fields using scripts. this is what I am doing.

1. Creating a Task in workflow item.

2. Setting up the fields using below scripts, there are fields that are created in Task form and fields create in change_request.

task.state = 7;

change_request.u_change_scale = "Minor";

change_request.risk = 4;

task.impact = 3;

task.contact_type = "change_service";

task.assignment_group = "2b931feb4faec200f6a144f18110c78e";

change_request.type = "Normal";

change_reuqest.start_date = current.variables.effective_date;

I am not able to create the Change Request using this approach, any assistance is highly appreciated.

Thanks,

Pradeep Shokeen

12 REPLIES 12

Daniel Draes
ServiceNow Employee
ServiceNow Employee

Why are you not using a record producer? This is what the baseline does with its example entries in the service catalog.


Have a look at Record Producer



Example in your instance would be


Reboot windows server


I need to have approvals at the Request Level, once the request is approved a CR record will be inserted with all relevant fields from the SR.



I am trying to run a script to insert a CR.



var newCR = new GlideRecord('change_request');


newCR.initialize();


newCR.state = 7;


newCR.short_description = "Switch Port Opening Request " + current.variables.switch.getDisplayValue();


newCR.description = "See request item " + current.number;


newCR.cmdb_ci = current.variables.switch;


newCR.setWorkflow(false);


newCR.insert();




This is also throwing Syntax error missing name after operator ((#0eval); line 5).



Thanks and Regards,


Pradeep Shokeen


I would assume the issue is with one of the current.variables calls. Can you comment them or change them to a fixed value for the sake of testing?


All other looks good and should work just fine.



Most likely it is current.variables.switch.getDisplayValue();



Also possible newCR.state = 7; ... try newCR.state = '7';


This is correct, I am not able to make any calls to the current.variables that are defined @ SR level, if I remove these calls from the script it is accepting all static values and creating a change request, however this is not what I am looking for I need to capture the Configuration Item, Planned affective date and configuration command from the SR variables and populate this into Change request.



I am not sure what exactly I should not be doing.



Thanks and Regards,


Pradeep Shokeen