Any chance of Auto click Ok (alert) for catalogs client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 01:15 PM
Hi Team ,
Am using the below code in catalogs client script ,we are showing alert in onchange ,but user should not click Alert OK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 12:56 AM
Hi @String
I could think of the below approach :
- Make the Add Button Disabled whenever an asynchronous Ajax call is being made on the "on change" event for Field A. Before making the AJAX call, you can disable the Add button and once you get a response, you can enable it. This way, you could restrict users from clicking the add button until you have value for field B. Refer below posts to make this work :
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2024 09:26 AM
Hi @String ,
To address your requirement, you can introduce a delay without using an alert by utilizing JavaScript's setTimeout() function. This function allows you to delay the execution of a piece of code for a specified amount of time. Here's how you can modify your code to introduce a delay after the user clicks the Add button:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Assuming 'check' is the field being changed (Field A)
var test1 = g_form.getValue('check');
// Delay the execution of the AJAX call by 2 seconds (2000 milliseconds)
setTimeout(function() {
var ga = new GlideAjax('Cus'); // Script include
ga.addParam('sysparm_name', 'gettest'); // Method
ga.addParam('consumable', test1);
ga.getXML(getResponse);
}, 2000); // Adjust the delay time as needed
}
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('test', answer);
}
In this code:
- We use setTimeout() to delay the execution of the AJAX call by 2000 milliseconds (2 seconds).
- After the specified delay, the AJAX call is made to retrieve the value for Field B (test) based on the value of Field A (check).
- Once the response is received, the getResponse() function is called to handle the response and set the value of Field B accordingly.
This approach should introduce a delay between when the user clicks the Add button and when the AJAX call is made, ensuring that the asynchronous call completes before proceeding with the form submission. Adjust the delay time (2000 milliseconds in this example) as needed to suit your requirements.
Please mark my answer as Accepted as Solution & hit helpful if it suffices your requirement !!! so that it will help other mates too !! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2024 11:56 AM
Hi @String ,
you can try timeout session for alert which will delay the pop up,
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang