- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2025 12:44 AM
Hello Team,
I have a requirement where if there is any external reference record attached to the related list of incident then assigned to field will be non mandatory for which i have written a piece of code over script include and and client script but it is not working as expected below are the code:
Script Include:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2025 10:00 PM
Can you try with below updated code,
Script include:
var ResetAssignee = Class.create();
ResetAssignee.prototype = Object.extendsObject(AbstractAjaxProcessor, {
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();
return userGrp.hasNext().toString(); // Return "true" or "false"
},
hasExternalReference: function() {
var incidentId = this.getParameter('sysparm_is_external_reference');
var gr = new GlideRecord('u_external_references'); // Ensure table name is correct
gr.addQuery('u_task', incidentId); // Assuming this is the reference to 'incident'
gr.setLimit(1);
gr.query();
return gr.hasNext().toString(); // Return "true" or "false"
},
isAssignedToMandatory: function() {
var isExternalReference = this.hasExternalReference();
return isExternalReference === "true" ? "false" : "true";
}
});
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === oldValue) {
return;
}
if (!g_form.getValue('assigned_to')) {
var getGroup = new GlideAjax('ResetAssignee');
getGroup.addParam('sysparm_name', 'isAssignedToMandatory'); // Calls the new method
getGroup.addParam('sysparm_is_external_reference', g_form.getUniqueValue()); // Gets Incident ID
getGroup.getXMLAnswer(function(response) {
alert(response);
if (response === "false") {
g_form.setMandatory('assigned_to', false);
} else {
g_form.setMandatory('assigned_to', true);
}
});
}
}
Please mark correct/helpful if this helps you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2025 12:52 AM
so what debugging did you perform from your side and what's your analysis?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2025 01:32 AM
like applied log, but did not get even any response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2025 02:01 AM
if logs didn't come it means it's not able to call your script include
are you calling the correct function from your GlideAjax?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2025 01:04 AM
Your script include defines two functions: isUserMember and hasExternalReference. Your client script is calling isUserMember (via setting sysparm_name to 'isUserMember'), but the requirement is to check for an external reference record. I think you need to use hasExternalReference instead.
getGroup.addParam('sysparm_name', 'hasExternalReference');