make fields editable when impersonated with specific user and other field in form should be readonly

e__chaithanya
Giga Contributor

when i impersonate with ex: abel tuter all the fields which are mandatory for abel tuter in the incident form should be editable and other fields which are not mandatory for him should be readonly.

1 REPLY 1

tharun_kumar_m
Mega Guru

Hi Chaithanya,

 

We can create a onLoad client script with the below code.

 

var user = gs.getSession().getUser(); 
var table = g_form.getTableName(); //get the table name of the current form
var isStrict = GlideProperties.getBoolean('glide.soap.strict_security');
var soapSecurity = new GlideSOAPSecurity();
soapSecurity.setStrictSecurity(isStrict);
var gr = new GlideRecord(table);
// are we allowed to see this table's fields?
var fields = [];
var elems = gr.getElements();
for (var i = 0; i < elems.size(); i++) {
var elem = elems.get(i);
var name = '' + elem.getName();
var field = {};
if(soapSecurity.canWrite(gr, name)){
g_form.setReadOnly(name, false); //make the field editable
}
}

 

Please test all the test cases before implementing this script.

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumbs up.

 

Best regards,

Tharun Kumar