Set incident state to 'awaiting change' when normal change is created from incident record

Vishwa Pandya
Tera Expert

Hello,

I would like to set the state on the incident record to "Awaiting Change" when a Change is created from an incident, by updating the existing "Create Normal Change" UI action.

Please guide me through this.

 

1 ACCEPTED SOLUTION

Actually I have created an "awaiting change" choice in the state field itself. And below solution worked for me. 

find_real_file.png

View solution in original post

8 REPLIES 8

Can you please share your full code?

Regards,
Muhammad

(function(current, previous, gs, action) {
    

    var stdChgCatalogActive = GlidePluginManager.isActive("com.snc.change_management.standard_change_catalog");

    if (stdChgCatalogActive) {
        var target = {};
        target.table = current.getTableName();
        target.sysid = current.getUniqueValue();
        target.field = 'rfc';
        try {
            target.isWorkspace = (typeof RP == 'undefined');
        }
        catch (err) {
            target.isWorkspace = false;
        }
        gs.getSession().putProperty('change_link', target);
    }

    var changeRequest = ChangeRequest.newNormal();
    changeRequest.setValue("short_description", current.short_description);
    changeRequest.setValue("description", current.description);
    changeRequest.setValue("cmdb_ci", current.cmdb_ci);
    if (changeRequest.hasValidChoice('priority', current.priority))
        changeRequest.setValue("priority", current.priority);
    changeRequest.setValue("sys_domain", current.sys_domain);
    changeRequest.setValue("company", current.company);
    var sysId = changeRequest.insert();
    current.setValue('state',4);
    current.update();

    if (!stdChgCatalogActive) {
        current.rfc = sysId;
        current.update();
        var incUrl = "<a href='" + current.getLink(true) + "'>" + current.getDisplayValue() + "</a>";
        gs.addInfoMessage(gs.getMessage("Normal Change {0} created from {1}", [changeRequest.getValue("number"), incUrl]));
    }

    action.setReturnURL(current);
    action.setRedirectURL(changeRequest.getGlideRecord());
})(current, previous, gs, action);

Try this.

(function(current, previous, gs, action) {
    

    var stdChgCatalogActive = GlidePluginManager.isActive("com.snc.change_management.standard_change_catalog");

    if (stdChgCatalogActive) {
        var target = {};
        target.table = current.getTableName();
        target.sysid = current.getUniqueValue();
        target.field = 'rfc';
        try {
            target.isWorkspace = (typeof RP == 'undefined');
        }
        catch (err) {
            target.isWorkspace = false;
        }
        gs.getSession().putProperty('change_link', target);
        current.setValue('state',4);
        current.update(); 
    }

    var changeRequest = ChangeRequest.newNormal();
    changeRequest.setValue("short_description", current.short_description);
    changeRequest.setValue("description", current.description);
    changeRequest.setValue("cmdb_ci", current.cmdb_ci);
    if (changeRequest.hasValidChoice('priority', current.priority))
        changeRequest.setValue("priority", current.priority);
    changeRequest.setValue("sys_domain", current.sys_domain);
    changeRequest.setValue("company", current.company);
    var sysId = changeRequest.insert();

    if (!stdChgCatalogActive) {
        current.rfc = sysId;
        current.setValue('state',4);
        current.update();
        var incUrl = "<a href='" + current.getLink(true) + "'>" + current.getDisplayValue() + "</a>";
        gs.addInfoMessage(gs.getMessage("Normal Change {0} created from {1}", [changeRequest.getValue("number"), incUrl]));
    }

    action.setReturnURL(current);
    action.setRedirectURL(changeRequest.getGlideRecord());
})(current, previous, gs, action);

Please mark this helpful/correct, if applicable.

Regards,
Muhammad

Thank you Vishwa Pandya !