How to automatically set a value to a variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 12:58 AM - edited 06-12-2024 01:02 AM
Hi,
I have a scenario where I have two variables
'Printer Category' which is a Select Box, and
'Printer Package' which is referencing the table 'u_printer_request_package'.
Now I am asked, if I select 'Home Use' from 'Printer Category', I should be able to automatically display a value 'HP OfficeJet Pro 9020 All-in-One Printer' from 'u_printer_request_package' table.
Here are the columns of the 'u_printer_request_package' table.
I don't see these two variables are connected anywhere. If I have to auto populate a particular value of the 'Printer Package' based on the 'Printer Category' value 'Home Use', how would I do it?
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 02:45 AM
Hi @Community Alums
You can apply below points . May be working for your scenario
Certainly! To achieve this behavior in ServiceNow, you can follow these steps:
Create a Choice List (Category): First, create a choice list (also known as a reference table) for the “Printer Category” field. This choice list will contain the available options (e.g., “Home Use,” “Business,” etc.). You can define the display values (labels) and their corresponding internal values (usually numeric or alphanumeric codes).
Define the ‘u_printer_request_package’ Table: Ensure that the “u_printer_request_package” table contains the necessary records with the appropriate display values (e.g., “HP OfficeJet Pro 9020 All-in-One Printer”) and their corresponding internal values.
Configure the ‘Printer Package’ Field:
- In the ServiceNow form where you want to display the “Printer Package” field, create a reference field (reference variable) for the “Printer Package.”
- Set the reference table to “u_printer_request_package.”
- In the “Reference Qualifier” field, write a script that filters the available options based on the selected “Printer Category.” For example:JavaScript
// Assuming 'Printer Category' is a reference field to the 'Category' choice list 'u_printer_request_package.category=' + current.u_printer_category;
AI-generated code. Review and use carefully. More info on FAQ.This script ensures that only printer packages related to the selected category are displayed.
Display the Correct Value:
- When the user selects a value from the “Printer Category” field, the “Printer Package” field will automatically update based on the reference qualifier.
- The display value in the “Printer Package” field will show the label (e.g., “HP OfficeJet Pro 9020 All-in-One Printer”) corresponding to the selected internal value.
Remember to adjust the field names and table names according to your specific ServiceNow instance.
If this is helpful for you, Please mark Helpful and Correct solution
Thanks & Regards
Adarsh Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 05:23 AM
Hi @Community Alums ,
If this is helpful for you, Please mark Helpful and select "Accept as Solution".
Thanks & Regards
Adarsh Verma