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

Another potentially complicating factor is that these two states need to be considered in the SLA Definitions (in the Pause condition).


Through my testing, it appears that if those States are added by Client Scripts and are not listed in the Choice List, they do not seem to appear in the Options when you are setting up the Conditions in the SLA Definitions.


OK.   Good news/bad news.



The good news is that we were also setting the Short Description to "Telecom Request" on the Requested Item, so I can use that instead of the reference field in my Client Script, like this:



find_real_file.png



So, that worked in that it only show these two States on Telecom Requests.



But I still have the issue I mentioned in my previous posts, that these two options are not being presented in SLA Definitions.   What to do about that?


You are going to want to do the reverse then, removing the options when not on that particular catalog item.   You'll have to add the 2 options to the list of choices so they are always there and show up for SLAs and other conditions (i.e. UI Policies, etc...), and then remove them with:



g_form.removeOption("state", "7");


g_form.removeOption("state", "8");



I'd suggest that you create a System Property to hold the sys_id of the Catalog Items instead of a hard-coded string though.   You could check the current Catalog Item against the System Property right in the Business Rule, setting the scratchpad variable to "true" or "false" with something like:



g_scratchpad.u_allowHoldState = gs.getProperty("u.allow.hold.state.items").toString().indexOf(current.getValue("cat_item")) != -1;



...or some property name that makes sense to you.   That gives you the flexibility to keep the states for any other catalog item without having to revisit the code (because you know someone will want to use them on another item ).   Just use a comma-separated list of sys_ids to hold the Catalog Items and then your Client Script can then check the scratchpad variable and remove the options when appropriate:



if (g_scratchpad.u_allowHoldState == "false"){


      g_form.removeOption("state", "7");


      g_form.removeOption("state", "8");


}



Another option would be to add a True/False field to the Catalog Item table and use that to base your logic on instead of sys_ids.



And something else you'll want to be careful of - is the State field editable in list views?   If so, you'll need a Business Rule to abort any attempt to set the State to one of the two if not on one of the particular item(s).


Thanks for the reply Jim.   I kind of blended your approach in with I had done in my last post, and it seems to work!


find_real_file.png


So, I think I have this working now.



Out of curiosity, so there isn't any way to do what I was trying to do using Dependent Values?


Just want to make sure that I am not re-creating the wheel and doing things the hard way!


Take a look at this post regarding having multiple sets of choice lists - Multiple Choice Lists for "State" Field.   Thanks for the inspiration