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

Babu Govind
Tera Contributor

Hi @Annirnita Dash1,

 

Please use the below code in your UI action this should redirect your to new change request without inserting the change. 

var changeFormUrl = 'https://INSTANCE_NAME.service-now.com/nav_to.do?uri=TABLE_NAME.do?sys_id=-1%26sysparm_query=caller_id='+current.FIELD_NAME; // Construct the URL 
action.setReturnURL(current); // Return URL to current record
action.setRedirectURL(changeFormUrl); // Landing page URL to new change form

Please add your instance name and Table name in the URL followed by the mapping. 

Hope this information is helpful. If helpful please mark as solution accepted or helpful so that it will help future readers.

 

Best Regards,

Babu