- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2024 07:30 AM
Would someone please help me with scripting for an OnChange Client Script?
It needs to query the database to retrieve Order Management 'Order Line Items' that are associated with a 'Product Order'. The value it needs to return to the Client Script is a true/false field 'u_order_line_updated'
Order Line Item table: sn_ind_tmt_orm_order_line_item
Product Order table: sn_ind_tmt_orm_product_order
Matching field is the 'Order' field on the 'Product Order' table: order_line_item.order
Use Case:
When state changes to "X" on the Product Order table, check all associated Order Line Items, if any of them have the field 'u_order_line_updated' set to true, popup a confirmation window.
I have the Client Script created and GlideModel for the pop up working. I need help scripting this logic:
Query the Order Line Item table
If Order # matches the Order # in the Product table
Check if the Order Line Item field 'u_order_line_updated' is true
Do this for all associated Order Line Items
should return true or false
(check all associated Order Line Items, if any of them have the field 'u_order_line_updated' set to true)
Help is GREATLY appreciated!!!
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2024 02:24 PM
Hello @ssellmeyer
Here is the script include (server-side script) which checks if any order line item has u_order_line_updated field is true. If found, it returns true.
var GlideAjaxCalls = Class.create(); //GlideAjaxCalls is the script include name
GlideAjaxCalls.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOrderLineUpdated: function() //getOrderLineUpdated is the function
{
var grI = new GlideRecord("sn_ind_tmt_orm_order_line_item"); //order line item table name
grI.addQuery("order", this.getParameter("sysparm_order")); //pleae use the sysparm_order when sending the value to the server side
grI.query();
while (grI.next()) {
if (grI.getValue("u_order_line_updated") == "1") //if it is true
return true;
}
return false;
},
type: 'GlideAjaxCalls'
});
Please post here if you have any difficulty. Happy to help 🙂
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2024 02:24 PM
Hello @ssellmeyer
Here is the script include (server-side script) which checks if any order line item has u_order_line_updated field is true. If found, it returns true.
var GlideAjaxCalls = Class.create(); //GlideAjaxCalls is the script include name
GlideAjaxCalls.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOrderLineUpdated: function() //getOrderLineUpdated is the function
{
var grI = new GlideRecord("sn_ind_tmt_orm_order_line_item"); //order line item table name
grI.addQuery("order", this.getParameter("sysparm_order")); //pleae use the sysparm_order when sending the value to the server side
grI.query();
while (grI.next()) {
if (grI.getValue("u_order_line_updated") == "1") //if it is true
return true;
}
return false;
},
type: 'GlideAjaxCalls'
});
Please post here if you have any difficulty. Happy to help 🙂
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 07:41 AM
This is Amazing!! Thank you so much!!!!
How can I call this from the OnChange Client Script?
This is what I'm trying but it is not working:
// Above the onChange Function
var ga = new GlideAjax('GlideAjaxCalls');
ga.addParam('sysparm_order', "1");
ga.getXML(getOrderLineUpdated);
function getOrderLineUpdated(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
// Inside the onChange Function
if (answer) {
g_form.addInfoMessage('Order Line Item is True!');
}
The above code does do anything when I change the state on the order form...
Your help is GREATLY appreciated!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 08:22 AM
This is Awesome!!! Thank you so much!!!
How can I call this from the OnChange Client Script?
This is what I have that is not working:
// placed above the onChange function
var ga = new GlideAjax('GlideAjaxCalls');
ga.addParam('sysparm_order', "1");
ga.getXML(getOrderLineUpdated);
function getOrderLineUpdated(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
// place inside the onChange Function
if (getOrderLineUpdated) {
g_form.addInfoMessage('Order Line Item is True!');
}
Your help is GREATLY appreciated!!
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 10:20 PM
Hi @ssellmeyer
You need to update the client script like below:
var ga = new GlideAjax('GlideAjaxCalls');
ga.addParam('sysparm_name', 'getOrderLineUpdated');
ga.addParam('sysparm_order', g_form.getValue('replace_with_your_field_name')); //replace with your actual order field name
ga.getXML(callbackdata);
function callbackdata(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if(answer == 'true'){
g_form.addInfoMessage('Order Line Item is True!');
}
}
Also, your script include should like below:
Please post the screenshots if you stuck any where.
Murthy