
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 12-17-2020 06:10 AM
Hello All,
In this article, I will show you how you can add the rows dynamically in MRVS based on the input value of a catalog item.
For this, I have created 1 Record producer(Multirow Test), in which there is one field "Department". And I have 1 Multirow variable set "Get Employee Details", which user has to fill the details of employee.
So once Requestor enter the value in the "Department " field, it will auto populate the Multi row variable set (MRVS) with no of users which is part of the Depart.
e.g. Selected Department - Development
Result: It will give you details of all Employees whose Department is "Development"
For this, we will require 1 catalog client script OnChange on the field (Department), 1 script Include.
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('global.multipop'); //calling script include
ga.addParam('sysparm_name', 'fetchDetails'); //Script include function
ga.addParam('sysparm_dpt', newValue); //On change Value
ga.getXML(setUserDet);
function setUserDet(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('get_employee_details', answer); // Add your Variable set Name
}
}
Script Include:
var multipop = Class.create();
multipop.prototype = Object.extendsObject(AbstractAjaxProcessor, {
fetchDetails : function()
{
var dataArr = [];
var data = {};
var deptId = this.getParameter('sysparm_dpt');
var gr = new GlideRecord("sys_user");
gr.addQuery('department',deptId);
gr.addQuery('active',true);
gr.query();
while(gr.next())
{
data = {};
data.employee = gr.sys_id.toString();
data.mobile_no = gr.mobile_phone.toString();
data.email_id = gr.email.toString();
dataArr.push(data);
}
return JSON.stringify(dataArr);
},
type: 'multipop'
});
Output:
Mark the article as helpful and bookmark if you found it useful.
- 6,082 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Bhojraj Dhakate this is very helpful! I have one question, how would I add a sort preference to this? So lets say the email variable that you have, how would I set the MRVS to add these items and filter alphabetically by the email?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This looks to be wonderful, and attempted to use in my case.
E.G. User needs to send back equipment.
MRV has Item Description, Item Category, Serial Number and Quantity - (alm_asset table - all set to string field)
Pulling in what has been assigned to user.
I'm getting an error in console log of "Invalid value for table variable". Thoughts?
Here is my code.
Script Include addDeployedEquipment
var addDeployedEquipment = Class.create();
addDeployedEquipment.prototype = {
fetchDetails: function() {
var dataArr = [];
var data = {};
var deptId = this.getParameter('sysparm_dpt');
var gr = new GlideRecord("alm_asset");
gr.addQuery('assigned_to', deptId);
gr.query();
while (gr.next()) {
data = {};
data.item_description = gr.model.toString();
data.item_category = gr.sys_class_name.toString();
data.serial_number = gr.serial_number.toString();
data.quantity = gr.quantity.toString();
dataArr.push(data);
}
return JSON.stringify(dataArr);
},
type: 'addDeployedEquipment'
};
Client Script: Based on Requested for.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('global.addDeployedEquipment'); //calling script include
ga.addParam('sysparm_name', 'fetchDetails'); //Script include function
ga.addParam('sysparm_dpt', newValue); //On change Value
ga.getXML(setUserDet);
function setUserDet(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('pickup_item_list', answer); // Add your Variable set Name
}
}
my MRV name is pickup_item_list
item_description (single line text)
item_category (single line text)
serial_number (single line text)
quantity (single line text)
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
//how to set value multirow variable set variable1 , variable2, variable3 for 3 rows with intername multi_row
var ItemDetails =[
{
variable1 :'ABCD';
variable2 :'DEF';
variable3 : 'FRS';
},
{
variable1 :'ABCD';
variable2 :'DEF';
variable3 : 'FRS';
},
{
variable1 :'ABCD';
variable2 :'DEF';
variable3 : 'FRS';
},];
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I had also tried the same but it did not work for me so can you please help me with the same - @Bhojraj Dhakate
Client Script:
function onLoad() {
try {
var ritm = 'sc_req_item';
var ga = new GlideAjax('showScheduledInProgressRecords');
ga.addParam('sysparm_name', 'popRecords');
ga.addParam('sysparm_current_tablename', ritm);
// Use getXML and handle the response with onComplete
ga.getXML(Complete);
function Complete(response) {
try {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
var detailsArray = JSON.parse(answer);
console.log('Response:', answer);
if (detailsArray.length > 0) {
g_form.setValue('time_slot_selected',answer);
// g_form.setValue('user', detailsArray[0].User);
// g_form.setValue('strt_date', detailsArray[0].StartDate);
// g_form.setValue('ed_date', detailsArray[0].EndDate);
} else {
console.log('Details not found');
}
} else {
console.log('Not Found');
}
} catch (e) {
console.error('Error processing response: ' + e);
}
}
} catch (error) {
console.error('Error in onLoad function: ' + error);
}
}
Script Include:
var showScheduledInProgressRecords = Class.create();
showScheduledInProgressRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
popRecords: function() {
try {
gs.info('Script Include Triggered');
var tableName = this.getParameter('sysparm_current_tablename');
gs.log('tableName: ' + tableName);
var data = {};
var dataArr = [];
var ritm = new GlideRecord(tableName);
ritm.addQuery('u_status', 'IN', ['In Progress', 'Scheduled']);
ritm.query();
while (ritm.next()) {
data = {};
data.user = ritm.variables.user_id.toString();
data.strt_date = ritm.variables.start_date.toString();
data.ed_date = ritm.variables.end_date.toString();
dataArr.push(data);
}
// Log the details for debugging
gs.log("User: " + data.user + " " + "start date: " + data.strt_date + " " + "end date: " + data.ed_date);
return JSON.stringify(dataArr); // Convert detailsArray to JSON format
} catch (ex) {
gs.error('Error in Script Include popRecords: ' + ex);
return '[]'; // Return an empty array as a string in case of an error
}
},
type: 'showScheduledInProgressRecords'
});
// Rest of the code remains the same...

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Works great thanks for that post!
How could we do it if we want to add data in the MVRS when department change instead of replacing the rows in the MVRS ?