Change Request qquivalent to script include "IncidentState"

Tim Noack
Tera Contributor

Hello, is there an equivalent to the IncidentState script include for change management?

 

When updating incident state values (e.g. in a business rule), it is recommended to use "IncidentState.CLOSED" instead of '7'.

 

Within change management I couldnt find a similiar script include. So I assume I have to hard coded the state value into my business rule or does anyone know about a best practice alternative?

1 ACCEPTED SOLUTION

Robert H
Mega Sage

Hello @Tim Noack ,

 

There is no equivalent Script Include for Change Requests out of the box.

 

But this does not mean you have to hard code the state values in your logic. You could simply create your own Script Include, based on IncidentStateSNC but adjusted for the Change Request states.

 

Regards,

Robert

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Tim Noack 

you can define constants similar to what's present for incident or hard-coded as per your requirement.

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

Are there any out of the box constants?

Hello @Tim Noack ,

 

That question is equivalent to asking if there is a Script Include like IncidentState.

It's the Script Include that is defining these constants, so that you don't have to deal with the internal value numbers.

 

But as mentioned there is no such Script Include for Change Requests.

You can create it yourself. It's just a simple list of constants.

 

var ChgState = Class.create();

ChgState.NEW           = "-5";
ChgState.ASSESS        = "-4";
ChgState.AUTHORIZE     = "-3";
// and so on...

ChgState.prototype = {
    initialize: function() {
    },

    type: 'ChgState'
};

 

Then you can use it in your scripts, like:

 

var grChg = new GlideRecord('change_request');
grChg.addQuery('state', ChgState.NEW);
...

 

Regards,

Robert

@Tim Noack 

Something like this shared below

Universal Pattern for Script Includes 

example like this

var MyConstantsUtil = Class.create();
MyConstantsUtil.prototype = {
    CONSTANTS: {
        STATUS_NEW: 'New',
        STATUS_IN_PROGRESS: 'In Progress',
        STATUS_COMPLETE: 'Complete'
    },
    initialize: function() {},
    type: 'MyConstantsUtil'
};

Then call it from server side as this

var util = new MyConstantsUtil();
gs.info(util.CONSTANTS.STATUS_NEW); // Outputs: New

AnkurBawiskar_0-1747841668327.png

 

Output:

AnkurBawiskar_1-1747841699060.png

 

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