Field on change form should be not mandatory to one particular group.

Atchutaram
Tera Contributor

Hi Everyone,

We do hava a Kb_article field on normal change form and it is mandatory, now we should make it non mandatory for users from Change management group. How can i achieve this?

 

Best Regards

3 REPLIES 3

ArpithaMenden
Tera Contributor

Hello @Atchutaram 

 

You can use OnLoad client script on Change request table

function onLoad()

{
if (g_form.getValue('type') != 'normal')
return;

if (g_user.isMemberOf('Change Management')) {
g_form.setMandatory('kb_article', false);
}
}

 

Please mark my answer helpful, if it resolves your query

Thanks,

Arpitha Menden

 

ArpithaMenden
Tera Contributor

@Atchutaram 

If any OOB ui policy is making the field mandatory you can override the ui policy and add conditions like
Type is Normal

Assignment group is not Change management(assuming this is created under groups table)

Nawal Singh
Tera Guru

Hi @Atchutaram ,

You can achieve this by writing the client script -(onload or onchange)-

function onLoad() {
    // Check if user is in Change Management group
    var ga = new GlideAjax('CheckUserGroup');
    ga.addParam('sysparm_name', 'isUserInChangeManagement');
    ga.getXMLAnswer(function(answer) {
        if (answer == 'true') {
            g_form.setMandatory('kb_article', false);
        } else {
            g_form.setMandatory('kb_article', true);
        }
    });
}

 

and server side script include- 

 

var CheckUserGroup = Class.create();
CheckUserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    isUserInChangeManagement: function() {
        var user = gs.getUser();
        return user.isMemberOf('Change Management');
    }
});

 

or you can also do this by UI Policies (alternative)- 

// Get current user groups
var user = gs.getUser();
if (user.isMemberOf('Change Management')) {
    // Disable mandatory rule for this group
    g_form.setMandatory('kb_article', false);
} else {
    // Keep it mandatory for others
    g_form.setMandatory('kb_article', true);
}

 

 

If you found my response helpful, please mark it as helpful and accept it as the solution.

Thank you
Nawal Singh