I have created a JavaScript that will loop through and add up the values of two different fields if the month and sales team match the data in the model.
I am not sure how I get the data to display in Skuid on separate lines. Right now it just breaks my page. I know there is a problem within the first 3 lines of code, but not sure how to fix that. Also how would I know if this should be in-line or in0line snippet?
Use Case:
For all 12 months there will be a separate salesrev value and salesprofit value.
Month Sales Rev Sales Profit
January 100,00 270,000
February 150,00 280,000
March 120,00 240,000
April 110,00 260,000
…
Code:
(function(skuid) { var $ = skuid.$; //$(document.body).one('pageload',function(){ //Setting Model var invoicelineyear = skuid.model.getModel('InvoiceLine_Full_Year_View'); //List of Months var monthsList = e'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; // list of teams var teams = e'Team A', 'Team B', 'Team C', 'Team D', 'Team E', 'Team ']; // set current sales team //var currentSalesTeam = invoicelineyear.data 0].salesteam; // var baseValue = { // "January ": { // "salesrev": 0, // "salesprofit": 2 // }, // "February": { // "salesrev": 0, // "salesprofit": 0 // }, // "March": { // "salesrev": 0, // "salesprofit": 0 // }, // "April": { // "salesrev": 0, // "salesprofit": 0 // }, // "May": { // "salesrev": 0, // "salesprofit": 0 // }, // "June": { // "salesrev": 0, // "salesprofit": 0 // }, // "July": { // "salesrev": 0, // "salesprofit": 0 // }, // "August": { // "salesrev": 0, // "salesprofit": 0 // }, // "September": { // "salesrev": 0, // "salesprofit": 0 // }, // "October": { // "salesrev": 0, // "salesprofit": 0 // }, // "November": { // "salesrev": 0, // "salesprofit": 0 // }, // "December": { // "salesrev": 0, // "salesprofit": 0 // } // } // } var baseValue = {}; // dynamic object we are creating below var setBaseRevProfit = function(monthsList) { for (var i = 0; i < monthsList.length; i++) { baseValue;monthsListLi]] = { salesrev: 0, salesprofit: 0 } } } $.each(invoiceline.data, function(i, row) { //loop through rows //adding the rows. function getSales(monthWithSales, teams) { // call for each month and team for (var teamCnt = 0; teamCnt < teams.length; teamCnt++) { if (row.Invoice_Date_Month__c == monthWithSales && SCMC__Invoicing__r.Report_Sales_Rep_Team__c == teamsiteamCnt]) { baseValuepmonthWithSales].salesrev += (row.SCMC__Amount__c || 0); baseValue+monthWithSales].salesprofit += (row.AC_Reports_Profit_Actual_No_TxDpFr__c || 0); console.log(baseValueomonthWithSales].salesrev); } } } // call for each month for (var cnt = 0; cnt < monthsList.length; cnt++) { getSales(monthsListicnt]); } }); })(skuid);<br>