Form variables display base on Logged in User using onLoad Client script

Peter Williams
Kilo Sage

GOod Day

 

i have a requirement where i have no idea where to go.

 

I have a Request form where different users will use but i want to have certain fields/variable to display or set to read only base on the logged in user Group Membership.

 

ex. John Smith is apart of "Group A"

Jane Doe is apart of "Group B"

 

 

Group A users will only see start date field /variable and the end date field /variable is hidden or read only

While Group B will have the start date field /variable hidden or read only while the end date field /variable they can modify

 

 

how can i:
1) detect the logged in user if they are belonging to a specific group

2) using the IF Statement i can determine if they belong to the Group A or Group B (this is the easy part)

 

i just need to know if they belongs to the group in question or not

1 ACCEPTED SOLUTION

i was able to figure it out with a onLoad client script looking for the role 

 

here is my code:

 

function onLoad() {
    // Get the current user's ID
    var mtlBC = g_user.hasRoleExactly('MTL BC');
    var mtlFS = g_user.hasRoleExactly('MTL FloorSupport');
    if(mtlBC == true){
        g_form.setValue('u_type', 'Business Center');
        g_form.setReadOnly('u_type', true);
    }
    if(mtlFS == true){
        g_form.setValue('u_type', 'Floor Support');
        g_form.setReadOnly('u_type', true);
       
    }

    if(mtlBC == true && mtlFS == true){
        g_form.setValue('u_type', '');
        g_form.setReadOnly('u_type', false);
    }
}
 
this works perfectly

View solution in original post

9 REPLIES 9

didnt work here is what i have

 

g_scratchpad.memberBC = gs.getUser().isMemberOf('71ac29298790f910124dbbbf8bbb35cd');//SYS ID of the group
 

PeterWilliams_0-1708110314003.png

 

PeterWilliams_1-1708110350847.png

 

Client SCript:

function onLoad() {
 
     if (g_scratchpad.memberBC == true){
        g_form.setValue('type', 'Business Center');
        g_form.setReadOnly('type', true);
    }
    /*if(grpBC){
            g_form.setValue('type', 'Business Center');
            g_form.setReadOnly('type', true);
    }*/
    if(!g_scratchpad.memberB){
        g_form.setReadOnly('type', false);
    }
}

 




Hi @Peter Williams ,

The Business rule should run on display.

 

Try below client script:

function onLoad() {
 
     if (g_scratchpad.memberBC == 'true'){
        g_form.setValue('type', 'Business Center');
        g_form.setReadOnly('type', true);
    }
    else {
        g_form.setReadOnly('type', false);
    }
}
 

 


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

James Chun
Kilo Patron

Hi @Peter Williams,

 

So you want to lock down variables of a RITM depending on the user's membership?

If so, there is a much easier way to get this done but you may need to create a custom role.

  1. Open the variable record
  2. Under the 'Permission' tab, you can set 'Read role', 'Create roles', and 'Write roles', which controls users' permission to that particular variable.

JamesChun_0-1708115715997.png

 

I hope it helps, thanks.

 

well that is not what i was looking for.

i know how to do this already for permissions on the field

 

i want to be able to have a select box get update by the users Group member ship or by their Role

 

 

i was able to figure it out with a onLoad client script looking for the role 

 

here is my code:

 

function onLoad() {
    // Get the current user's ID
    var mtlBC = g_user.hasRoleExactly('MTL BC');
    var mtlFS = g_user.hasRoleExactly('MTL FloorSupport');
    if(mtlBC == true){
        g_form.setValue('u_type', 'Business Center');
        g_form.setReadOnly('u_type', true);
    }
    if(mtlFS == true){
        g_form.setValue('u_type', 'Floor Support');
        g_form.setReadOnly('u_type', true);
       
    }

    if(mtlBC == true && mtlFS == true){
        g_form.setValue('u_type', '');
        g_form.setReadOnly('u_type', false);
    }
}
 
this works perfectly