
- 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
‎11-30-2022 07:18 AM - edited ‎11-30-2022 07:23 AM
I appreciate I am very late with answer here, but I have had this issue today and found work around. @Ankur Bawiskar is definitely right, this is not supported, but you can get around it by using session client data.
I had this same problem:
- a variable in the mutli-row variable set needs to be dependent on a variable outside of the multi-row variable set
- using current.variables.variable_name in ref qual does not work
Solution:
- we need to store the value of the variable we want to be dependent on when it changes
- the best place to put this is session client data which is accessed on the server with gs.getSession().putClientData(property,value) and gs.getSession().getClientData(property).
- we need to use GlideAjax in an onchange catalog client script to set the property when the field we want to be dependent on changes.
- Then we can use gs.getSession().getClientData() in the reference qualifier to get the value.
Steps to implement the solution:
- create a client-side script include with a function which sets a session client data property
- Script Details
- name: MRVSDependencyHelperAjax
- client callable: true
- script:
- Script Details
var MRVSDependencyHelperAjax = Class.create();
MRVSDependencyHelperAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
/*Description - Add a property to session client data
* param - prop string - the property name to add
* param- val string - the value of the property to add
* returns - n/a no return value
*/
setClientDataForMRVSRefQual: function(){
var prop = this.getParameter("sysparm_prop");
var val = this.getParameter("sysparm_val");
gs.getSession().putClientData(prop,val);
},
});​
- create a catalog client script in the same place as the variable you want to be dependent on. For example, if he variable you want to be dependent on is on the catalog item, create the catalog client script there. If it is in another variable set, create it there. Note, I do not expect this solution would work with dependency between two multi-row variable sets.
- Catalog Client Script details:
- UI type: all
- Type: onChange
- Variable name: {the name of the variable you want to be dependent on}
- Script:
- Catalog Client Script details:
function onChange(control,oldValue,newValue,isLoading){
if(isLoading || newValue==""){
return;
}
var ga = new GlideAjax("MRVSDependencyHelperAjax");
ga.addParam("sysparm_name","setClientDataForMRVSRefQual");
ga.addParam("sysparm_prop","prop_name");//change this to be more descriptive
ga.addParam("sysparm_value",newValue);
ga.getXMLAnswer(doNothing); //my callback function does nothing because there is no response
}
function doNothing(){
return
}​
- set the reference qualifier in the variable you want to be dependent on that value
- example reference qualifier
javascript: "location="+gs.getSession().getClientData("prop_name");
So, in your case @Mahesh Kumar7 you would want the onChange catalog client script to be triggered on the contract number variable and set that value in the client data like this
function onChange(control,oldValue,newValue,isLoading){
if(isLoading || newValue==""){
return;
}
var ga = new GlideAjax("MRVSDependencyHelperAjax");
ga.addParam("sysparm_name","setClientDataForMRVSRefQual");
ga.addParam("sysparm_prop","contract_number");
ga.addParam("sysparm_value",newValue);
ga.getXMLAnswer(doNothing); //my callback function does nothing because there is no response
}
function doNothing(){
return
}​
and you reference qualifier would be something like
javascript:new global.TestUtils().getAssetsForCustomer(gs.getSession().getClientData("contract_number"));