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

Assigned to should only be assesible to the user if he is the member of current assignment group

Susmitha1625
Tera Guru

Hi People,

I have a request, On the Incident Form, the 'Assigned to' field should be accessible to the user only if he is a member of the current Assignment Group or make it read-only otherwise. I've tried to use the OnLoad Client Script but, it's not working for the newly opened records (before submitting a new incident) and also there is a delay of a few seconds after the form loads for the script to execute. Due to the delay, though the user is not a member of the group he's able to access Assigned to and fill in the data, and then the field is turning read-only. I'm adding my scripts Please help me.

 

Client Script

function onLoad() {
  
    var assignmentgroup = g_form.getValue('assignment_group');
    var ga = new GlideAjax('UserProtectionAssignedto');
    ga.addParam('sysparm_name', 'incidentassignedto');
    ga.addParam('sysparm_group', assignmentgroup);
    ga.getXMLAnswer(generateassignedto);
 
    function generateassignedto(answer) 
        if (answer == 'true') {
           g_form.setReadOnly('assigned_to', false);
        } else {
            g_form.setReadOnly('assigned_to', true);
        }
}
 
 
SCRIPT INCLUDE:
 
var UserProtectionAssignedto = Class.create();
UserProtectionAssignedto.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    incidentassignedto: function() {
        var groupname;
        var assignmentgroup = this.getParameter('sysparm_group');
        var group = new GlideRecord('sys_user_group');
        group.addQuery('sys_id', assignmentgroup);
        group.query();
        if (group.next()) {
            groupname = group.name;
         
            var gr = new GlideRecord('incident');
            gr.query();
            while (gr.next()) {            
         
            if (gs.getUser().isMemberOf(groupname) ) {
         
                    return true;
            }
               

            }
        }
    },

    tyUserProtectionAssignedtoe: 'UserProtectionAssignedto'
});
1 ACCEPTED SOLUTION

Eswar Chappa
Mega Sage

Hi @Susmitha1625 find the below Communiy article which will help you with your Use case:

 

https://www.servicenow.com/community/now-platform-forum/need-to-make-assigned-to-readonly-based-on-l...

Thanks & Regards,

Eswar Chappa

Mark my answer correct and Helpful if this helps you 😀

View solution in original post

2 REPLIES 2

Eswar Chappa
Mega Sage

Hi @Susmitha1625 find the below Communiy article which will help you with your Use case:

 

https://www.servicenow.com/community/now-platform-forum/need-to-make-assigned-to-readonly-based-on-l...

Thanks & Regards,

Eswar Chappa

Mark my answer correct and Helpful if this helps you 😀

Hi @Susmitha1625,

 

Can you please mark it as Helpful as well. As it helped you 

 

Thanks & Regards,

Eswar Chappa