Scripting Help- Querying the Database and returning a True/False Answer for onCellEdit Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 08:34 AM
Would someone please help me with scripting for onCellEdit Client Script?
I have an onChange Client Script that works, but I need to replicate the same functionality with an onCellEdit Client Script.
The onChange Client Script uses a GlideAjax call to a Script Include.
The Script Include queries the database and returns a True/False Answer
The Client Script uses that Answer to determine if a pop up should display with 2 options: 'Yes' (proceed) or 'Cancel'
Needed Outcome:
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.
The onChange Client Script, GlideModel for the pop up, and the associated Script Include is working.
I need help scripting to replicate this functionality for an onCellEdit Client Script with 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)
Here is the code that is working for the onChange Client Script and Script Include-
onChange Client Script:
Script Include (client-callable):
Help is GREATLY appreciated!!!
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2024 08:52 AM
Hi @Su522 ,
Here is an example that should work with a few tweaks to match your fields/values:
onCellEdit Client Script
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
var ga = new GlideAjax('OrderLineItems');
ga.addParam('sysparm_name', 'hasAnyOrderLineUpdated');
ga.addParam('sysparm_order', sysIDs);
ga.getXMLWait()
var response = ga.getAnswer();
if (response == 'true') {
var messageResult = confirm('Pop Up Message'); // << This will be your pop-up message
}
if(messageResult == true) {
saveAndClose = true;
} else {
saveAndClose = false;
}
callback(saveAndClose);
}
Update your script include with additional functions:
hasAnyOrderLineUpdated: function() {
var grProductOrder = new GlideRecord('sn_ind_tmt_orm_product_order');
if (grProductOrder.get(this.getParameter('sysparm_order'))) {
return this._orderLineItemCheck(grProductOrder.order_line_item.order.getValue());
}
},
_orderLineItemCheck: function(orderLineItemSysId) {
var grI = new GlideRecord('sn_ind_tmt_orm_order_line_item');
grI.addQuery('order', orderLineItemSysId);
grI.addQuery('u_order_line_updated', true); // <<<< Change this to your specific value
grI.setLimit(1);
grI.query();
if (grI.hasNext()) {
return true;
} else {
return false;
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2024 09:54 AM
Thank you Jon. I very much appreciate your help!!
I'm trying to get the Script Include working but it is not. 'u_order_line_updated' is the correct value
Can you please take a look. Here is what I have now:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2024 09:59 AM
What field type is 'u_order_line_updated'? In my example it is a boolean but your field could be a choice as your original shows you evaluating to '1'
// if (grI.getValue("u_order_line_updated") == "1") // If it is true
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2024 10:36 AM
Hi Jon,
It is a true/false boolean