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

@Brijmohan 

 

Basically each time the system runs .query() on the current table, the business rule you have written will run and  append the additional query configured in the script. So that is why you get a lot error messages in the form

 

You should remove the error message from Query Business rule to stop the issue since its difficult to control the number of times the query business rule will run