What is the best practice for removing/deleting variables from catalog items?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2016 02:12 PM
We have quite a few catalog items that have different variables on them. There have been some requests to update the catalog items to remove some questions (variables) since some are no longer needed.
To accomplish this, I have been deleting the variable from the catalog item setup to keep it clean. However, I see an issue with this since any already submitted Request Items that had this variable populated before will no longer have this variable show and will make the request item look incomplete.
So my question is, what is the best practice for removing any catalog item variables that are no longer needed?
Thanks,
Johnny

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2016 02:03 PM
Probably the easiest solution would be to create a Catalog UI Policy that hides the choice if it is not currently selected. That way the choice will not be available in the form moving forward, but will still show on existing submissions where the choice was made. This is taking into account that the variable is not editable after submission.
For my example, I created a Select box type variable called 'test_select_box' with three choices: (Choice 1, Choice 2, Choice 3) and values of: choice1, choice2, choice3.
I created a Catalog UI Policy with the Run scripts checkbox checked. [Hint] you may have to select Advanced view to get the Script tab to show.
Into the Execute if true field, I put the following script:
function onCondition() {
var varVal = g_form.getValue('test_select_box');
if (varVal != 'choice2') {
g_form.removeOption('test_select_box', 'choice2');
}
}
What this does is gets the value of the variable, then if the variable is not already the choice we want to remove, it removes the choice.
You can have this UI Policy run on the Catalog Item view, Catalog Tasks, and Requested Items so that it will apply to all places where this Select box is used.
This solution above works best if you are not editing the variable in the Requested Item or Catalog Task record. If you need to edit the variable, you may want to consider creating a control variable that is hidden and use a condition on the Catalog UI Policy to run if the variable has any value [is anything]. Since variables are carried over only after submit, this condition should result in False which will cause the Execute if true to not run. Keep in mind that the Catalog Task workflow activities will need to be adjusted in your workflow to have the control variable available in Catalog Tasks.
Let me know if you need further clarification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2016 06:22 AM
Thanks Chris for the detailed explanation.
I tried your solution, but it doesn't seem to work in my situation. Can you confirm that this script works for Multiple Choice variables? Based on several threads I found on the community, I don't think "g_form.removeOption" works on multiple choice variables.
Thanks,
Johnny

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2016 08:20 AM
It sounds like you have variable choices that will always change. If that is the case, you could leverage a Lookup Select Box variable type instead.
I would recommend disabling the existing Select Box variable and using a new Lookup Select Box variable in its place.
You can set up the variable to look up using the Choice [sys_choice] table. For my example, I am using the Operating system [os] field that is found on the Computer [cmdb_ci_computer] table:
Lookup from table: Choice [sys_choice]
Lookup value field: Value
Lookup label field(s): label
Reference qual: name=cmdb_ci_computer^element=os^inactive=false^ORDERBYsequence
The reference qual field uses the following formula:
name=table_name^element=field_name^inactive=false^ORDERBYsequence
...where:
table_name is the name of the table the choice resides on.
field_name is the name of the field the choice list uses.
inactive=false only shows those choices where Inactive is false.
ORDERBYsequence will sort the list by the Sequence field.
Depending upon if your choices are found on another table will determine which table and field value to use in the Reference qual field.
You could create a special table that is used to house the choice lists you know will change. That way you could change the Reference qual field to match accordingly. For example, let us say we created a special table called ReqVars [u_req_vars]. We then create a choice list called Server type [u_server_type] with the following Label/Value pairs:
Windows Server/win_server (sequence: 10)
Linux Server/linux_server (sequence: 20)
Unix Server/unix_server (sequence: 30)
Your Reference qual field on the Lookup Select Box variable would be the following:
name=u_req_vars^element=u_server_type^inactive=false^ORDERBYsequence
Let me know if you need further clarification,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2016 09:07 AM
Thanks for your responses Chris.
It looks like your solution is for select box variable types. The variable that I'm trying to work with is a Multiple Choice type (radio buttons), not a select box. From what I understand, multiple choice variables are completely different from select boxes and more difficult to work with in terms of hiding/disabling choice options. I don't want to change the variable type from multiple choice to select box or anything else since this is how the users want the form to be.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2016 10:21 AM
There is a Lookup Multiple Choice type that you can use the same filtering functionality:
Variable Types - ServiceNow Wiki