How can i use IncidentState script include (OOB) constant values in Client scripts

Debasis Pati
Tera Guru

Hello All,

How i can use IncidentState constants in Client scripts?
Is there a way we can use the constants in client scripts?

@Ankur Bawiskar any idea?



Regards,
Debasis

1 ACCEPTED SOLUTION

@Debasis Pati 

then something like this will help you

Note: This is just an example

var IncidentState = {
    NEW: '1',
    IN_PROGRESS: '2',
    ON_HOLD: '3',
    AWAITING_USER_INFO: '4',
    AWAITING_EVIDENCE: '5',
    RESOLVED: '6',
    CLOSED: '7',
    CANCELED: '8'
};

// Usage in client script
if (g_form.getValue('state') == IncidentState.NEW) {
    alert('Incident is New');
}

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

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Debasis Pati 

no you cannot as those are defined in script include which is server side.

You can have your own constants in client script and then have logic.

what's your actual business 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

No There is no such requirement specific.
I want to use constants for example i want to set the value to New.
in order to do that in client script ideally we do like.
g_form.setValue('state', '1');

instead of direct backend values can i use some constants so that its readable and easy to understand.
giving direct backend values just to avoid this?

Regards,
Debasis

@Debasis Pati 

then something like this will help you

Note: This is just an example

var IncidentState = {
    NEW: '1',
    IN_PROGRESS: '2',
    ON_HOLD: '3',
    AWAITING_USER_INFO: '4',
    AWAITING_EVIDENCE: '5',
    RESOLVED: '6',
    CLOSED: '7',
    CANCELED: '8'
};

// Usage in client script
if (g_form.getValue('state') == IncidentState.NEW) {
    alert('Incident is New');
}

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