on change client script is not working for particular catalog item

keval3
Tera Contributor

Hi All,

I have written below client script but it is not working for my catalog item it is apply for all catalog item.

kindly let me know what is issue.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue == '') {

        return;

    }

var catitem = g_form.getValue("u_catalog_item");

alert(catitem);

 

   

   

    //g_form.addInfoMessage("line 9 testing");

 

    if(catitem == '9c9df05597661e500cb57bae2153afe2')

    alert("askhr");

    {

 

    if(g_form.getValue('state') =="7")

    {

g_form.setValue("close_notes", "123455");

g_form.setValue("u_knowledge_article", "no");

g_form.setValue("u_support_type", "desk");

g_form.setValue("u_resolution_code", "Solved (Permanently)");

 

g_form.setValue("u_via_kb_article", "no");

g_form.setValue("u_via_kb_article", "no");

    }

 

    //Type appropriate comment here, and begin script below

 

}

}

 

Thanks & Regards

KP

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

@keval3 

can you share details about the script?

it's normal client script or catalog client script?

If it's normal client script and you want it to run for specific catalog item then ensure Item field is present on RITM form and you are comparing correct catalog item sysId

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue == '') {

        return;

    }

    var catitem = g_form.getValue("cat_item");

    alert(catitem);







    //g_form.addInfoMessage("line 9 testing");



    if (catitem == '9c9df05597661e500cb57bae2153afe2')

        alert("askhr");

    {



        if (g_form.getValue('state') == "7")

        {

            g_form.setValue("close_notes", "123455");

            g_form.setValue("u_knowledge_article", "no");

            g_form.setValue("u_support_type", "desk");

            g_form.setValue("u_resolution_code", "Solved (Permanently)");



            g_form.setValue("u_via_kb_article", "no");

            g_form.setValue("u_via_kb_article", "no");

        }



        //Type appropriate comment here, and begin script below



    }

}

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

Hi Ankur,

it is normal client script, Item name is present on RITM table

 

Thanks & Regards

KP

@keval3 

what came in alert for that cat_item sysId?

did you compare with correct sysId?

what came in alert for this?

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue == '') {
        return;
    }
    var catitem = g_form.getValue("cat_item");
    alert(catitem);
    if (catitem == '9c9df05597661e500cb57bae2153afe2') {
        alert("askhr"); // did this come?
        if (g_form.getValue('state') == "7") {
            g_form.setValue("close_notes", "123455");
            g_form.setValue("u_knowledge_article", "no");
            g_form.setValue("u_support_type", "desk");
            g_form.setValue("u_resolution_code", "Solved (Permanently)");
            g_form.setValue("u_via_kb_article", "no");
            g_form.setValue("u_via_kb_article", "no");
        }
        //Type appropriate comment here, and begin script below
    }
}
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

Hi Ankur,

I have tried your code but is not not working for my item. I have put current sys_id.

I have checked with other catalog item it is working over there but wrong option have been select.

as per screen snap support type is remote I have put Desk in the script also resolution notes are not populated. I want auto populate  this fields for ASK_HR catalog not for any other.

keval3_0-1735035513967.png