The CreatorCon Call for Content is officially open! Get started here.

How to make a readonly field as editable for users in particular group

test1231998
Tera Contributor

I have a field company on cmdb_ci table which is read only for all users except admin. I want to make this field editable for only those users belonging to a particular group. can anyone please help me with the code or solution

17 REPLIES 17

Yes this is what I want But I dont see it working as expected 

function onLoad(){

if(g_scratchpad.isMember.toString() == 'true'){
g_form.setReadOnly('company', false);
}

}

Hi,

As per your question you require this

1) if the logged in user is member of that group then it is editable

2) if the logged in user is not member of that group then it is read-only

so my script does the same

you should use false to compare

function onLoad(){

if(g_scratchpad.isMember.toString() == 'false'){

// also if that field is mandatory first make it non-mandatory

g_form.setMandatory('company', false);

g_form.setReadOnly('company', true);

}

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@deepika 

Hope you are doing good.

Would you mind marking the best matching answer as correct and helpful, to close this thread?

Regards
Ankur

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader