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

On submit validations

VALLUB
Tera Contributor
I have one requirement, In form level having requestor for filed and assignment group filed, requestor field taking the user table and in assignment group filed taking the group table, and in my requirement they ask me to create one new check box filed which is assign to me and if user check the check box which is assign to me and user is the member of that group then the form should submits and if user is not member of that group then form should not be submitted.
 
I wrote the below Onsubmit client script and script Include, but when user is member of the assignment group also form is not submitting, when user is not member of the group then it working correctly, but when user is part of the assignment then form should submits.
 
Client Script:
 
function onSubmit() {
    //Type appropriate comment here, and begin script below

 

    var assignmentGroup = g_form.getValue('assignment_group');
    var user = g_form.getValue('requested_for');
    var assignToMe = g_form.getValue('assign_to_me');

 

    if (assignToMe === 'true') {
        var ga = new GlideAjax('GetUserDetails');
        ga.addParam('sysparm_name', 'isUserInGroup');
        ga.addParam('sysparm_user_id', user);
        ga.addParam('sysparm_group_id', assignmentGroup);
        ga.getXMLAnswer(function(response) {
            if (response === 'true') {
                g_form.submit();

 

            } else {
                g_form.addErrorMessage('you are not a member of the assignment group');
            }
        });

 

        return false;
    }

 

    return true;
}
}
 
Script Include:
 
isUserInGroup: function() {
        var userId = this.getParameter('sysparm_user_id');
        var groupId = this.getParameter('sysparm_group_id');

        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', userId);
        gr.addQuery('group', groupId);
        gr.query();

        if (gr.hasNext()) {
            return 'true';
        }
        return 'false';

    },
 
And in my ServiceNow portal only Request button is there, no submit button available, please check the below code and help me accordingly, Thanks in Advance.
0 REPLIES 0