Field should be visible only for one set of people who group name contains SM.

Atchutaram
Tera Contributor

Hi Team,

We have a requirement u_kb_article field on change request should be visible only for people who belong to group names contains "SM", we have multiple groups that has "SM"  in like Test -SM-test. how can i achieve this?

 

Best Regards

4 REPLIES 4

glideFather
Tera Patron

Hi @Atchutaram,

 

from design perspective a condition that "group starts of [XY]" doesn't seem to be optimal.

 

ACL

  • Consider adding a new group type (that can be called "SM") and make the display condition in ACL based on the group type...

 

Role

  • Or onLoad (catalog) client script with g_user.hasRoleExactly('');

 

Group name starting with "SM"

  • it would require a onLoad catalog client script to display in Portal and one client script to display in backend, both would call a GlideAjax call to check if the logged in user has been a member of "SM" group.

 

g_scratchpad

  • display BR and onLoad client script
  • backend only
  • not applicable in portal

 

Ankur Bawiskar
Tera Patron

@Atchutaram 

Multiple ways to achieve

1) you can use field level READ ACL on that field, use advanced script in ACL, ensure you give correct role in ACL

var userId = gs.getUserID();
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userId);
gr.addQuery('group.name', 'LIKE', 'SM');
gr.setLimit(1);
gr.query();
answer = gr.hasNext();

OR

2) Display business rule + onLoad client script

Display BR on change_request table

(function executeRule(current, previous /*null when async*/ ) {
    var userId = gs.getUserID();
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('user', userId);
    gr.addQuery('group.name', 'LIKE', 'SM');
    gr.setLimit(1);
    gr.query();
    g_scratchpad.show_kb_article = gr.hasNext();
	
})(current, previous);

onLoad client script

function onLoad() {
    // Check the value from g_scratchpad
    var canSeeKbArticle = g_scratchpad.show_kb_article;

    if (canSeeKbArticle) {
        g_form.setVisible('u_kb_article', true);
    } else {
        g_form.setVisible('u_kb_article', false);
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

@Atchutaram 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.