The CreatorCon Call for Content is officially open! Get started here.

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

Part 4. In this video i have talked about ServiceNow form, list, menu, sub-menu, application, table and more basic thing which are necessary to know. For document please visit: https://servicenowwithrunjay.com/ Follow Facebook page for latest update on upcoming videos: ...

@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

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

Part 4. In this video i have talked about ServiceNow form, list, menu, sub-menu, application, table and more basic thing which are necessary to know. For document please visit: https://servicenowwithrunjay.com/ Follow Facebook page for latest update on upcoming videos: ...

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