How to populate incident records based on check box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 10:41 AM
Hello Experts,
I created 2 fields in XYZ record producer.
1. ABC ( field type is checkbox)
2. Select Incident ( field type is reference to incident table)
Now my requirement is
If ABC is false then in Select Incident field we need to populate my incident records only.(means caller = current logged in user )
If ABC is true the in Select Incident field we need to populate all incident records.
How to achieve this...?
Best regards,
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 11:26 AM
Hi, as your filtering\query requirements are very simple, in the Incident reference variable you can add an advanced reference qualifier to check the content of the checkbox variable and then use simple javascript query.
Something like this should suit, although you might want to remove the active=true reference
javascript: var ret='active=true'; if (current.variables.abc == 'false') ret += ' ^caller_id=' + gs.getUserID(); ret;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 09:03 PM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('GetUserInc');
ga.addParam('sysparm_name', 'getIncidents');
ga.addParam('sysparm_user', g_user.userID);
ga.addParam('sysparm_all', newValue);
ga.getXMLAnswer(handleResponse);
}
function handleResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var incidents = JSON.parse(answer);
g_form.clearOptions('incident1');
incidents.forEach(function(incident) {
g_form.addOption('incident1', incident.sys_id, incident.number);
});
}
var GetUserInc = Class.create();
GetUserInc.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getIncidents: function() {
var all = this.getParameter('sysparm_all');
var user = this.getParameter('sysparm_user');
var incidents = [];
var gr = new GlideRecord('incident');
if (all !== 'true') {
gr.addQuery('caller_id', user);
}
gr.query();
while (gr.next()) {
incidents.push({
sys_id: gr.sys_id.toString(),
number: gr.getValue('number') // Using getValue() instead of toString()
});
}
return JSON.stringify(incidents);
},
type: 'GetUserInc'
});