Restrict insertion and updation of asset record if "Assigned to" user had already same model categor

Anusha Kunta
Tera Contributor

I want to restrict records getting inserted and updated in alm_hardware table if user is already assigned to a model category except categry is not "Rugged device"

I am currently using the below Business rule but when I update a asset record even though user doesn't have any other asset with the same model category it shows user already has asset with same model category.

AnushaKunta_0-1709825186846.png

AnushaKunta_1-1709825230936.png

 

Please help me with the script

 

2 REPLIES 2

Shruti
Mega Sage
Mega Sage
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('alm_hardware');
gr.addEncodedQuery('assigned_toISNOTEMPTY^assigned_to='+current.assigned_to+'^model_category='+current.model_category);
gr.query();
if(gr.next()){
    gs.addErrorMessage("Same model category exists");
    current.setAbortAction(true);
}

})(current, previous);

Anusha Kunta
Tera Contributor

Hi Shruti,

 

Thanks for the response, but it is still the same issue.

When I update the asset record which the "Assigned to" user has only one asset with that category still it showing the error message and aborting action which ideally should not happen. Could u pls suggest any other idea