- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2016 09:11 AM
Hi all,
I have an onChange catalog client script on a list collector variable. I have made UI type to both to apply on service portal but it does not work. I am aware that some functionalities do not work on Service Portal side and need to be written in a different way. But i am not sure how to change the script for a list collector. Here is my script
Type: onChange
Catalog client script
variable type: list collector
logic: Make description mandatory if request type is empty or other request type is selected. Here request type is list collector and description is string.
script:
function onChange(control, oldValue, newValue, isLoading) {
var rightBucket = $('request_type_select_1');
for(i=0; rightBucket.options.length;i++) {
if(rightBucket.options[i].text=='Other' || newValue == '') {
g_form.setMandatory("description",true); // Set description mandatory if other request type is selected
return;
}
else {
g_form.setMandatory("description",false); // reset description not mandatory if other is not selected
}
}
}
Thank You
Reva
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2016 01:48 AM
You would just need to use the split() JavaScript function in your Client Side code.
I have tried to modify the script accordingly, but I have not tested, it. You can use it as starting point for your development, please see the below:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var arrSysId = newValue.split(",");
var currentSysId="";
for (var i=0 ; arrSysId.length > i ; i++){
currentSysId = arrSysId[i];
var ga = new GlideAjax('requestAjax');
ga.addParam('sysparm_name','Description');
ga.addParam('sysparm_type', currentSysId);
ga.getXML(DescriptionParse);
}
function DescriptionParse(response) {
var results = response.responseXML.getElementsByTagName("answer");
var type1 = results[0].getAttribute("type1");
alert("Type1: " +type1);
if(type1) {
g_form.setMandatory('description' , true); // if type1 has value
}
}
}
Please mark Correct / Helpful / Like based on the effect of this response
Best Regards,
Loris D'Avanzo | Application Developer | ServiceNow
www.servicenow.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2016 09:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2016 09:42 AM
Hi Tanumoy,
Thank You for your response. The thread was about hiding containers but not on list collector. were you trying to point to something specific.
Thank You
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2016 09:48 AM
Hi Reva,
I believe you can use the oldValue and newValue of the Catalog Client Script. They seem to work fine in the Service Portal for the List Collector variables, I just made a test in order to print value of those variables in an onChange Catalog Client Script (which variable is a List Collector).
See the script:
And the results in the browser console:
So I believe you can get rid of rightBucket and then just check if the newValue contains your other value (by using the indexOf JavaScript method for String).
Note: g_form.setMandatory should work absolutely fine in the Service Portal, so whatever is the issue with your script it should not be rooted in that function.
Regards,
Loris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2016 11:11 AM
Hello Loris,
Thank You for your response and detailed explanation.
The newValue brings the sys id or sys ids. how do i get the display value if more than one is selected in a list collector ? This is because i have to search through the display value it is other type ?
Thank You