Help in Client Script: If user belongs to CMDB assignment group, he can edit a field in cmdb table

ArushiG
Tera Contributor

Hi team,

Please help me with a client script on cmdb_ci_hardware table:

 

If a user belongs to cmdb_ci_hardware table, he should be able to edit the new field "External IP". I've written the below:

 

function onLoad() {
   //Type appropriate comment here, and begin script below


    var usrdetail = g_user.getUserID();
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('user', usrdetail);
    gr.addQuery('group', '47d86fe1db7f845055434cb11596192a');
    gr.query();
   
    if(gr.next()){
        g_form.setVisible('u_external_ip',true);
        g_form.setReadOnly('u_external_ip', false);
    }
       
    else{
        g_form.setVisible('u_external_ip',false);
        g_form.setReadOnly('u_external_ip', true);
    }
   
}
13 REPLIES 13

No @ArushiG 

 

Just write your script in script field that's it. It will work. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Thank you, I'll try that and update here

@ArushiG 

 

Or if not all members at once - 

 

answer = gs.getUser().isMemberOf('47d86fe1db7f845055434cb11596192a') 

 

That's it. This one line is enough. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

 

Thank you, I will go online in sometime, I'll try it and will reply, thank you

Sure @ArushiG 

 

Kindly mark my original answers as solution if that works for you. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY