Make reference variable dependant on another reference variable

SN_BUDDY
Tera Guru

I have an "Account" variable (reference field) to customer_account table and i have a "Site" variable (reference field) to cmn_location table. The "Site" variable sits in a MRVS. When account is selected and i click into the MRVS and select "Site" i should only see sites relating to the account.

 

The relationship is, there is an account field within the location table which captures the account.

 

I thought this would be simple with Ref qualifier and variable attributes but cannot get it to work

1 ACCEPTED SOLUTION

Its sorted. Managed to populate the account field from the below script

 

function onLoad() {
	
	//populates the Account_capture variable with the Account variable selected.
g_form.setValue('account_new', g_service_catalog.parent.getValue('account'));
}

View solution in original post

6 REPLIES 6

DrewW
Mega Sage
Mega Sage

This post goes thru it

https://www.servicenow.com/community/developer-articles/solved-dependent-variable-on-catalog-item-us...

 

You need to set the Variable attribute ref_qual_elements to get the dependent attribute to work.

 

Thanks for the response. I did try this but it did not work. Its the MRVS causing the issue. I need to populate the account_new variable in MRVS from the account variable outside the MRVS

Its sorted. Managed to populate the account field from the below script

 

function onLoad() {
	
	//populates the Account_capture variable with the Account variable selected.
g_form.setValue('account_new', g_service_catalog.parent.getValue('account'));
}

BharathChintala
Mega Sage

@SN_BUDDY 

 

here is script please change it with your variable backend names

 

You need to create a reference variable to account table in Multi row variable set and hide it.

 

Create below catalog client scripts in cat item to pass account details to MVRS.

1. Pass Account(onChange applies to catalog item)

BharathChintala_6-1680199401966.png

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (typeof(Storage) !== "undefined") {
sessionStorage.setItem("account", "" + g_form.getValue('accounts'));
} else {
alert("Sorry, your browser does not support Web Storage...");
}

}

 

2. Get Account(onLoad applies to catalog item)

BharathChintala_5-1680199384945.png

 

function onLoad() {
if (typeof(Storage) !== "undefined") {
sessionStorage.setItem("account", "" + g_form.getValue('accounts'));

} else {
alert("Sorry, your browser does not support Web Storage...");
}
}

3.  Get Program (OnLoad on MVRS set)

BharathChintala_4-1680199344456.png

 

function onLoad() {
var account = sessionStorage.getItem("accounts");
g_form.setValue('account', account);
}

 

Now with account is available in MVRS you can write simple ref qualifier and filter records.

 

Let me know if you need help with ref qual.

 

 

 

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala