Set values on a record using business rule

Hari1
Mega Sage

Hi,

I have created a business rule to set values on the "assessment instance question" table. I am not able to set the values. I can see the values in the logs. But still i am not able to set those values.
Below is my business rule.

 

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

    var arrQust = [];

    var obj = {};

    var recordSysId = current.getValue('sys_id');

    var wfd = new GlideRecord("u_wfd_assessment"); // custom table
    wfd.addQuery('u_assessment_number', recordSysId);
    wfd.query();
    if (wfd.next()) {
        var wfdQust = new GlideRecord('asmt_assessment_instance_question');
        wfdQust.addQuery('instance', recordSysId);
        wfdQust.query();
        while (wfdQust.next()) {
            obj = {
                metric: wfdQust.getDisplayValue('metric'),
                value: wfdQust.getValue('value'),
                stringValue: wfdQust.getValue('string_value')
            };

            arrQust.push(obj);
        }
        gs.info("WFD : Business Rule: arrQust: " + arrQust);
        gs.info("WFD : Business Rule: JSON.stringify(arrQust): " + JSON.stringify(arrQust));

        for (var i = 0; i < arrQust.length; i++) {
            gs.info("WFD : Business Rule: Assessment Number: " +wfd.getValue("u_assessment_number") + ",arrQust[i].metric: " + arrQust[i].metric + " ,arrQust[i].value: " + arrQust[i].value + " ,arrQust[i].stringValue: " + arrQust[i].stringValue);
            if (arrQust[i].metric == "Product") {
                gs.info("WFD : Business Rule: Inside if block " + arrQust[i].metric);

                wfd.product = arrQust[i].stringValue;
                //wfd.update();
				
            } else if (arrQust[i].metric == "ID") {
                gs.info("WFD : Business Rule: Inside if block " + arrQust[i].metric);

                wfd.u_id = arrQust[i].stringValue;
                //wfd.update();
				
            } else if (arrQust[i].metric == "Application Type") {
                gs.info("WFD : Business Rule: Inside if block " + arrQust[i].metric);

                wfd.u_application_type = arrQust[i].stringValue;
                //wfd.update();
				
            } else if (arrQust[i].metric == "Application") {
                gs.info("WFD : Business Rule: Inside if block " + arrQust[i].metric);

                wfd.u_application = arrQust[i].stringValue;
                //wfd.update();
				
            } 
        }
		wfd.update();
    }

})(current, previous);

 

 c1.JPG

9 REPLIES 9

RaghavSh
Kilo Patron

As per your question statement you want to set the values on the "assessment instance question" table but no where in your code you are doing wfdQust.update(); which is the object of assessment instance table  in your code.

I can see wfd.update() which will update your custom table.


Raghav
MVP 2023
LinkedIn

Sorry my bad it is not on the assessment instance question table it is on the u_wfd_assessment table that i want to update the values.

Ok then there are few more observations:
1. wfd.addQuery('u_assessment_number', recordSysId) : you are comparing sysid with number is that correct?

2. Also if your BR is on custom table and you need to update the custom table itself, why are you not using current.update()?


Raghav
MVP 2023
LinkedIn

Okay, I am creating records on the "assessment instance" table on submission of the catalog and once the records are created on the assessment instance table i am also creating records on the custom table in parallel using the background workflow. Once i take the assessment assigned to me and the state of the assessment instance gets completed and I am taking the assessment instance question table records associated with the assessment instance table and updating the custom table u_wfd_assessment table records. The business rule that is created is on the table "assessment instance" as i need the business rule to run once the state gets to completed.

Please let me know if you still have any questions.