- 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 01:33 AM
Will try and get back to you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2025 08:43 PM
Not Working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2025 09:08 PM
please share your updated scripts and what debugging did you perform so far and what's your findings?
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 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 10:55 PM - edited ‎02-24-2025 10:57 PM
Hi @ABC6
No need of using isUserMember() function, directly call getGroup.addParam('sysparm_name', 'hasExternalReference') instead.
Thanks