Populating Variables in a Multirow variable Set based on the selection of another Variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2023 04:57 AM - edited 06-05-2023 04:58 AM
I need some help please 🙂
I am trying to Populate Variables in a Multirow variable Set based on the selection of another Variable.
So if a part number is chosen i need to then populate the stock and description variables of that part into the MRVS after clicking add.
Table sn_customerservice_part
Hidden variable 1 on the form 'part_description' , Table field = 'u_part_description'
Hidden variable 2 on the form 'in_stock' , Table 'u_required_stock_quantity'
I tried with the below client script but does not seem to be working I can see in the console logs that it sees the info but it however does not set the variables.
Your assistance would be greatly appreciated.
Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Get the selected part reference field value
var selectedPart = g_form.getValue('part_number');
// Query the Parts table to get the part details
var gr = new GlideRecord('sn_customerservice_part');
gr.addQuery('sys_id', selectedPart);
gr.query(queryCallback); // Pass the callback function to query()
function queryCallback() {
if (gr.next()) {
// Set the description and in-stock field values
var description = gr.getValue('u_part_description');
var inStock = gr.getValue('u_required_stock_quantity');
// Log the retrieved values for debugging
console.log('Description:', description);
console.log('In Stock:', inStock);
// Set the values in the form fields
g_form.setValue('part_description', description);
g_form.setValue('in_stock', inStock);
} else {
console.log('Part not found!');
}
}
}
onChange(control, oldValue, newValue, isLoading, isTemplate);
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2023 09:43 AM
Hi Michael,
Are you running this onChange of the part_number variable, which is part of the MRVS, and the script applies to the Variable Set, not the Catalog Item? Are your part_description and in_stock variables also part of the MRVS, or do they belong to the Catalog Item, and are they of the same types as the u_part_description and u_required_stock_quantity fields?