Populate templates in a reference field based on Groups selected in template..

micky09
Tera Contributor

I have created a custom field called Template in a table which is referencing to the sys_template table, now the requirement is to only populate those template records from sys_template table in the template field for which the logged in user is member of the groups selected in sys_template record while creating the template or Global checkbox is checked... 

4 REPLIES 4

Amit Pandey
Kilo Sage

Hi @micky09 

 

Please create Before Business Rule with the following script-

 

(function executeRule(current, previous, operation) {
    //
    var currentUser = gs.getUser();
    var templateGroups = current.getValue('groups'); // Assuming 'groups' is the field referencing groups in sys_template table

    // Check if the Global checkbox is checked
    var isGlobal = current.getValue('global_field'); // Replace 'global_field' with the actual field name

    if (isGlobal || currentUser.isMemberOf(templateGroups)) {
        // User is member of the groups or Global checkbox is checked, allow the operation to proceed
        gs.log('User is authorized to use this template');
    } else {
        // User is not authorized, cancel the operation and display a message
        gs.addErrorMessage('You are not authorized to use this template.');
        current.setAbortAction(true);
    }
})(current, previous, operation);

Hi Amit, Thanks for the reply, but as I said we created a reference field called as Template which reference to sys_template table and we need to hide the templates from the users in that field for which user is not member of the selected groups

 

micky09_1-1710148681176.png

so we need to show only those templates in that field for which user is member of the group for example u can see in the image CAB Approval..

Hi @micky09 

 

Did the above script not work? I think it should.

 

Regards,

Amit

micky09
Tera Contributor

No, I need to create a reference qualifier where in template field only those templates will be visible to the  user who is a member of the groups added in the sys_template record as mentioned in the screen shot or he or she have knowledge_manager role..