Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Create change from problem, but do not insert

Annirnita Dash1
Tera Contributor

Please help me out in creating a change request from problem but not inserting it. Since the Ui action which creates a change record is saved through it that runs, the mandatory fields not filled in and  continue to show as required. It should navigate to sys_is -1.

 

Below is the code and I have commented out line where it inserts.

 

var change = new GlideRecord("change_request");
change.short_description = current.short_description;
change.description = current.description;
change.cmdb_ci = current.cmdb_ci;
change.priority = current.priority;
change.company = current.company;
change.sys_domain = current.sys_domain;
change.type = 'Normal';
//var sysID = change.insert();
 
current.rfc = sysID;
var mySysID = current.update();

gs.addInfoMessage("Change " + change.number + " created");
action.setRedirectURL(change);
action.setReturnURL(current);

 

 

1 ACCEPTED SOLUTION

@Annirnita Dash1 

you are not inserting so you won't get the CHG number

so these lines makes no point

var change = new GlideRecord("change_request");
change.short_description = current.short_description;
change.description = current.description;
change.cmdb_ci = current.cmdb_ci;
change.priority = current.priority;
change.company = current.company;
change.sys_domain = current.sys_domain;
change.parent = current.sys_id;
change.type = 'Normal';
//var sysID = change.insert();

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

View solution in original post

15 REPLIES 15

Sanjay191
Tera Sage
Tera Sage

Hello @Annirnita Dash1 

i just correct the few thing in  above code is like type of Normal in backend is normal

and please mention what EXACULTY issue you are getting ?

 

Hi, 

yes the type is normal. the UI action create normal change.

 want it t to a new change record with prefilled data (few of fields) and wont create one. so the url shall show sys_id -1. Once I fill in required fields (other than pre filled), I should submit it and then a change will be created

Hi @Annirnita Dash1 , Did you try to use templates? 

Hi Gopika,

No, I have not done anything apart from above script.