Checkbox onChange catalog client script on Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2017 02:30 PM
I created a test Service Catalog with 2 variables. One checkbox and other as single line text. Created a catalog UI Policy to show single line text when checkbox is checked or true. Then an onChange catalog client script of checkbox to alert true if checkbox if true and alert false if checkbox is false.
Then I went to service portal opened the service catalog, clicked on checkbox, the single text field appears and the first alert comes as true.
To the surprise the alerts never stops. It keeps on running again and again.
Next thing I tried the same with only a difference of variable type as yes/no. Everything worked fine and there was only one true alert.
Is this a Service portal bug with onchange catalog client script for checkbox?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2017 07:22 PM
That may be a product issue but you should be able to bypass it using below code at beginning of script.
if(newValue == oldValue){
return;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 06:58 AM
This solution looks to be working but when you add another alert in your code you will see that the client script keeps on rendering again and again which is not a best programming method.
if(newValue == oldValue){
alert('return');
return;
}
This will give you infinite loop of return alert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 04:14 AM
Hi Karan i think it is scripting issue may be am also agree with Gurpreet
For better coding u can follow the coding best practices that will prevent this type of issues for above issue u can follow this code
for more information http://wiki.servicenow.com/index.php?title=Client_Script_Best_Practices#gsc.tab=0
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading)
return;
if (newValue) {
if (newValue != oldValue) {
//write ur code here
}
}
}