Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

HI

basha shaik
Tera Contributor

HI All,

 

i write a code on variable set, it's working catalog form but when i use this form under orderguide should not work on orderguide

 

Means this code should not work on this sc_cat_item_guide table

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   if (newValue.length < 50) {
      g_form.showErrorBox("business_justification", "You must enter at least 50 characters", true);
     
      // Wait 30 seconds (60000 milliseconds) before resetting to old value
      setTimeout(function() {
         g_form.setValue("business_justification", oldValue);
      }, 3000);
   } else {
      g_form.hideErrorBox("business_justification");
   }
}
 
please any one suggest
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@basha shaik 

see by checking in URL in client script.

if you find something specific to order guide then don't run

Something like this

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var url = top.location.href;
    if (url.indexOf('sc_cat_item_guide') != -1) {
        if (newValue.length < 50) {
            g_form.showErrorBox("business_justification", "You must enter at least 50 characters", true);

            // Wait 30 seconds (60000 milliseconds) before resetting to old value
            setTimeout(function() {
                g_form.setValue("business_justification", oldValue);
            }, 3000);
        } else {
            g_form.hideErrorBox("business_justification");
        }
    }
}

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

@basha shaik 

see by checking in URL in client script.

if you find something specific to order guide then don't run

Something like this

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var url = top.location.href;
    if (url.indexOf('sc_cat_item_guide') != -1) {
        if (newValue.length < 50) {
            g_form.showErrorBox("business_justification", "You must enter at least 50 characters", true);

            // Wait 30 seconds (60000 milliseconds) before resetting to old value
            setTimeout(function() {
                g_form.setValue("business_justification", oldValue);
            }, 3000);
        } else {
            g_form.hideErrorBox("business_justification");
        }
    }
}

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

i write a code on variable set, it's working catalog form but when i use this form under orderguide should not work on orderguide

 

Means this code should not work on this sc_cat_item_guide table , run only sc_cat_item

Its_Azar
Tera Guru
Tera Guru

Hi @basha shaik 

 

you can wrap your logic in a check that verifies the current table. Try adding this condition at the top of your script:

if (g_form.getTableName() === 'sc_cat_item_guide') return;

the script will exit without running any validation logic. Everything else in your code looks good—just plug this check in right after the if (isLoading || newValue === '') line and it should work as expected!

 

If this helps kindly accept the solution thanks much.

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG