Scripting Help- Querying the Database and returning a True/False Answer for onCellEdit Client Script

Su522
Kilo Sage

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

Matching field is the 'Order' field on the 'Order Line Item'table: 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:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var gFormAlreadySubmitted = false;

// Callback to the Script Include
    var ga = new GlideAjax('OrderLineItems');
    ga.addParam('sysparm_name', 'getOrderLineUpdated');
    ga.addParam('sysparm_order', g_form.getValue('order_line_item.order'));
    ga.getXML(callbackdata);

    function callbackdata(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");

        // Check if the new state is "Sent to billing" and if Order Line Items have been updated
        if ((newValue === '4') && (answer == 'true')) {

            // Opens Pop Up Window

 

Script Include (client-callable):

var OrderLineItems = Class.create();
OrderLineItems.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    getOrderLineUpdated: function() {
        var grI = new GlideRecord("sn_ind_tmt_orm_order_line_item");
//        gs.info("Order: " + this.getParameter("sysparm_order"));
        grI.addQuery("order", this.getParameter("sysparm_order"));
        grI.query();
        while (grI.next()) {
            if (grI.getValue("u_order_line_updated") == "1") // If it is true
                return true;
        }
        return false;
    },
    type: 'OrderLineItems'
});

 

 

Help is GREATLY appreciated!!!

Thank you

5 REPLIES 5

You could try putting some logging into the script include to see where it's getting hung up.

 

In the list view of order line items [sn_ind_tmt_orm_order_line_item], do a list query filter using the same query fields and take a look at the encoded query.

for example:

Jon23_0-1712860961657.png

encoded query: order=c26ca6ae11f43110f877366201dea656^u_order_line_updated=true