Need to write an ACL to allow only members of particular group to edit few fields in location table

Kayathri
Tera Contributor

Hi Team,

 

Having a requirement to write a ACL to allow only members of a particular group to edit three user defined fields in location table. Kindly suggest.

 

Regards,

Kayathri

1 ACCEPTED SOLUTION

Hi,

so members of that group should be allowed editing only 3 fields

All others should be readonly

Do this

Display BR on your table:

g_scratchpad.isMember = gs.getUser().isMemberOf('Group Name');

onLoad Client Script:

function onLoad(){

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

		// make all fields readonly
		var fields = g_form.getEditableFields();
		for (var x = 0; x < fields.length; x++) {
			g_form.setReadOnly(fields[x], true);
		}

		// make those 3 fields as editable
		g_form.setReadOnly('fieldA', false);
		g_form.setReadOnly('fieldB', false);
		g_form.setReadOnly('fieldC', false);
	}

}

Regards
Ankur

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

View solution in original post

11 REPLIES 11

Hi Ankur,

This is the BR I have used,find_real_file.png

find_real_file.png

 

This is the onload script I have used,

find_real_file.png

but its not working as expected, kindly suggest.

 

Regards,

Kayathri

 

Hi,

did you add alert what came in client script?

Did you check any UI policy etc is making those 3 fields read-only?

function onLoad(){

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

        alert('inside if');

        // make all fields readonly
        var fields = g_form.getEditableFields();
        for (var x = 0; x < fields.length; x++) {
            g_form.setReadOnly(fields[x], true);
        }

        // make those 3 fields as editable
        g_form.setReadOnly('fieldA', false);
        g_form.setReadOnly('fieldB', false);
        g_form.setReadOnly('fieldC', false);
    }

}

Regards
Ankur

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

Hi Ankur,

 

There is no UI policy for these 3 fields, 

function onLoad() {
//Type appropriate comment here, and begin script below
if(g_scratchpad.isMember.toString() == 'true'){
alert('inside if');

// make all fields readonly
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
alert('inside for');
g_form.setReadOnly(fields[x], true);
}

// make those 3 fields as editable
g_form.setReadOnly('u_hot_site', false);
g_form.setReadOnly('u_hot_site_end_date', false);
g_form.setReadOnly('u_hot_site_reason', false);

}
}

 

Its going "inside if", but not "inside for".

 

Regards,

Kayathri 

Hi,

I hope you are running this on native instance?

Regards
Ankur

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

Sorry Ankur, I haven't given the role in ACL, that was my mistake, your code is perfect.

Regards,

kayathri