- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2019 03:57 PM
Follow up from: Add Advanced Reference Qualifier to Variable Set that is dependent on a Catalog Item field
In a Service Catalog(shown below) I am trying set a default value on the Product field when their is only one option from the reference table. I would also like to hide this variable or set it as a read-only field with the default option.
I have already added a reference qualifier(follow up link) to that field which will filter how many options are show. If there is more than one option, I want to do nothing.
I have been playing around with Business rules, Client Scripts and UI Policies, but none have been successful. Can anyone point me in the direct of the right script to write?
Thank you.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 09:23 AM
I think it needs to be an onChange client script using GlideAjax to query the server, and if the result set has only one member, then return that member, else, do nothing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 01:20 PM
Hi B,
on the client side please adjust sysparam to sysparm in the two lines
ga.addParam('sysparam_name', 'getRMProductsLength');
ga.addParam('sysparam_cat_item', cat_item);
The SI line changes
var cat_item = this.getParameter('sysparm_cat_item');
Give one more try
------------------------------Also in the background script editor run this code---------------
var productList = [];
var gr = new GlideRecord("sc_cat_item");
gr.addQuery("sys_id", 'sys id of the cat item if you know it');
gr.query();
while (gr.next()) {
productList.push(gr.getValue('u_products'));
}
gs.info('len = ' + productList.length);
gs.info('products = ' + productList.toString());
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 01:20 PM
You have:
ga.addParam('sysparam_name', 'getRMProductsLength');
when it should be:
ga.addParam('sysparm_name', 'getRMProductsLength');
Example:
var ga = new GlideAjax('HelloWorld'); ga.addParam('sysparm_name', 'helloWorld'); ga.addParam('sysparm_user_name', "Bob"); ga.getXML(HelloWorldParse); function HelloWorldParse(response) { var answer = response.responseXML.documentElement.getAttribute("answer"); alert(answer); }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 01:49 PM
I fixed the sysparam to sysparm in the two lines in the client script and the one line in the script include however I am still getting a null alert.
@vkachineni I have tried using productList.length to get the length of the list, but it always returns 1. That is why I went with productList.toString().split(',').length
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 01:58 PM
Did you also fix the Scriopt include line? it should match the parameter name you are sending
var cat_item = this.getParameter('sysparm_cat_item');
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 02:01 PM
Yes, I fixed that one too