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

How to populate incident records based on check box

raj149
Giga Guru

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

6 REPLIES 6

AshishKM
Kilo Patron
Kilo Patron

Hi @raj149 , 

For Select Incident, write script include and call that using GlideAjax and get the list of incident  for selection.

In script include, glide the incident table with  condition on caller field passed from GlideAjax along with checkbox value.

Write some draft code and share if you need some help.

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hello @AshishKM 

I am trying with below Script include and catalog client script but it is not working 

 

Script include is 

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.number.toString()
});
}
return JSON.stringify(incidents);
},
type:'GetUserInc'
});
    
 
 
Catalog client script is 
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);

});
}
 
 
please correct the above script 
 
Best Regards,
Raj

James Chun
Kilo Patron

Hey @raj149,

 

Are you referring to applying a reference qualifier on the 'Select Incident' variable? i.e. instead of populating the variable, you want to filter the list of records that can be selected.

If so, create a Script Include and use the 'Advanced' reference qualifier. For details, refer to another article - https://www.servicenow.com/community/itsm-articles/reference-qualifier/ta-p/2306509

 

Just as an example, your reference qualifier will be something like:

javascript: new yourScriptInclude().getQualifier(current.variables.abc);

 

And your function in the script include will be

getQualifier: function(abc){
if(abc == true)
return "caller_idDYNAMIC90d1921e5f510100a9ad2572f2b477fe"
else
return "";
}

 

Cheers

sasi_v
Tera Guru

Hi,

 

This functionality can be achieved by adding an advance reference qualifier on the Select Incident field.

 

If you need guidance to configure advance reference qualifier I will help you out.

 

Regards,

Sasikanth