Type Specification

DeIvory Gordon
Tera Guru

Hello,

 

I am working on a catalog item that has two fields "Life Cycle Stage" and "Life Cycle Stage Status".  When I select "Operational" under "Life Cycle Stage", I should see four choices under "Life Cycle Stage Status", they are End of Support, In Maintenance, In Use, and Pending Fulfillment.  Currently, there are more seven choices under "Life Cycle Stage Status".  How do I remove the other choices so that only the four choices listed above show under "Life Cycle Stage Status"?  Thanks!

  

DeIvoryGordon_1-1746639134759.png

 

 

 

 

 

DeIvoryGordon_0-1746638927785.png

 

2 ACCEPTED SOLUTIONS

BrianProvencher
Giga Guru

You can accomplish this with a Catalog UI policy. Let me know if you need specific instructions.

 

 

View solution in original post

Zach N
Tera Guru

Hey DeIvory!

 

As Brian suggested, you will want to use a Catalog UI Policy. Since you want this to occur based on the selection of the other field, this will need to happen client-side. Here are some step by step instructions:

 

  1. Navigate to the Catalog Item in question.
  2. Scroll to the Related Lists and select Catalog UI Policies.
  3. Click New to create a new policy.
  4. Add a Short description to the policy. I recommend trying to have a consistent naming pattern, so something like "Show / Hide <Variable Name> Choices."
  5. On the When to Apply tab, add a Catalog Condition: life_cycle_stage | is | Operational
  6. Save the record.
  7. Navigate to the Script tab.
  8. Check Run scripts.
  9. In the Execute if true script box, add the following code:
function onCondition() {

	// Remove the three options that aren't needed when "Life Cycle Stage" is "Operational".
	// Parameters are <field_name> and <choice_value>.
	g_form.removeOption('life_cycle_stage_status','available');
	g_form.removeOption('life_cycle_stage_status','learning_mode');
	g_form.removeOption('life_cycle_stage_status','pending_fulfillment');

}

     10. In the Execute if false script box, add the following:

function onCondition() {

	// Add the three options back.
	// Parameters are <field_name> and <choice_value>, <choice_display_value>.
	g_form.addOption('life_cycle_stage_status','available', 'Available');
	g_form.addOption('life_cycle_stage_status','learning_mode', 'Learning Mode');
	g_form.addOption('life_cycle_stage_status','pending_fulfillment', 'Pending Fulfillment');

}​

    11. Save the policy and test your catalog item. See attached for examples.

 

Essentially we have to use the GlideForm API (g_form) to remove the options from the variable list (This is the code that executes in the Execute if true code box). Since this is happening in the client, we have no access to the server record. This means once they are removed client-side, we have to add them back manually (Code in the Execute if false code box). This ensures that if your user selects another option they can see the other options. Note: Make sure that your variable names match exactly what you have server-side when using "addOption" otherwise you might have unexpected results.

 

Also, since the Life Cycle Stage Status field is driven by the Life Cycle Stage field, I highly recommend that you make Life Cycle Stage Status read-only until an option is selected for Life Cycle Stage (if you haven't done so already). This will ensure the user can't select the wrong choice.

 

Alternatively you could solve this using a Catalog Client Script, but UI Policies are preferred whenever possible.

Hope this helps! Let me know if you have any questions!

View solution in original post

4 REPLIES 4

BrianProvencher
Giga Guru

You can accomplish this with a Catalog UI policy. Let me know if you need specific instructions.

 

 

Zach N
Tera Guru

Hey DeIvory!

 

As Brian suggested, you will want to use a Catalog UI Policy. Since you want this to occur based on the selection of the other field, this will need to happen client-side. Here are some step by step instructions:

 

  1. Navigate to the Catalog Item in question.
  2. Scroll to the Related Lists and select Catalog UI Policies.
  3. Click New to create a new policy.
  4. Add a Short description to the policy. I recommend trying to have a consistent naming pattern, so something like "Show / Hide <Variable Name> Choices."
  5. On the When to Apply tab, add a Catalog Condition: life_cycle_stage | is | Operational
  6. Save the record.
  7. Navigate to the Script tab.
  8. Check Run scripts.
  9. In the Execute if true script box, add the following code:
function onCondition() {

	// Remove the three options that aren't needed when "Life Cycle Stage" is "Operational".
	// Parameters are <field_name> and <choice_value>.
	g_form.removeOption('life_cycle_stage_status','available');
	g_form.removeOption('life_cycle_stage_status','learning_mode');
	g_form.removeOption('life_cycle_stage_status','pending_fulfillment');

}

     10. In the Execute if false script box, add the following:

function onCondition() {

	// Add the three options back.
	// Parameters are <field_name> and <choice_value>, <choice_display_value>.
	g_form.addOption('life_cycle_stage_status','available', 'Available');
	g_form.addOption('life_cycle_stage_status','learning_mode', 'Learning Mode');
	g_form.addOption('life_cycle_stage_status','pending_fulfillment', 'Pending Fulfillment');

}​

    11. Save the policy and test your catalog item. See attached for examples.

 

Essentially we have to use the GlideForm API (g_form) to remove the options from the variable list (This is the code that executes in the Execute if true code box). Since this is happening in the client, we have no access to the server record. This means once they are removed client-side, we have to add them back manually (Code in the Execute if false code box). This ensures that if your user selects another option they can see the other options. Note: Make sure that your variable names match exactly what you have server-side when using "addOption" otherwise you might have unexpected results.

 

Also, since the Life Cycle Stage Status field is driven by the Life Cycle Stage field, I highly recommend that you make Life Cycle Stage Status read-only until an option is selected for Life Cycle Stage (if you haven't done so already). This will ensure the user can't select the wrong choice.

 

Alternatively you could solve this using a Catalog Client Script, but UI Policies are preferred whenever possible.

Hope this helps! Let me know if you have any questions!

Wow, you really bent over backwards to help me with this.  I cannot thank you enough!  Honestly, it's over my head, but you have inspired me to learn Javascript, thank you!!!

No problem, and happy to help! If you are going to venture down the path of learning JavaScript, I'd recommend the following resources:

 

Anything client-side (in the browser) can be a little finicky in ServiceNow, and messing with choice options can get out of hand quickly. If you want to avoid scripting, you could look into adding more purpose driven or specific fields, or even creating entirely new catalog items depending on your requirements.

 

Anyway, best of luck!