answer returning false while making field mandatory on resolve

ABC6
Tera Contributor

I am making field assigned to Non-mandatory while resolving when there is an external reference record attached over the related list of incident, for this i have written script include and client script and not getting solution

isUserMember: function() {
        var userGrp = new GlideRecord('sys_user_grmember');
        userGrp.addQuery('user', this.getParameter('sysparm_usr'));
        userGrp.addQuery('group', this.getParameter('sysparm_grp'));
        userGrp.setLimit(1);
        userGrp.query();
        if (userGrp.next()) {
            var incidentId = this.getParameter('sysparm_is_external_reference');
        var gr = new GlideRecord('u_external_references');
        gr.addQuery('u_task', incidentId);
        gr.setLimit(1);
        gr.query();
       
        // Check if there's an external reference for the incident
        if (gr.next()) {
            return true;
        } else {
            return false;
        }
    }
    else {
        return false;
    }
       

    },
 
 
Client Script
if (g_form.getViewName() == 'sow_incident_resolve_modal' || g_form.getViewName() == 'ui16_incident_resolve_modal') {

        if (isLoading || newValue === '') {
            g_form.setMandatory('comments', true);
            g_form.setMandatory('assignment_group', true);

        }
        if (g_form.getValue('assigned_to') == '') {
            var getGroup = new GlideAjax('ResetAssignee');
            getGroup.addParam('sysparm_name', 'isUserMember');
            getGroup.addParam('sysparm_usr', g_user.userID);
            getGroup.addParam('sysparm_grp', g_form.getValue('assignment_group'));
            getGroup.addParam('sysparm_is_external_reference',g_form.getUniqueValue());
            getGroup.getXML(FCRAssignmentGroup);

        }
    }

}

function FCRAssignmentGroup(response) {
    var ans = response.responseXML.documentElement.getAttribute("answer");
    alert(ans);
    if (ans == true || ans == 'true') {
        g_form.setMandatory('assigned_to', false);
    } else {
        g_form.setMandatory('assigned_to', true);
    }

}
1 ACCEPTED SOLUTION

GopikaP
Mega Sage

Hi @ABC6 , Is the current user part of the assignment group you selected? If he is not, then it is directly returning false, even if the reference record exists in 'u_external_references' table.

View solution in original post

15 REPLIES 15

In your script include please put some logs like gr.sys_id

And find that and in the table also make sure there are cores fulfilling your condition.

Regards,
Debasis

ABC6_0-1740994200569.pngNot getting any logs

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@ABC6 

so what debugging did you perform?

is the script getting called?

Any error in system logs?

Script looks good to me.

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

Every time it is going into false condition even though it has reference record, please guide me what i need to perform

@ABC6 

u_task field is reference type or string?

Are you sure if it's reference type then you are passing sysIds?

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