Record not found

Brijmohan
Tera Contributor

Hi All,

 

I have one before query BR in which I am restricting view cases if user is not part of the assignment group. 

If user is not part for the assignment group then I am getting "Record not found" message.

 

I want to show my custom error message with 'Record not found'  but it is showing multiple times on screen like below.

 

1)Form View

Brijmohan_2-1686431569888.png

 

2) List view

Brijmohan_3-1686431664155.png

 

3)When user is not part of the assignment group.

Brijmohan_4-1686431703437.png

 

I am not sure why it showing multiple times and I want to show only 3rd case (When user is not part of the assignment group.). Please suggest how we can achieve this.

 

Below is my before query BR.

 

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

 

    if (gs.hasRole('admin') || gs.hasRole('auditor_procurement_auditor') || !gs.getSession().isInteractive()) return;

               

    var grMember = new GlideRecord('sys_user_grmember');

    grMember.addNotNullQuery('group');

    grMember.addQuery('user', gs.getUserID());

    grMember.query();

 

    var groupIDS = [];

    while (grMember.next()) {

        groupIDS.push(grMember.getValue('group'));

    }

 

    var flag = true;

    for (var i = 0; groupIDS.lenght; i++) {

        flag = false;

    }

 

    if (flag == false) {

        current.addQuery('requested_by', gs.getUserID()).addOrCondition('assignment_group', 'IN', groupIDS.toString());

    } else {

        current.addQuery('assignment_group', 'IN', groupIDS.toString());

        gs.addErrorMessage('Error for not having access to this record');

    }

 

})(current, previous);

 

Thanks in advance!

 

5 REPLIES 5

Manmohan K
Tera Sage

Hi @Brijmohan 

 

The Query Business Rule is triggered not only when accessing the table through the user interface but also during any operations that involve reading the table using Glide Record Query in scripts. 

So you will have multiple executions of the Query Business Rule since there would be many scripts that are reading the table via GlideAjax calls, g_from.reference calls or Display Business Rules

 

Hi Manmohan, 

 

Thanks for your response, is there any other way to show that message with record not found message?

@Brijmohan 

 

You can create an load client script and use GlideAjax to run same logic in script include. Based on result returned from script include, you can show the error message

Yeah I have use the on submit client script and populating the message from there but is showing only 1 second and then record not found because OOTB Query BR have more preference.  Even I cannot able to find that OOTB Query BR to override that "Record not found" message.