How to set delay in my on change client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 02:49 AM
Below is my the small part of code that i am using in my client script, could anyone please help to know that how i can place a delay there, i mean after setting the value in "category" i want to waiit for few seconds then only i should populate the sub categor.
basicall i have code "window.setTimeout(function, 5000)" to use for delay purpose but i do not know what i need to put in place keyword "function".
g_form.setValue('category',''+cat);
g_form.setValue('subcategory', subCat);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 02:58 AM
Hi @VIKAS MISHRA ,
refer below question.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 03:08 AM
The url that you have provided i have already seen that but there the code is saying that it will hold for 5 second and then it will run the another function mentioned in the code "window.setTimeout(function, 5000)" but the issue is i do not know what should i put in place of keyword "Function" becuase after holiding the screens i do not need to run any other function, instead of that after holding the screen for few seconds i need to run the next line of code to set the sub category field , so in that case how should i using this delay method
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 03:20 AM - edited 12-22-2022 03:25 AM
Hi @VIKAS MISHRA ,
If you place your script with in the function it will hold for 2 secs.
You have to place the code with in the function that you need to execute after 2 secs.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.setValue('category', '' + cat);
var setTimer = '';
setTimer = setTimeout(setTimerDelay, 2000); /*to set the timer for 2 sec*/
function setTimerDelay() {
alert('timer waits for 2 sec');
g_form.setValue('subcategory', subCat);
}
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 03:21 AM
@VIKAS MISHRA you can use the setTimeout like below
setTimeout(function(){
}, 5000);
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023