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

Ankur Bawiskar
Tera Patron
Tera Patron

@Annirnita Dash1 

you want to create the CHG or want user to be taken to new record with pre-filled data?

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

Hello Ankur,

I want it to go to a new change record with prefilled data (few of fields) and wont create one. Once I fill in required fields (other than pre filled), I should submit it and then a change will be created.

@Annirnita Dash1 

then use this and send the fields in sysparm_query

I included for 2 fields, please enhance for other fields as well which you want to pre populate

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

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

Hello Ankur I tried this earlier and once again now also, even though it doesnot create the change anymore, but after I submit it, it is not getting related to the problem. Means I cant find the change in problem related list. Do i need to remove any lines of code

@Annirnita Dash1 

it is not meant to create new change, but will simply take user to the new CHG form with pre-filled data

that's what you wanted.

For that you can populate parent field of CHG with the current problem record sysId, so that it gets linked with the CHG. For this ensure parent field is present on the form. You can include that in URL like this

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

Now when you open Problem form in related list you will see that CHG as it's parent you already populated.

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