Dependent Choice List in Requested Items

jmiskey
Kilo Sage

So, we need to add a few new options to the State field in the Requested Items (sc_req_item) table.   However, we ONLY want these options to appear for Requested Items where the cat_item field is equal to "Telecom Request".   I thought we could use Dependent values to get this to work, but I cannot figure out how to make it work.   I have searched around and looked at past articles and videos, but most seem to address old versions of ServiceNow (we are on Helsinki).

I can see how to add the Dependent Value to each choice, but I do not see how to actually make the field itself Dependent on another field (if understand it correctly, there are two parts:

1. What field is it dependent on?   This would be the "cat_item" field.

2. What value is it dependent on?   The would be "Telecom Request".

So, where/how do I set that first part?

Or am I going about this wrong and need to take a different approach?

1 ACCEPTED SOLUTION

You can write an Display Business Rule to get the current Catalog Item, instead of using sys_id in Client Script. Please find the details below:



1) Configure On Display Business Rule on Requested Item Table as shown below:



find_real_file.png



2) Modify your client script as below:



find_real_file.png



Hope this helps. Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

9 REPLIES 9

shloke04
Kilo Patron

Hi,



You can write an On Load Client Script on Requested Item table as below:



function onLoad() {


    //Type appropriate comment here, and begin script below


    var request = g_form.getValue('cat_item');


    if(request == 'ff70f4f0db017a00eb7fd740cf961917')         // sys_id of the Catalog Item for which you want the new Choice


      {


    g_form.addOption('state','6','choice1');


      }


}



find_real_file.png




Below is the syntax for add option:


g_form.addOption(fieldName, choiceValue, choiceLabel)



Hope this helps. Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

I don't think I can hard code sys_id fields, because this code will need to be copied/pushed to other environments, so it needs to be more dynamic than that.


You can write an Display Business Rule to get the current Catalog Item, instead of using sys_id in Client Script. Please find the details below:



1) Configure On Display Business Rule on Requested Item Table as shown below:



find_real_file.png



2) Modify your client script as below:



find_real_file.png



Hope this helps. Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hmm... Doesn't seem to be working.   Do I need to set any values on the "When to Run" tab of the Business Rule?



Here is my exact script.   Just to test, I commented everything out except for the two "g_form.addOption" statements, and confirmed that works.   Just cannot get it to work on the condition.


Seems a little odd to me that we can call "cat" out of the blue with no reference.



find_real_file.png