How to restrict/validate users for specific source warehouse and stock entry type using custom doctype(Stock Entry Restriction)

I want to restrict a users with respect to its Source warehouse and stock entry type using Custom doctype (Stock Entry Restriction) with Child table (Stock Entry Permission) .
If user saving form without using specific given validation , It should throw frappe.msgprint and frappe.throw

Custom doctype(Stock Entry Restriction)


I have applied this logic on client script :

frappe.ui.form.on(‘Stock Entry’, “validate”, function(frm) {
var email = frappe.session.user;
console.log(email);

    frappe.model.with_doc('Stock Entry Restriction',frm.doc.validate,function(){
        var table_info = frappe.model.get_doc('Stock Entry Restriction',frm.doc.validate);
        console.log(table_info);
        console.log(table_info.stock_entry_permission);
        var users = table_info.stock_entry_permission;
        
        for(var i=0;i<users.length;i++){
            var user_mail = users[i].user;
            var restrict_sw = users[i].source_warehouse;
            var restrict_set = users[i].stock_entry_type;
            console.log(user_mail);
            
            if(email==user_mail && frm.doc.from_warehouse==restrict_sw && frm.doc.stock_entry_type == restrict_set){
                console.log('success');
            }
            else{
                console.log(restrict_sw);
                
                frappe.validated = false;

                frappe.msgprint(__('You are only allowed '));
                frappe.throw(__('This is an Error Message'));
            }
        }
    });

});

But it is only checking for 1st row of validation for specific user , what should i do ?
Should I make a list or dictionary for checking this validation Or else any other solution ?

your throw in for loop that’s why look break on throw.

you can add this throw below loop.
Like this.

frappe.model.with_doc('Stock Entry Restriction',frm.doc.validate,function(){
        var table_info = frappe.model.get_doc('Stock Entry Restriction',frm.doc.validate);
        console.log(table_info);
        console.log(table_info.stock_entry_permission);
        var users = table_info.stock_entry_permission;
        
        for(var i=0;i<users.length;i++){
            var user_mail = users[i].user;
            var restrict_sw = users[i].source_warehouse;
            var restrict_set = users[i].stock_entry_type;
            console.log(user_mail);
            
            if(email==user_mail && frm.doc.from_warehouse==restrict_sw && frm.doc.stock_entry_type == restrict_set){
                console.log('success');
            }
            else{
                console.log(restrict_sw);
                
                frappe.validated = false;

                frappe.msgprint(__('You are only allowed '));
// Remove throw from here.
            }
        }
// Add throw here
        if (!frappe.validated) {
             frappe.throw(__('This is an Error Message'));
        }
    });

Actually , Error is in for loop it is checking only first row of stock entry restriction doctype .
I want to create dictionary or list so that i can store all that rows in that dictionary or list and check those data validate it , so how to do that ??