Help: Business Rule is not working.

YummyAmericano
Tera Contributor

Developers,

I am seeking guidance on resolving an issue that is currently impeding progress. In my scope application, I have implemented a Business Rule that validates supplier matches and creates/updates records accordingly. However, I have encountered a problem with a particular section of the script that fails to update the value in the Global. Specifically, it is unable to update the 'u_last_verified_date' field with today's date. This field is of the Date type. I would greatly appreciate your advice on how to rectify this issue. Thank you in advance.

Here is the BR script (part that is not working):

 // Update 'u_last_verify_date' in 'u_current_sup' table in Global to today's date

// I tried this and it is not working
        supplierGR.u_last_verify_date = gs.nowDateTime();
        supplierGR.update();*/

// I tried this and it is not working
		var today = new GlideDate();
		supplierGR.u_last_verify_date = today;
		supplierGR.update();



Here is the BR Script in the scope application:

(function executeRule(current, previous /*null when async*/ ) {

    // Check if there is a matching supplier in 'u_current_sup'
    var supplierGR = new GlideRecord('u_current_sup');
    if (supplierGR.get('u_supplier_code', current.supplier_code)) {

        // Reconcile for existing supplier code
        var outputGR = new GlideRecord('x_new_sup');
        outputGR.addQuery('supplier_code', current.supplier_code);
        outputGR.query();

        if (outputGR.next()) {
            // Update existing record for reconciliation
            // Bring over the status to the output table
            outputGR.new_status = current.supplier_status; // copy over new active status
            outputGR.current_status = supplierGR.u_active; // copy over current active status
            outputGR.update();
        } else {
            // Create a new record for reconciliation
            outputGR.initialize();
            outputGR.supplier_code = current.supplier_code;
            outputGR.supplier_name = current.supplier; //supplierGR.supplier;
            outputGR.new_status = current.supplier_status;
            outputGR.current_status = supplierGR.u_active;
            outputGR.insert();
        }

        // Update 'u_last_verify_date' in 'u_current_sup' table in Global to today's date
        /*supplierGR.u_last_verify_date = gs.nowDateTime();
        supplierGR.update();*/

		var today = new GlideDate();
		supplierGR.u_last_verify_date = today;
		supplierGR.update();


    } else {
        // Reconcile for new supplier code
        var newSupplierOutputGR = new GlideRecord('x_new_sup');
        newSupplierOutputGR.initialize();
        newSupplierOutputGR.supplier_name = current.supplier;
        newSupplierOutputGR.supplier_code = current.supplier_code;
        newSupplierOutputGR.new_status = current.supplier_status;
        newSupplierOutputGR.current_status = current.supplier_status; // Assuming 'u_supplier_status' for new suppliers
        newSupplierOutputGR.new_supplier = true; // set new supplier to true
        newSupplierOutputGR.insert();
    }

})(current, previous);

 

12 REPLIES 12

Siddhesh Gawade
Mega Sage
Mega Sage

Hello @YummyAmericano ,

 

Can you check the type of u_last_verify_date ? It should be date time field not only date field. As you are settling the date time value

 

The field 'u_last_verify_date' is of type (Date); this is the really the output I am looking for which is without the time.
However, I also have another field called 'u_last_verified_date' which is of type (Date/Time), for testing purposes as my script is not working. The script is not updating this field too.

SanjivMeher
Kilo Patron
Kilo Patron

Can you try below?

 

var gdt = new GlideDate();
supplierGR.u_last_verify_date = gdt.getValue();
supplierGR.update();

  


Please mark this response as correct or helpful if it assisted you with your question.

Thanks for the script but it is not updating the value as well.