Dynamic drop down value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2024 06:28 AM
The Requested Item form contains a custom field 'u_category', with a drop down value that should be dynamic depending on the Business Service or ServiceOffering. It does not work with the settings shown below. What might have gone wrong?
**Type is String but it has drop down value from sys_choice table.
Script include:
Client Callable (False)
var RITMCategorization = Class.create();
RITMCategorization.prototype = {
initialize: function() {},
getCategory: function(current) {
var category = [];
var service_offering = current.service_offering.getValue();
var business_service = current.business_service.getValue();
if (current.business_service) {
if (current.business_service == '342423r23eweqeqe23432') { //IT services
var choice = new GlideRecord('sys_choice');
choice.addQuery('dependent_value', service_offering);
choice.addQuery('element', 'u_category');
choice.addQuery('inactive', false);
choice.query();
while (choice.next()) {
category.push(choice.label);
}
} else {
var choice1 = new GlideRecord('sys_choice');
choice1.addQuery('dependent_value', business_service);
choice1.addQuery('element', 'u_category');
choice1.addQuery('inactive', false);
choice1.query();
if (choice1.next()) {
category.push(choice1.label);
}
}
return category;
}
},
type: 'RITMCategorization'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2024 06:53 AM
Hi @tsoct ,
In u_category field dictionary, you are calling your script include in default value which is only called when record is created. if you want u_category field data should be populate based on service option and offering then you have to write onLoad client script and there you need to call ClientCallable script include.
For that first you have to write client callable script include and then call it in OnLoad client script via GlideAjax API call and then set the response in your category field via glide form api.
g_form.setValue('u_category', response);
I hope it help you.
Regards
Moin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2024 07:54 AM
Hello @Moin Kazi ,
Could you help me with below:
Script include:
Client Callable = true
var RITMCategorization = Class.create();
RITMCategorization.prototype = Object.extendsObject(AbstractAjaxProcessor, {
GetCategory: function() {
var category = {};
var service_offering = this.getParameter('sysparm_serviceOffering');
var business_service = this.getParameter('sysparm_businessServices');
if (business_service) {
if (business_service == 'faa7872a1bacc6505e9542ede54bcbc9') { //tcgs
var choice = new GlideRecord('sys_choice');
choice.addQuery('dependent_value', service_offering);
choice.addQuery('element', 'u_category');
choice.addQuery('inactive', false);
choice.query();
while (choice.next()) {
category.push(choice.label);
}
} else {
var choice1 = new GlideRecord('sys_choice');
choice1.addQuery('dependent_value', business_service);
choice1.addQuery('element', 'u_category');
choice1.addQuery('inactive', false);
choice1.query();
if (choice1.next()) {
category.push(choice1.label);
}
}
return JSON.stringify(category);
}
},
type: 'RITMCategorization'
});
On Load Client Script:
Answer return empty
function onLoad() {
var service_offering = g_form.getValue('service_offering');
var business_service = g_form.getValue('business_service');
var ga = new GlideAjax('RITMCategorization');
ga.addParam('sysparm_name', 'GetCategory');
ga.addParam('sysparm_serviceOffering', service_offering);
ga.addParam('sysparm_businessServices', business_service);
ga.getXML(RelCategory);
function RelCategory(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = JSON.parse(answer);
alert(" answer " + JSON.stringify(answer));
for (var i = 0; i < answer.length; i++) {
g_form.setValue('u_category', answer);
}
}
}