currentUser.hasRole('u_dmn_cost_vendor_exempt') Line is not working

thaduri sai
Tera Contributor

Hi Team,

 

For Demands under Cost Plan tab. we return logic for users to view the cost plans.

1. If user is vendor they can't able to view Cost plan. This is working expected.

2. If user is vendor and user having u_dmn_cost_vendor_exempt role. Then they can able to view. This behaviour is not working.

 

We have a read ACL for this :- 

answer = new EPSPPMUtil().checkVendorAccessToCostPlan(current.resource_type.u_vendor);
 
Script inculde is :-
checkVendorAccessToCostPlan: function(costTypeCompany) {
        var currentUser = gs.getUser();
        var currentCompany = new GlideRecord('core_company');
        currentCompany.get(currentUser.getCompanyID());
        //gs.log("gethere0 costTypeCompany: "+costTypeCompany);
        //gs.log("ID : "+current.task.number);
        //gs.log("ID Task : "+current.u_demand_task.number);
        // is vendor
        if (currentCompany && currentCompany.vendor){
            //is lead SD or is collborator or part of assignment group of demand task
            //gs.log("****** assignmentGroup" +  current.u_demand_task.assignment_group.name );
            if (current.task.assigned_to==gs.getUserID() || current.task.collaborators.includes(gs.getUserID()) || current.task.u_collaborators.includes(gs.getUserID()) || currentUser.isMemberOf(current.u_demand_task.assignment_group)){
                //for vendors - check if vendor company matches cost type company, or cost type company is empty (in case of fixed cost type)
                //gs.log("gethere1 currentCompany.name: "+currentCompany.name);
                if (currentCompany.sys_id == costTypeCompany || costTypeCompany == ''){
                    //gs.log("gethere2");
                    return true;
                } else if(currentUser.hasRole('u_dmn_cost_vendor_exempt') ){//allow to see cost
                    return true;
                }else return false;
            } else {
                return false;
            }
        }else{
            return true;
        }
    },
 
This currentUser.hasRole('u_dmn_cost_vendor_exempt') Line is not working.
 
Thanks,
Saikrishna
8 REPLIES 8

and two read ACL:-

 

thadurisai_0-1749317509200.pngthadurisai_1-1749317530491.png

 

@thaduri sai  Picture is not clear..please share the clear picture

Hi @J Siva ,

 

Could you please help on this.

 

Thanks,

Saikrishna

@thaduri sai try the below and see..

    checkVendorAccessToCostPlan: function(costTypeCompany) {
        var companyId = gs.getUser().getRecord().getValue('company');
        var currentCompany = new GlideRecord('core_company');
        currentCompany.get(companyId);
        if (currentCompany.hasNext()) {
            if (currentCompany.vendor) {
                //is lead SD or is collborator or part of assignment group of demand task
                //gs.log("****** assignmentGroup" +  current.u_demand_task.assignment_group.name );
                if (current.task.assigned_to == gs.getUserID() || current.task.collaborators.includes(gs.getUserID()) || current.task.u_collaborators.includes(gs.getUserID()) || gs.getUser().isMemberOf(current.u_demand_task.getDisplayValue('assignment_group'))) {
                    //for vendors - check if vendor company matches cost type company, or cost type company is empty (in case of fixed cost type)
                    //gs.log("gethere1 currentCompany.name: "+currentCompany.name);
                    if (currentCompany.sys_id == costTypeCompany || costTypeCompany == '') {
                        //gs.log("gethere2");
                        return true;
                    } else if (gs.hasRole('u_dmn_cost_vendor_exempt')) { //allow to see cost
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            } else {
                return true;
            }
        }else {
                return true;
            }
    },