Create a Standard Change Request using a custom UI action for a particular Standard Change Template

Lavanya Damotha
Tera Contributor

Hi All,

 

I have a requirement to create a Standard Change Request when the "Create change request" button is clicked from a form with a specific Standard change template. Please help me here. Thanks in Advance.

1 ACCEPTED SOLUTION

@Lavanya Damotha 

try this

// Get the standard change template (producer version) record
var stdChange = new GlideRecord('std_change_producer_version');
if (stdChange.get('<sys_id_of_standard_change_producer_version>')) {
    var chg = new GlideRecord('change_request');
    chg.initialize();
    chg.chg_model = stdChange.chg_model;
    chg.type = 'standard';
    chg.requested_by = '<sys_id_of_default_user>';
    chg.std_change_producer_version = stdChange.sys_id;
    chg.short_description = stdChange.short_description; // Manually set
    chg.assignment_group = stdChange.assignment_group;   // Manually set
    chg.service = stdChange.service;                     // Manually set
    chg.service_offering = stdChange.service_offering;   // Manually set
    // Set other fields as needed
    var chg_id = chg.insert();
}

also check this link - response from GBall

Apply Standard Template for Change Request through Script 

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

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@Lavanya Damotha 

UI action should be on which form? share screenshots

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 Bawiskar ,

Thank you for the reply. The UI action should be on CISCO form, so when user click on Create change request, the standard change request should get automatically created by populating the values from the existing standard template they have created.
So I have written the below script, now the Standard CR is getting created but short description, assignment group, service and service offering field values are not getting populated. Only Description, Implementation and Backout plan is getting copied from that template.
Script:

var chg = new GlideRecord('change_request');
chg.initialize();
chg.chg_model = <std change model sys id>;
chg.type = 'standard';
chg.requested_by = '<sys id of the default user they provided>';
chg.std_change_producer_version = '<sys id of that standard change producer version>';
var chg_id = chg.insert();

Please help me here, as why the Short desc, Assignment grp, Service and service offering are not getting populated.

Thanks in Advance

@Lavanya Damotha 

try this

// Get the standard change template (producer version) record
var stdChange = new GlideRecord('std_change_producer_version');
if (stdChange.get('<sys_id_of_standard_change_producer_version>')) {
    var chg = new GlideRecord('change_request');
    chg.initialize();
    chg.chg_model = stdChange.chg_model;
    chg.type = 'standard';
    chg.requested_by = '<sys_id_of_default_user>';
    chg.std_change_producer_version = stdChange.sys_id;
    chg.short_description = stdChange.short_description; // Manually set
    chg.assignment_group = stdChange.assignment_group;   // Manually set
    chg.service = stdChange.service;                     // Manually set
    chg.service_offering = stdChange.service_offering;   // Manually set
    // Set other fields as needed
    var chg_id = chg.insert();
}

also check this link - response from GBall

Apply Standard Template for Change Request through Script 

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

@Lavanya Damotha 

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