- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2025 08:17 AM
I have written a script to map the fields on custom table and create a record in another custom table as well [ as record producer is linked to another custom table]. We need record producer to create records in 2 tables based on Expense Category [reference type variable] shown as dropdown in record producer. There are 2 different MRVS for 2 different Categories. Here is the Script:-
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2025 08:37 PM
Hi Shivangi,
The error occurs because you're referencing "items.exp_amount" instead of the current row's "line_Item.exp_amount." Here's the corrected script:
var erSysId = current.sys_id; // Get current sys_id now
var currency = producer.currency;
current.description = "Expense Request raised by Record Producer";
// Process Multi-row Variable Set (MRVS)
if(producer.getDisplayValue('expense_choice') == "Planned Expense"){
var lineItems = producer.line_items;
var rowCount = lineItems.getRowCount();
for (var i = 0; i < rowCount; i++) {
var lineItem = lineItems.getRow(i);
var li = new GlideRecord('x_merl4_expense_ma_line_of_items');
li.initialize();
li.er_no = erSysId;
li.expected_budget = lineItem.expected_budget;
li.currency = currency;
li.advance_amount_requested = lineItem.adv_amt;
li.start_date_of_expense = producer.start_date;
li.end_date_of_expense = producer.end_date;
li.expense_type = lineItem.expense_type;
li.short_description = lineItem.description;
li.expected_budget = lineItem.expected_budget;
li.state = 'Request Submitted';
li.insert();
}
} else if(producer.getDisplayValue('expense_choice') == 'Claim Expense'){
var items = producer.line_items_claim;
var rows = items.getRowCount();
for (var i = 0; i < rows; i++){
var line_Item = items.getRow(i); // Access the current row
var li = new GlideRecord('x_merl4_expense_ma_line_of_items');
li.initialize();
li.er_no = erSysId;
li.expense_type = line_Item.exp_type; // Use line_Item.exp_type
li.amount = line_Item.exp_amount; // Use line_Item.exp_amount (not producer.currency + ...)
li.attachement = line_Item.bill_receipt; // Ensure variable name matches (e.g., "attachement" vs "attachment")
li.short_description = line_Item.short_description;
li.state = 'Request Submitted';
li.insert();
}
}
Mark this as helpful and correct, if this solves your issue.
Thanks,
Yaswanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2025 08:37 PM
Hi Shivangi,
The error occurs because you're referencing "items.exp_amount" instead of the current row's "line_Item.exp_amount." Here's the corrected script:
var erSysId = current.sys_id; // Get current sys_id now
var currency = producer.currency;
current.description = "Expense Request raised by Record Producer";
// Process Multi-row Variable Set (MRVS)
if(producer.getDisplayValue('expense_choice') == "Planned Expense"){
var lineItems = producer.line_items;
var rowCount = lineItems.getRowCount();
for (var i = 0; i < rowCount; i++) {
var lineItem = lineItems.getRow(i);
var li = new GlideRecord('x_merl4_expense_ma_line_of_items');
li.initialize();
li.er_no = erSysId;
li.expected_budget = lineItem.expected_budget;
li.currency = currency;
li.advance_amount_requested = lineItem.adv_amt;
li.start_date_of_expense = producer.start_date;
li.end_date_of_expense = producer.end_date;
li.expense_type = lineItem.expense_type;
li.short_description = lineItem.description;
li.expected_budget = lineItem.expected_budget;
li.state = 'Request Submitted';
li.insert();
}
} else if(producer.getDisplayValue('expense_choice') == 'Claim Expense'){
var items = producer.line_items_claim;
var rows = items.getRowCount();
for (var i = 0; i < rows; i++){
var line_Item = items.getRow(i); // Access the current row
var li = new GlideRecord('x_merl4_expense_ma_line_of_items');
li.initialize();
li.er_no = erSysId;
li.expense_type = line_Item.exp_type; // Use line_Item.exp_type
li.amount = line_Item.exp_amount; // Use line_Item.exp_amount (not producer.currency + ...)
li.attachement = line_Item.bill_receipt; // Ensure variable name matches (e.g., "attachement" vs "attachment")
li.short_description = line_Item.short_description;
li.state = 'Request Submitted';
li.insert();
}
}
Mark this as helpful and correct, if this solves your issue.
Thanks,
Yaswanth