- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2021 06:35 AM
Hi,
I have issue where there are two drop downs in Incident form.
Product Line - this is populating from choices we have added to sys_choice table
Based on the selected product line value related Products have to populate into the Products drop down.
I'm populating these products value from Choice mapping custom table.
In Incident.
Product Line-String
Product column - String
See below screenshots.
I have written a Onchange Client script as below but can't populate 'Product' drop down.
Can anyone please give some guidance on this how to achieve this.
var prod_line = g_form.getValue('u_p_line');
var gr=new GlideRecord('u_choice_mapping');
gr.addQuery('u_product_line',prod_line);
gr.query();
while(gr.next())
{
g_form.setValue('u_product',gr.u_product_choice_mapping);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2021 10:18 AM
Use the same code in OnChange script
Sample code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.clearOptions('u_integer_f');
//your code here
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name', 'helloWorld');
ga.addParam('sysparm_user_name', newValue);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// alert(answer);
var x = answer.split(",");
for (var i = 0; i < x.length; i++)
g_form.addOption('u_integer_f', x[i], x[i]);
}
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2021 06:42 AM
Hi SSA
Use addOption method
Syntax : g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2021 07:09 AM
it's not working. I think since I'm getting from directly from a customer table. There's nothing called choiceValue. But I have used choice Label value to choiceValue . But it's not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2021 07:16 AM
Hi ssa
Try this
g_form.addOption('u_product',gr.u_product_choice_mapping, gr.u_product_choice_mapping);
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2021 07:49 AM
Try this:
Specify Your choice table and field
Table - u_choice_mapping, Field - u_product
Remove this
Use Below code in your client script:
var prod_line = g_form.getValue('u_p_line');
var gr=new GlideRecord('u_choice_mapping');
gr.addQuery('u_product_line',prod_line);
gr.query();
while(gr.next())
{
g_form.addOption('u_product',gr.u_product_choice_mapping,gr.u_product_choice_mapping);
}
Instead of directly using gliderecord in Client script, Try to use GlideAjax in returning choice values.
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP