To configure a standard change template that is already approved and moved to Scheduled state

Susan Goh
Tera Contributor

Hi,

 

I have a Catalog Item, where as per my current organization policy requires for it to have an automated Standard Change Request created and related to the catalog item for record purpose.

 

I have already configured an automated task for the catalog item, whereby it will run and update the necessary CI attribute into the cmdb_ci table. And once this automation task is completed, it is suppose to trigger an automate Standard Change creation relate/link it to the RITM under Change Request tab. 

 

I have already an SRM change template and a SRM Change Configuration setup with a specific Standard Change Template created. The workflow is now working correctly but the change triggered is created in a Being Prepared/Draft state instead of Scheduled.

 

How do I go about amending this to be created straight into Scheduled state. I was trying to use a Business Rule to do this but not sure if it is working correctly or should be the right way to go. Below is my current code:

 

(function executeRule(current, previous) {
    // Ensure this runs only for the specific catalog item
    var catalogItemSysId = 'dae519d747b0e2503ef66ee4f16d4307';
    if (current.cat_item.toString() !== catalogItemSysId) {
        return;
    }

    // Get the Standard Change Template
    var templateSysId = '51a0356d470ea6103ef66ee4f16d43a3'; // Replace with your template's sys_id
    var template = new GlideRecord('change_proposal'); // or 'change_model' depending on your instance
    if (!template.get(templateSysId)) {
        gs.error('Standard Change Template not found.');
        return;
    }

    // Create the Change Request
    var change = new GlideRecord('change_request');
    change.initialize();

    // Apply values from the template
    change.short_description = template.short_description;
    change.description = template.description;
    change.category = template.category;
    change.cmdb_ci = template.cmdb_ci;
    change.assignment_group = template.assignment_group;
    change.change_type = template.change_type;
    change.implementation_plan = template.implementation_plan;
    change.backout_plan = template.backout_plan;
    change.test_plan = template.test_plan;

    // Set additional values
    change.type = 'standard';
    change.state = '4'; // Scheduled
    change.approval = 'approved';
    change.planned_start_date = gs.daysAgoStart(0);
    change.planned_end_date = gs.daysAgoEnd(0);
    change.parent = current.sys_id; // Link to the RITM

    var changeSysId = change.insert();

    if (changeSysId) {
        gs.info('Change Request created from Standard Change Template and linked to RITM: ' + change.number);
    } else {
        gs.error('Failed to create Change Request from Standard Change Template.');
    }
})(current, previous);
1 REPLY 1

Susan Goh
Tera Contributor

Screen shot of the tab in question for the Change Request. This is to be applied only to specific catalog with specific standard change template. anyway how i can have this automatically created already in Scheduled state

SusanGoh_0-1749715846941.png