Subcategory shows for a few secods when called from CS

tom the
Giga Guru

Hi,

 

I have this use case where need to set, some fields once the caller is set to Abel Tuter, I used a CS onChange, I could say it is working but subcategory shows for les than a second then goes back to -none-

I used the following script 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (newValue == '62826bf03710200044e0bfc8bcbe5df1') { // Sys ID = Abel Tuter
        g_form.setValue('category', 'end_user_devices'); // Set Category
        g_form.setValue('subcategory', 'Keyboard'); // Set Subcategory
        g_form.setValue('short_description', 'This is the end user device'); // Short Description
        g_form.setValue('impact', '2'); // Impact = Medium
        g_form.setValue('urgency', '3'); // Urgency = Low
        g_form.setValue('service_offering', 'fae7e9e7c3635210075edf3d050131a5');// Set SO = Azure AD Auth
        g_form.setValue('cmdb_ci', '780b8ce8735423002728660c4cf6a7e7'); // Set CI = *MACBOOK-AIR-13
    }
}
tomthe_0-1739426155885.png

 

tomthe_1-1739426209154.png

 

1 ACCEPTED SOLUTION

tom the
Giga Guru

thank you for all your help, it was an issue with a capital letter on the category value

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@tom the 

that's because subcategory is dependent on category

I hope you are setting the correct subcategory for the category you are setting via script.

give some timeout like 2-3 seconds and then set subcategory

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

Ankur Bawiskar
Tera Patron
Tera Patron

@tom the 

something like this

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (newValue == '62826bf03710200044e0bfc8bcbe5df1') { // Sys ID = Abel Tuter
        g_form.setValue('category', 'end_user_devices'); // Set Category
        g_form.setValue('short_description', 'This is the end user device'); // Short Description
        g_form.setValue('impact', '2'); // Impact = Medium
        g_form.setValue('urgency', '3'); // Urgency = Low
        g_form.setValue('service_offering', 'fae7e9e7c3635210075edf3d050131a5'); // Set SO = Azure AD Auth
        g_form.setValue('cmdb_ci', '780b8ce8735423002728660c4cf6a7e7'); // Set CI = *MACBOOK-AIR-13

        setTimeout(function() {
            g_form.setValue('subcategory', 'Keyboard'); // Set Subcategory
        }, 3000);
    }
}

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

@tom the 

Thank you for marking my response as helpful.

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

Jitendra Diwak1
Kilo Sage

Hi @tom the,

 

Subcategories are dependent on categories so please verify whether you are providing the exact subcategory respect to category. Simply open the form and select category and check which values are appearing in subcategory then you can select only those subcategory.

 

Please accept my resolution if it works for you and thumps up.

 

Thanks

Jitendra

Please accept my solution if it works for and thumps up.