Untitled

mail@pastecode.io avatar
unknown
javascript
2 months ago
1.9 kB
4
Indexable
Never
// Constants
var ciServiceNow = '2df4b70b93eba190ffb4bb2c5cba10ea';

// Initializations
var impPlan = "Implement the following update sets using ServiceNow's commit functionality:\n";
var bkPlan = "Backout the following update sets using ServiceNow's backout functionality:\n";
var changeDescription = "";

//Because it run on BG Script, need to select a specific release record
//In UI Action, just current.stuff
var releaseGr = new GlideRecord('rm_release_scrum');
if (releaseGr.get('number', 'RLSE0010063')) {

    // Get release information
    var releasePlannedStart = releaseGr.start_date;
    var releasePlannedEnd = releaseGr.end_date;
    var releaseShortDes = releaseGr.short_description;

    // Get stories related to the release
    var storyGr = new GlideRecord('rm_story');
    storyGr.addQuery('release', releaseGr.sys_id);
    storyGr.query();

    while (storyGr.next()) {
        // Short description
        changeDescription += storyGr.short_description + '\n';

        // Update set for implementation plan
        impPlan += storyGr.u_update_set_s + '\n';

        // Update set for backout plan
        bkPlan += storyGr.u_update_set_s + '\n';
    }

    // Create new change request
    var changeRequestGr = new GlideRecord('change_request');
    changeRequestGr.initialize();

    changeRequestGr.cmdb_ci = ciServiceNow;
    changeRequestGr.short_description = releaseShortDes;
    changeRequestGr.start_date = releasePlannedStart;
    changeRequestGr.end_date = releasePlannedEnd;
    changeRequestGr.description = changeDescription;
    changeRequestGr.implementation_plan = impPlan;
    changeRequestGr.backout_plan = bkPlan;

    var changeRequestId = changeRequestGr.insert();

    gs.info('Change Request created with ID: ' + changeRequestId);
} else {
    gs.error('Release RLSE0010063 not found.');
}
Leave a Comment