Using Out-of-the-box Indient Category & Subcategory Fields on a Request Form

Wesley Breshear
Tera Expert

Hello

I trying to keep this simple and align with ServiceNow OOTB features.   Currently in ServiceNow on an Incident Record there is Category (string) and Subcategory (reference) fields.   I am creating a Service Portal/Catalog form request to get End User values and directly create an Incident record; standard or basic Help Desk form "I have a problem and need to create an Incident".   So my thinking was to match to the exact current "Category" and "Subcategory" field values of our ServiceNow instance, that way the values stay consistent with the values on the service catalog form vs. creating two static choice string fields and just passing the values to the incident record; more maintenance keep the form up to date with Incident record field values.

I am having two issue.

1.)   I am struggling in getting the string values of the 'Category' field from the Incident table to appear on my catalog from. I am using a reference field type on my catalog form but obviously the Category field on the Incident table is just a string box, and I am not able to find an appropriate table to reference, which maybe reason why it is not working.   So how do I reference this field from the Incident table?   Or am I just going to need to create a choice field with the same values as on my Incident Category column field?

2.)   Not seeing how to make the Subcategory field dependent on Category field selection like it is done within the Incident record.   I found the following article, so do I still need create a script include to make this functionality work on the catalog form request?   Or is there already an Out-of-the-box script include for the this function?   http://wiki.servicenow.com/index.php?title=Adding_Dependent_Reference_Variables#gsc.tab=0

______________________________________________________________________________________________________________________________

Fig #1

find_real_file.png

______________________________________________________________________________________________________________________________

Fig #2

find_real_file.png

1 ACCEPTED SOLUTION

You should just use Select Box for the Category/Subcategory on the record producer.


Screen Shot 2017-03-20 at 7.14.04 AM.png



I recently ran into a problem where I couldn't filter subcategory based on category on Service Portal. This link helped with that: Dependent Variables in Service Portal do not reload on values when changed


View solution in original post

17 REPLIES 17

Michael



Nice catch! I missed that when looking at your post. I think the confusion came on your catalog client script where it says "Applies to: A catalog item". In terms of catalog client scripts, it doesn't differentiate record producers from catalog items. The OOB record producer you used is correct to create the incident.



Congrats on figuring it out!


The article you referenced in your original post is in-regards to a Reference variable (where their value is a sys_id). The script returns an encoded query to filter the results for a reference field. You don't need that in this case as we are working with string / dropdown fields.



Instead, you need to:


  1. Return your list of subcategories (remove 'sys_idIN' and just do return subcategoryList;
  2. In an onChange client script (field: category) (see Michael's article he linked to), loop through the subcategoryList and add all the options to the subcategory field.


g_form.clearOptions('subcategory'); // remove all options from subcategory field


var listArray = subcategoryList.split(','); // Need to convert to array if not already


for (var x=0; x < listArray.length; x++){


      g_form.addOption('subcategory', listArray[x], listArray[x] );


}


Note: This does assume that in your dropdown of subcategories that the Value and Label are the same value. If you have converted your values to lowercase/no-space, you'll need to return both the value and label.


Hi Cary,



Yes, I ended up making the values lower case and no spaces.   What needs to be modified to handle Name and Value of each Subcategory?



-Wesley