How can make attachment editable only for particular group members

nikhitha24
Tera Guru

Hi Team,

 

Please help me on the below requirement.

 

I have hide the attachments based on the states for this i have written on load client script, now i want for Change Management groups members need to accessible in all states.

I have written below script to hide the attachments.

 

function onLoad() {
    var state = g_form.getValue("state");
    if (state == '-2' || state == '-1' || state == '4' || state == '3' || state == '0'){
        g_form.disableAttachments();

    }
}

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@nikhitha24 

that group has some role? if yes then add that check in script

function onLoad() {
	var state = g_form.getValue("state");
	if(!g_user.hasRoleExactly('roleName')){
		if (state == '-2' || state == '-1' || state == '4' || state == '3' || state == '0'){
			g_form.disableAttachments();
		}
	}
}

If your group has no role then you can use display business rule and check if logged in user belongs to that group and use g_scratchpad variable

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	g_scratchpad.isMember = gs.getUser().isMemberOf('Group Name');

})(current, previous);

Client script

function onLoad() {
	var state = g_form.getValue("state");
	if(g_scratchpad.isMember.toString() == 'false'){
		if (state == '-2' || state == '-1' || state == '4' || state == '3' || state == '0'){
			g_form.disableAttachments();
		}
	}
}

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

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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@nikhitha24 

that group has some role? if yes then add that check in script

function onLoad() {
	var state = g_form.getValue("state");
	if(!g_user.hasRoleExactly('roleName')){
		if (state == '-2' || state == '-1' || state == '4' || state == '3' || state == '0'){
			g_form.disableAttachments();
		}
	}
}

If your group has no role then you can use display business rule and check if logged in user belongs to that group and use g_scratchpad variable

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	g_scratchpad.isMember = gs.getUser().isMemberOf('Group Name');

})(current, previous);

Client script

function onLoad() {
	var state = g_form.getValue("state");
	if(g_scratchpad.isMember.toString() == 'false'){
		if (state == '-2' || state == '-1' || state == '4' || state == '3' || state == '0'){
			g_form.disableAttachments();
		}
	}
}

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

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