How to get the message in form when a async business rule is running

Anna_Servicenow
Tera Guru

I have the below scope SI and async BR . Its important that I show the message on form, but I am unable to do this as I am calling this from Asyn BR. How to fix this.

var AttachmentParserScoped = Class.create();
AttachmentParserScoped.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    getExcelInfo: function(sysId, callback) {
  
        var currentSysId = sysId;
        var attachment = new GlideSysAttachment();
        var getdata = new GlideRecord('sys_attachment');
        getdata.addQuery('table_sys_id', sysId);
        getdata.addQuery('table_name', "x_fdrbl_business");
        getdata.query();
    
        if (getdata.next()) {
            //An attachment is found
            // ********Parsing the Excel to extract the data*******
            // ***** Create entries in  table******//
// Check if the username exists in sys_user table
                var userName = resolvedBy[i];
                var userDetail = new GlideRecord('sys_user');
                userDetail.addQuery('name', userName);
                           userDetail.query();
                              if (userDetail.next()) {
                    qualityControlList.resolved_by = userDetail.sys_id.toString();
                    qualityControlList.sub_team = userDetail.getDisplayValue('u_sub_team');
                    qualityControlList.parent_team = userDetail.u_parent_team;
                } else {
                    gs.addInfoMessage("Resolved by user not found: " + userName);
                }
                qualityControlList.case_id = caseID[i];
                qualityControlList.insert();
                       }
        } else {
            gs.addInfoMessage("Please attach a file to import the data");
        }
        callback();
    },
    type: 'AttachmentParserScoped'
});

Async BR:

(function executeRule(current, previous /*null when async*/ ) {
     new AttachmentParserScoped().getExcelInfo(current.getUniqueValue(), function() {
        current.import_state = 'Complete';
        current.update();
    });
})(current, previous);



5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Anna_Servicenow 

not possible as Async BR runs in background

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar Is there a workaround?

@Anna_Servicenow 

you can use a state or status field and set it to In Progress and if any error then update it with Status as Error

In this way user can come back and see if the import is In Progress or success or failure.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Anna_Servicenow 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader