Skip to content

Commit 6012eff

Browse files
authored
Get MRVS values from parent (ServiceNowDevProgram#873)
* Create onload.js * Create readme.md
1 parent 0ea3cfb commit 6012eff

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function onLoad() {
2+
3+
/*
4+
* work out the parent form based on platform and return the given MRVS data
5+
* This could go in a global UI script but that wouldn't work for Portal,
6+
* would love anyone to suggest an alternative for portal :)
7+
*/
8+
function getMRVSDataFromParent(mrvsName) {
9+
var parent_g_form = g_service_catalog.parent; // default for backend/platform
10+
if (parent.angular) {
11+
// this is portal so get a different way
12+
var parentItem = parent.angular.element(parent.$('#sc_cat_item').find('sp-variable-layout')[0]).scope();
13+
parent_g_form = parentItem.getGlideForm();
14+
}
15+
var vmData = parent_g_form.getValue(mrvsName);
16+
// on portal we get back an empty string rather than an empty array so convert
17+
return vmData == '' ? [] : JSON.parse(vmData);
18+
}
19+
20+
var vmJSONData = getMRVSDataFromParent('virtual_machine');
21+
console.log("JSON " + JSON.stringify(vmJSONData, '', 3));
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Get Multi-row Variable Set Values from parent form
2+
3+
Sometimes you need to query the current set of values for a MRVS from the actual MRVS or another MRVS.
4+
This requires getting the data from the parent form, the method to retrieve and the format of the data is different
5+
when running on the platform or portal.
6+
7+
This script gives a way of getting the values regardless of the platform in use.
8+
9+
On the platform (backend) this could be moved to a global UI Script, but that is not available to portal scripts.
10+
11+
Make sure the UI Type is All, and Isolate Script is false (unchecked).

0 commit comments

Comments
 (0)