
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
02-14-2021 09:35 PM - edited 08-17-2024 10:00 AM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
Wouldn't it be awesome, to create a dynamic Multi-Row Variable Set form, based of the contents of the Catalog Item? Up to the Paris release, this was limited possible. Reading through the Quebec release notes again and again I noticed… "Create a dynamic MRVS form by accessing all data in the catalog item form".
That sounds interesting, though also what is it exactly about? Let's have a closer look!
Accessing Catalog Item data within Multi-Row Variable Set
Paris release
When setting up a Multi-Row Variable Set, you'll notice that within the Catalog UI Policy and Catalog Client Script, there's no option to select a Variable from outside the Multi-Row Variable Set. Also, scripting like g_form.getValue() won't get data from Variables outside the Multi-Row Variable Set.
So basically, if you would stick with the above methods, accessing Catalog Item data within a Multi-Row Variable Set is not possible. There are some exceptions, one for example when automatically populating Multi-Row Variable Set records.
At least… this is how it is up to the Paris release.
Quebec release
So what has changed with the Quebec release then, changed so you can access Catalog Item data within a Multi-Row Variable Set? Let's skip Catalog UI Policies (no changes that a noticed there), and going straight to Catalog Client Scripts. The Docs mentions a new API, "g_service_catalog". An API that also works in all environments, such as, Service Portal, Now Platform, Workspace, and Now Mobile. The API is described as "The g_service_catalog API enables you to access data in a multi-row variable set (MRVS) when a model is open. This API is available in all environments, such as, Service Portal, Now Platform, Workspace, and Now® Mobile".
The g_service_catalog_api has only one method available (or one documented, there might be more, who knows), method "getValue()" which can be used like:
g_service_catalog.parent.getValue("your_variable")
Example usage
Let's give it a go. For example, having a Catalog Item with a "Decision" Variable (of type Yes / No), and based on the Decision set in the Catalog Item, having certain Variables within the Multi-Row Variable Set modal visible or maybe even containing certain pre-filled data.
Multi-Row Variable Set Variables
Adding two Variables to the Multi-Row Variable Set:
- Show Yes
- Show No
Both of type Single Line Text. Let's immediately tick the "Hidden" checkbox on these Variables. This would make the Variable concerned hidden onLoad (hiding a Variable onLoad is new in the Quebec release, read about it in one of my recent articles: New "Hide" variable field (onLoad)).
Basic onLoad Catalog Client Script
A basic onLoad Catalog Client Script within the Multi-Row Variable Set, responding to the Decision Variable from the Catalog Item, could be something like:
function onLoad() {
var decision = g_service_catalog.parent.getValue("decision");
if(decision == "Yes") {
...
} else if(decision == "No") {
...
}
}
Creating a Dynamic Multi-Row Variable Set form (1)
Let's enrich the If statement, making the Variables concerned visible.
if(decision == "Yes") {
g_form.setVisible('show_yes', true);
} else if(decision == "No") {
g_form.setVisible('show_no', true);
}
Just simply using good old g_form.setVisible().
Creating a Dynamic Multi-Row Variable Set form (2)
Can we do more? Just for fun, just exploring… let's test with pre-filling the Variable and adding an Info or Error Message.
if(decision == "Yes") {
g_form.setVisible('show_yes', true);
g_form.setValue('show_yes', 'Showing the Yes Variable…');
g_form.addInfoMessage('YES!');
} else if(decision == "No") {
g_form.setVisible('show_no', true);
g_form.setValue('show_no', 'Hope this will show the No Variable…');
g_form.addErrorMessage('NO!');
}
Result
Nice all this theory, though what is the actual result of this?!
After selecting Yes, and opening the Multi-Row Variable Set modal:
After selecting No, and opening the Multi-Row Variable Set modal:
---
And that's it actually. Hope you like it. If any questions or remarks, let me know!
C |
If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.
Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in? |
Kind regards,
Mark Roethof
ServiceNow Technical Platform Architect @ Quint Technology
2x ServiceNow Developer MVP
2x ServiceNow Community MVP
---
- 10,605 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This is amazing.
This was very much needed.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Great. That would be very useful for my employee monitoring forum
here https://www.worktime.com/employee-monitoring
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I am trying to do something similar but the other way round. So i have a variable within the MRVS and based on the choice selected, it should make catalog variable visible/mandatory. Cannot seem to get it to work. Please see onChange client script below.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 'CSL Managed Services') {
g_service_catalog.parent.setVisible('customer_request_date', true);
g_service_catalog.parent.setVisible('select_appointment_slot', true);
g_service_catalog.parent.setVisible('delivery_address_for_csl_router_s', true);
g_service_catalog.parent.setVisible('is_this_a_new_or_existing_line_installation', true);
} else if (newValue != 'CSL Managed Services') {
g_service_catalog.parent.setVisible('customer_request_date', false);
g_service_catalog.parent.setVisible('select_appointment_slot', false);
g_service_catalog.parent.setVisible('delivery_address_for_csl_router_s', false);
g_service_catalog.parent.setVisible('is_this_a_new_or_existing_line_installation', false);
}
}
Any guidance much appreciated
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How would this work if Decision was a reference field and the requirement is to filter a reference field on the MRVS based on the Sys ID of the decision field value?
If it does not work, should I go with session storage? SOLVED: Issue with MRVS multi row variable set accessing the form values
Thanks.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I'm trying to use this value in a Reference qualifier within the MRVS:
javascript: "u_is_active=true^account_parent=" + g_service_catalog.parent.getValue("u_customer_parent_account")
But I cannot get that to work. User error or know issue?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I guess the documentation answers my question (emphasis mine).
Returns the value of the specified field on the catalog item form when used in a client script on multi-row variable sets (MRVS).
Is there a way to use a client script to make the value available to the reference qualifier?