How to fetch current catalog task state inside catalog client script

Obito
Tera Expert

How to fetch current catalog task state inside catalog client script, so that I can compare if the state is close or not.

Please refer below image.

 

23121.png

2 ACCEPTED SOLUTIONS

Runjay Patel
Giga Sage

Hi @Obito ,

 

You can use code like below.

g_form.getValue('state')

It will give you current task state value.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

View solution in original post

In this video i have explained about Web service integration in ServiceNow like how it works, how we can configure it, what are the prerequisite and many more. I have covered below topics in this video. 1. understand Web Service. Like when and how we will use it. 2. Talked about Inbound and ...

@Obito 

if your requirement is to make all variables readonly when task is closed then use this script in normal onLoad client script on sc_task and not catalog client script

function onLoad() {
    if (g_form.getValue('state').toString() == '3')
        g_form.setVariablesReadOnly(true);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

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

6 REPLIES 6

Runjay Patel
Giga Sage

Hi @Obito ,

 

You can use code like below.

g_form.getValue('state')

It will give you current task state value.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

In this video i have explained about Web service integration in ServiceNow like how it works, how we can configure it, what are the prerequisite and many more. I have covered below topics in this video. 1. understand Web Service. Like when and how we will use it. 2. Talked about Inbound and ...

Ankur Bawiskar
Tera Patron
Tera Patron

@Obito 

you cannot access field value using catalog client script.

So g_form.getValue('state') won't work. But did you try that and see what it gave?

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

@Obito 

if your requirement says to use catalog client script then use GlideAjax

OR

you can use GlideRecord with callback

function onLoad() {

    function myCallbackFunction(gr) {
        if (gr.next()) {
            if (gr.state.toString() == '3') {
                // it's close complete   
            }
        }
    }
    var gr = new GlideRecord('sc_task');
    gr.addQuery('sys_id', g_form.getUniqueValue());
    gr.query(myCallbackFunction);
}

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

@Obito 

if your requirement is to make all variables readonly when task is closed then use this script in normal onLoad client script on sc_task and not catalog client script

function onLoad() {
    if (g_form.getValue('state').toString() == '3')
        g_form.setVariablesReadOnly(true);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

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