Filter Variable based on a reference Field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 05:40 PM
I have a Variable named 'var A' in the Variable set referencing the company table.
I have a field on the Incident table named 'Fil A' which again refrences the company table.
Now what I want is, whatever the Value is selected in the Field 'Fil A', I want to show these values in Variable 'Var A' in a Variable set.
Please help with the response.
Thanks
Xion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 06:26 PM
Okay, in this case, you have a variable 'Var A' referencing the Company table and a filed 'Fil A' on the Incident table referencing the Company table.
As you are relating the var A and Fil A, I assume there is an another variable on Catalog item referncing to the incident table and based on selection of the Incident, you need to populate the Fil A data into Var A.
You can try with GlideAjax as below.
Onchange Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('global.CatalogUtils');
ga.addParam('sysparm_name', 'getIncidentCompany');
ga.addParam('sysparm_incident', newValue);
ga.getXML(callBack);
function callBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('company', answer);
}
}
Script Include:
var CatalogUtils = Class.create();
CatalogUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getIncidentCompany: function() {
var incidentId = this.getParameter('sysparm_incident');
var grInc = new GlideRecord("incident");
if (grInc.get(incidentId)) {
gs.log("Sunil Incident compamny is - " + grInc.company);
return grInc.company;
} else {
return '';
}
},
type: 'CatalogUtils'
});
Regards,
Sunil