How to find which field/variable are avaliable on catalog form at Service Portal using client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 09:29 AM - edited ‎01-06-2025 09:29 AM
Hi All,
I have requirement to update only the variable/fields available on the form at service portal and not RITM/SCTASK.
but I am unable to get that information in catalog client script as g_form.getFieldNames() or g_form.isVisible() methods are not available/deprecated in Xanadu version.
So can you please help me or guide me how I can get the fields names that are available in current form through client Script.
Thank you in advance.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 09:56 AM
@Prabhu4 Please find the link below for reference,
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 10:30 AM
Hi @Sujatha V M
Thanks for the reference, I tried to implement the same but getting "There is a JavaScript error in your browser console" attached the screenshot of the same along with the script. Seems like g_form.elements method is no longer available in Xanadu version.
I also tried getControl but still no luck but thank you for input.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 10:56 AM
@Prabhu4 @Could you please try the below syntax accordingly,
function onLoad() {
// Retrieve all variables
var variableNames = g_form.getEditableFields(); // Returns an array of field names (variables).
// Loop through and retrieve all variable names
variableNames.forEach(function(variable) {
var variableValue = g_form.getValue(variable);
// Get the value
alert("Variable Name: " + variable + ", Value: " + variableValue);
});
}
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2025 12:27 AM - edited ‎01-07-2025 12:28 AM
@Sujatha V M I tried the above script, it is working in getting the variable names available in catalog(even if they are hidden at the portal level), the g_form.getEditableFields() is not available in ServiceNow documentation, so I thought I won't work but it worked. Thanks to you.
Also I tried to use isVisible method as well to filter the variable but still no luck as it is returning true only even if the field is hidden on portal. can you suggest any other method to get only variable available at portal only. Attaching the screenshots FYR of both scenarios
Field2 is hidden on portal level in example catalog.
Client Script
function onLoad() {