Onchange Client script response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 08:40 AM
Hi All ,
Am using the below code in Catalog Client Scripts (variable set) onchange and using the below code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 09:59 AM
Hi @String
From what I understand, you're facing an issue where the "total" field is not updated immediately after the change in the "Item" field. This is because the onchange event is only triggered when the focus is lost on the field.
To solve this issue, you can try adding an additional event that triggers the onChange function when the "Item" field is changed. For example, you can add the "onkeyup" event to the "Item" field so that the onChange function is triggered whenever a key is pressed in the field.
Here's an example of how you can add the "onkeyup" event to the "Item" field:
// Add this to your existing code
var itemField = g_form.getControl('item_field'); // Replace "item_field" with the name of the "Item" field
itemField.onkeyup = function() {
onChange(itemField, '', itemField.value, false);
};
This should trigger the onChange function immediately after the change in the "Item" field. I hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 04:56 PM - edited 02-21-2024 04:59 PM
Hi @String ,
In onLoad event, register onkeyup event, and move your code from OnChange to onkeyup function.
function onLoad() {
var field = g_form.getControl("name");
field.onkeyup = function(){
// Move your code from OnChange to here!
alert("Put your logic here");
};
}
Please refer to the screenshot for details:
on keyup:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 07:48 PM
HI @String ,
I trust you are doing great.
Please find below reference code for the same :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// This is used for Consumable Ordering Portal
var cons = g_form.getValue('u_test');
// Call script include synchronously
var ga = new GlideAjax('test'); // Script include
ga.addParam('sysparm_name', 'getcount'); // Method
ga.addParam('test1', cons);
// Execute synchronously
var response = ga.getXMLWait();
getResponse(response);
}
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('total', answer);
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 02:44 PM
Hi @Amit Gujarathi thanks for your response ,but am getting the below Error
GlideAjax.getXMLWait is no longer supported !