Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 08:11 PM
Hi @Alan42
Please try and see the below code:
Script Include:
var PlantManagerFetcher = Class.create();
PlantManagerFetcher.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getManagersByPlant: function(plantName) {
var result = {};
var gr = new GlideRecord('u_rwi_plants');
// Use the correct column names
gr.addQuery('u_plant', plantName);
gr.query();
if (gr.next()) {
result.qc_manager = gr.getValue('u_qc_manager');
result.plant_accountant = gr.getValue('u_plant_accountant');
result.shipping_manager = gr.getValue('u_shipping_manager');
}
return result;
},
type: 'PlantManagerFetcher'
});
Client Script:
function onLoad() {
var plantName = g_form.getValue('plant_name_field'); // Replace with the correct field name
if (plantName)
{
getManagersByPlant(plantName);
} }
function getManagersByPlant(plantName)
{
var ga = new GlideAjax('PlantManagerFetcher');
ga.addParam('sysparm_name', 'getManagersByPlant');
ga.addParam('plantName', plantName);
ga.getXMLAnswer(processResponse);
}
function processResponse(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
var result = JSON.parse(answer);
if (result)
{ g_form.setValue('qc_manager_field', result.qc_manager); // Replace with the correct field name g_form.setValue('plant_accountant_field', result.plant_accountant); // Replace with the correct field name g_form.setValue('shipping_manager_field', result.shipping_manager); // Replace with the correct field name } else { g_form.addErrorMessage('No managers found for the selected plant.');
} }