Remove options from a record producer variable in native view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi All,
I have an incident record producer. There is a variable of select box type named as rp_subcategory. The choices in this fields gets populated based on 2 other fields - u_entity and u_department . While submitting it on the portal it works once.
Once the incident is raised, in the backed incident form -- variables section -- all the choices are being shown irrespective of the entity and department since its coming from sys_choice table.
I have created below script include function and on load client script to remove the choices from this field but its not removing the chocies.
Script include
getIssueTypesByEntityandDepartment: function() {
var entity = this.getParameter('sysparm_entity');
var department = this.getParameter('sysparm_department');
var arr = [];
var res = [];
var gr = new GlideRecord('table##');
gr.addEncodedQuery('##');
gr.orderBy('u_incident_sub_category');
gr.query();
while (gr.next()) {
arr.push(gr.u_incident_sub_category.toString());
}
var ga = new GlideRecord('sys_choice');
ga.addEncodedQuery('name=u_data_administration^element=u_incident_sub_category^inactive=false');
ga.query();
while (ga.next()) {
if (arr.indexOf(ga.value.toString()) === -1) {
if (res.indexOf(ga.value.toString()) === -1) {
res.push(ga.value.toString());
}
}
}
return res.toString();
},
On Load Client Script
function onLoad() {
var ga = new GlideAjax('IncidentRecordProducerUtils');
ga.addParam('sysparm_name', 'getIssueTypesByEntityandDepartment');
ga.addParam('sysparm_entity', g_form.getValue('u_entity'));
ga.addParam('sysparm_department', g_form.getValue('u_inc_department'));
ga.getXMLAnswer(function getIssueTypes(answer) {
var arr = answer.split(',');
for (var i = 0; i < arr.length; i++) {
g_form.removeOption('variables.rp_subcategory', arr[i]);
}
});
g_form.removeOption('variables.ent_eng', 'Single');
}
I added logs and its correctly returning the choices which needs to be removed on the form. I tried adding timeout, doesn't help.
However, the same logic is working in Service Operations Workspace (SOW).
Is it because the variable is displayed under a container in the form (Incident form variables - formatter)
Let me know if anyone has any solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Ankur,
Thanks for your response.
Apparently, I created the Catalog Client Script only under the Record Producer, and the "Applies to target record" option is marked as true.
I’ve updated the variable syntax as you suggested.
However, I’m still not sure why the issue persists.
When I print all the subcategories returned from arr[i], it displays all of them correctly.
When I print the current subcategory, it gives me the correct value.
But it’s still not removing the categories as expected.
function onLoad() {
var ga = new GlideAjax('IncidentRecordProducerUtils');
var subcate = g_form.getValue('rp_subcategory');
ga.addParam('sysparm_name', 'getIssueTypesByEntityandDepartment');
ga.addParam('sysparm_entity', g_form.getValue('u_entity'));
ga.addParam('sysparm_department', g_form.getValue('u_inc_department'));
ga.getXMLAnswer(function getIssueTypes(answer) {
var arr = answer.split(',');
g_form.addInfoMessage('Current Subcategory: ' + subcate);
g_form.addInfoMessage('Returned Subcategories: ' + arr.join(', '));
for (var i = 0; i < arr.length; i++) {
g_form.removeOption('rp_subcategory', arr[i]);
}
});
g_form.removeOption('ent_eng', 'Single');
}
Is there anything else I should try?