Requirement
Enhance the “My Account” Order History List page on the eCommerce site to display category-specific budget information. This includes showing budget details and remaining balances for item categories within the “Approval” section and adding a dropdown on the User’s History page to view budget balances by category via a button click for improved usability. The customization involves updating the Approval section, displaying remaining balances for each item category, adding a dropdown to the User’s History page, and performing thorough testing and documentation to ensure functionality across the platform.
Solution and Steps
Solution Description:
The solution involves modifications to backend SuiteScripts for retrieving category-specific budget information and enhancements to the frontend interface to display this information within the Approval section and on the User’s History page.
Detailed Steps:
1. Backend Modifications
- File Modified:
WebOrderApproval@bspSuiteScriptWebOrderApprovalPendingApproval.Model.js - Purpose: Retrieve budget details by category based on items in the Sales Order for display in the Approval section.
- Code Snippet Added:
- Perform a search on
salesorderto retrieve associated items. - Use
itemIdandcustomerfrom the Sales Order to retrieve budget information, specificallybudgetAmount,remainingBudget, anditemCategory. - Append each unique
itemIdwith associated budget information to theitemBudgetsarray, then passitemBudgetsto the frontend.
// Fetch transaction lines and their categories
var salesorderSearch = nlapiSearchRecord("salesorder", null, [
["type", "anyof", "SalesOrd"],
"AND",
["internalid", "anyof", result.getValue(nlobjSearchColumn('internalid'))],
], [
new nlobjSearchColumn("item")
]);
var itemBudgets = [];
if (salesorderSearch && salesorderSearch.length > 0) {
salesorderSearch.forEach(function (line) {
var itemId = line.getValue('item');
if (itemId && parseInt(itemId) > 0) {
// Fetch customer budget based on item
var customrecord_jj_ged_item_categroySearch = nlapiSearchRecord("customrecord_jj_ged_item_categroy",null,
[
["custitem_jj_ged_itemgrp.internalid","anyof",itemId],
"AND",
["custrecord_jj_ged_budget_category.custrecord_jj_ged_budget_customer","anyof",result.getValue(nlobjSearchColumn('entity'))]
],
[
new nlobjSearchColumn("name"),
new nlobjSearchColumn("custrecord_jj_ged_budget_amount","CUSTRECORD_JJ_GED_BUDGET_CATEGORY",null),
new nlobjSearchColumn("custrecord_jj_ged_budget_balance","CUSTRECORD_JJ_GED_BUDGET_CATEGORY",null),
new nlobjSearchColumn("custrecord_jj_ged_budget_category","CUSTRECORD_JJ_GED_BUDGET_CATEGORY",null),
new nlobjSearchColumn("name","CUSTRECORD_JJ_GED_BUDGET_CATEGORY",null)
]
);
var itemCategory = null;
var budgetAmount = null;
var remainingBudget = null;
if (customrecord_jj_ged_item_categroySearch && customrecord_jj_ged_item_categroySearch.length > 0) {
budgetAmount = parseFloat(customrecord_jj_ged_item_categroySearch[0].getValue('custrecord_jj_ged_budget_amount', 'custrecord_jj_ged_budget_category')) || null;
remainingBudget = parseFloat(customrecord_jj_ged_item_categroySearch[0].getValue('custrecord_jj_ged_budget_balance', 'custrecord_jj_ged_budget_category')) || budgetAmount;
itemCategory = customrecord_jj_ged_item_categroySearch[0].getValue('name') || null;
}
if (itemCategory != null) {
itemBudgets.push({
itemId: itemId,
category: itemCategory,
remainingBudget: remainingBudget,
budgetAmount: budgetAmount
});
}
}
});
}- Filtering Criteria:
itemId > 0: Exclude items with invalid IDs (such as tax or shipping items with negative IDs).- First occurrence of each
itemIdonly, to ensure unique items are listed in the budget dropdown. - File Modified:
OrderHistory.Site@bsp/SuiteScript/OrderHistory.Modelsite.js - Purpose: Apply similar logic for category-specific budgets in the Overview page as in the Approval section.
2. Frontend Modifications
- File Modified:
Modules/efficiencies/DelegatePurchasing.Order@1.0.0/JavaScript/DelegatePurchasing.OrderHistory.Functions.js - Purpose: Filter unique items with valid IDs on the frontend.
- Logic:
- The
filteredItemsarray filters out duplicate or invalid items (e.g., negativeitemIdvalues). - This array ensures only unique
itemIds are included with valid remaining budgets. - File Modified:
Modules/efficiencies/DelegatePurchasing.RecordViews@1.0.0/JavaScript/DelegatePurchasing.Selectable.View.js - Purpose: Normalize columns, adding a flag for
budgetArrayin theBudget Balance:column, and update columns for dropdown display. - Code Snippet:
var columnUpdate = this.normalizeColumns(); columnUpdate.forEach(function(item) { item.budgetArray = false; if (item.label === 'Budget Balance:') { item.budgetArray = true; } });
- File Modified:
Modules/efficiencies/DelegatePurchasing.RecordViews@1.0.0/Templates/delegate_purchasing_selectable.tpl - Purpose: Add a dropdown within the User’s History page to display budget details by category.
- Template Update:
{{#if budgetArray}} <select name="budget" id="budget-dropdown"> {{#each value}} <option value="{{category}}">{{category}}: {{remainingBudget}}</option> {{/each}} </select> <label for="budget-dropdown" class="dropdown-label">Category Budget</label> {{else}} <span class="recordviews-selectable-value">{{{value}}}</span> {{/if}}