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

@Annirnita Dash1 

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

Hi Ankur,

sorry for replying late,

I tried adding line number 8 and used in url... but it is not working.

Can you point out the problem here?

 

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();


//action.setRedirectURL("/change_request.do?sys_id=-1&sysparm_query=short_description=" + current.short_description + "^description" +  current.description + '^parent=' + current.sys_id);

var url = 'change_request.do?sys_id=-1&sysparm_query=' + 'short_description=' + short_description + '^description=' + description + '^cmdb_ci=' + cmdb_ci + '^priority=' + priority + '^sys_domain=' + sys_domain + '^company=' + company + '^type=' + type + '^parent=' + parent;

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

 

@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

Sorry I got the fix, below line  I did, as of now with limited fields:

 

var url = 'change_request.do?sys_id=-1&sysparm_query=' + 'short_description=' + current.short_description + '^type=' + current.type + '^parent=' + current.sys_id;