
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2020 07:39 AM
I have a service catalog where I have two fields :
1. Contract Number - Single line text (independent variable)
2. Assets (Multi row variable set having one variable of type reference to asset)
Now, when I enter Contract Number, I should see only those assets which are associated in that contract.
I wrote a script include :
getAssetsForCustomer: function(contractNumber) {
gs.info('Checkpoint 1 '+contractNumber);
if (contractNumber == '') {
gs.info('Checkpoint 2 '+contractNumber);
return '';
} else {
gs.info('Checkpoint 3 '+contractNumber);
var contractId = '';
var grContract = new GlideRecord("ast_contract");
grContract.addQuery("number", contractNumber);
grContract.query();
if (grContract.next()) {
contractId = grContract.sys_id;
}
if(contractId == ''){
gs.info('Checkpoint - Empty contractId');
return '';
}
var AssetIDs = [];
var gr = new GlideRecord("clm_m2m_contract_asset");
gr.addEncodedQuery("contract="+contractId);
gr.query();
while (gr.next()) {
if(AssetIDs.indexOf(gr.asset.toString()) == -1){
AssetIDs.push(gr.asset.toString());
}
}
if(AssetIDs.length == 0){
return '';
}else{
gs.info('Checkpoint 4'+AssetIDs.join(','));
return 'sys_idIN'+AssetIDs.join(',');
}
}
},
I am calling this function in reference qualifier as below :
javascript:new global.TestUtils().getAssetsForCustomer(current.variables.contract_number);
In the logs I am getting the parameter as undefined(Checkpoint 1 and Checkpoint 2) i.e. current.variables.contract_number is undefined
Could you please help me pass a catalog variable into this function?
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2020 08:02 AM
This is not supported
Variables that are not included in a multi-row variable set cannot be used in dependent reference qualifiers for variables in the multi-row variable set.
Similarly, the variables included in the multi-row variable set cannot be used in dependent reference qualifiers for variables that are not in the multi-row variable set.
For a reference qualifier, the current row is the one that is being edited.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2020 08:09 AM
Thanks Ankur for the confirmation.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2020 03:50 PM
Hi Mahesh,
We had same problem statement, and we found the solution have posted it in the article link below.
See if this helps you, and if does, please mark it helpfu
https://community.servicenow.com/community?id=community_article&sys_id=b92de10cdb146410fa192183ca9619df

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2020 03:51 PM
Hi Mahesh,
We had the same problem statement, and we found the solution have posted it in the article link below.
See if this helps you, and if does, please mark it helpful.
ServiceNow Community Article link

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2021 09:41 AM
Found a workaround.
1. Create onChange client script on the item level that writes the independent variable value to a global javascript variable:
function onChange(control, oldValue, newValue, isLoading) {
contract_number = newValue;
}
2. Create duplicate variable for the independent variable on the MRVS. You can set the variable Hidden so it is not seen on the MVRS. You can also just leave the data type as Single Line Text as all we are concerned with is the value.
3. Create onLoad client script on the MRVS to set the duplicate variable value
function onLoad() {
g_form.setValue('contract_number',contract_number);
}
4. Voila, everything should work from here!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 02:49 AM
Hi
Issue is that the 'global' variable I am setting on the Catalog Item onChange script seems not to be available to the onLoad script on the MRVS with error:
ReferenceError: variableToPass is not defined
Sample code:
// onChange script on catalog item level - populates 'variableToPass' as expected
var variableToPass = "";
function onChange(control, oldValue, newValue, isLoading)
{
if(isLoading || newValue == '')
{
return;
}
variableToPass = newValue;
console.log("variableToPass OC " + variableToPass);
}
//onLoad script of MRVS - 'variableToPass' not defined
function onLoad()
{
console.log("variableToPass " + variableToPass);
g_form.setValue('variableToPass', variableToPass);
}
Anything I may have missed? Not sure I want to use this implementation but I'd least like to get it working and decide from there.
Thanks