How do I set specific variables as visible on an INC Incident Variable Editor Formatter?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2024 09:27 AM - edited ‎10-16-2024 06:42 AM
Hello All,
I need your help with making only specific variables visible within an incident form's Incident Variable Editor formatter.
Before you share links, I reviewed the following articles and still have not been able to achieve the results I'm looking for:
https://www.servicenow.com/community/developer-forum/hide-incident-variable-editor/m-p/2776495#M1067...
https://www.servicenow.com/community/developer-forum/how-to-hide-incident-variable-editor-for-certai...
Context:
I have a security record producer form that utilizes a variable set and variables to capture issues related to security threats.
The variable set is a shared variable set, used for capturing standard technical incidents. The items in the variable set are already present as a part of the incident form, and update specific fields on the INC form such as caller, category, subcategory, and location.
I know to use the Incident Variable Editor to bring in the variable set, but want to avoid, redundant information from populating on the incident record especially for the SOW view.
Here is the most recent script I tried.
// Client Script to Hide Specific Variables in the Variable Editor on Incident Form
function onLoad() {
// List of variables to hide within the Variable Editor
var variablesToHide = ['current_caller', 'caller_id', 'u_jo_yes_no', 'u_ops_yes_no', 'location', 'u_floor_level', 'callback_number', 'category', 'subcategory', 'short_description'];
// Wait for the Variable Editor to load, since it may load asynchronously
setTimeout(function () {
// Get all elements of the Variable Editor by targeting the form elements inside the Variable Editor container
var variableElements = document.querySelectorAll('div[data-type="variable"]');
// Iterate through each element and check if it needs to be hidden
variableElements.forEach(function (element) {
var variableName = element.getAttribute('id').split('.')[1]; // Extract the variable name from the element's ID
if (variablesToHide.includes(variableName)) {
element.style.display = 'none'; // Hide the variable element
}
});
}, 1000); // Delay to ensure the Variable Editor has loaded properly
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2024 03:20 PM
If you just want this logic to apply for this one item, add a catalog ui policy onto the item and set it to apply to the target record (see below). Then add the fields you want to hide as UI policy actions, with visible = false.