- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2024 08:49 AM
Hi ,
I have to add choices to a particular field on change of its dependent field. I wrote on change and script include but on change is not triggering it however I'm able to get desired result from background script. I have deactivated as of now but it's not working when it is active
Below is screenshot:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2024 11:26 PM
Yes, Use the script include code that I have already provided earlier.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2024 09:02 AM
So I can quickly debug this on my PDI, can you copy and paste both the onLoad script and Script Include (not screen shots) please.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2024 09:23 AM
var TestAJAX = Class.create();
TestAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOptions: function() {
gs.addInfoMessage('script include triggered');
capexFun = this.getParameter('sysparm_val');
capexObj = this.getParameter('sysparm_sys_id');
gs.log(capexFun + capexObj, '144');
var choice = {};
var choiceArr = [];
var choiceGr = new GlideRecord('sys_choice');
choiceGr.addEncodedQuery('name=dmn_demand^element=u_sub_objective^inactive=false');
choiceGr.query();
while (choiceGr.next()) {
gs.print(capexFun +capexObj);
if (capexFun == "Production" || capexFun == "Logistics and Distribution") {
if (capexObj == "5") {
gs.log("Coming in the loop", '144');
choice['Efficiency'] = choiceGr.getValue('value');
choice['Civil'] = choiceGr.getValue('value');
} else if (capexObj == '1') {
choice['Topline'] = choiceGr.getValue('value');
}
} else if (capexFun == 'D&T_capex') {
choice['Fridges'] = choiceGr.getValue('value');
choice['Fire Safety'] = choiceGr.getValue('value');
}
choiceArr.push(choice);
return JSON.stringify(choiceArr); // Return a stringified array to the client
}
},
type: 'TestAJAX'
});
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
//return;
}
var capexfunction = g_form.getValue('u_capex_function');
var capexObjective = g_form.getValue('u_capex_objective');
var ga = new GlideAjax('global.TestAJAX');
//Pass the name of the method and the parameter
ga.addParam('sysparm_name', 'getOptions');
ga.addParam('sysparm_val', capexfunction);
ga.addParam('sysparm_sys_id', capexObjective);
ga.getXMLAnswer(setChoices);
function setChoices(answer) {
if (answer) {
alert("Answer--" + answer);
var choiceArray = JSON.parse(answer);
for (i = 0; i < choiceArray.length; i++) {
g_form.addOption(targetChoiceField, choiceArray[i].value, choiceArray[i].label, i + 1);
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2024 09:13 AM
Hi @Nivedita9 ,
Try doing a modification in line number 8 of your client script where using GlideAjax.
Maybe you're using wrong name in GlideAjax API. Use the below line instead.
// var ga = new GlideAjax('TestAJAX');
Thanks,
Hope this helps you, let me know!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2024 09:22 AM
Hi
I tried it.But not working