This topic contains 14 replies, has 0 voices, and was last updated by jmessersmith 8 years, 4 months ago.
-
AuthorPosts
-
July 7, 2016 at 7:59 am #23671
jmessersmithIs there a way to add a total item count to a sublist? I understand how to get the total with suitescripts but don't see a way to put a div or field at the buttom of the sublist so I can populate it.
Do I have to recreate the entire form in a Suitelet to get this level of customization?
This is a cached copy. Click here to see the original post. -
July 7, 2016 at 1:05 pm #23672
errolDo you need it at the bottom of the sublist? Will a custom integer field on that subtab (above the sublist) work? If so, you can create a custom integer field and populate it with the count either using script or a non-stored field and a search. Depending on your skills, doing the non-stored field (search) may be the easiest option. Though, I do think the script is the best way to accomplish what you are trying to do for many reasons. Finally, if you do NEED it as the bottom of the sublist, you will probably need to "hack" it using jquery. You could do that pretty easily by just adding a row with total to the list, though I probably wouldn't recommend that. Hope this helps, maybe others will have better ideas for you.
-Errol
-
July 8, 2016 at 7:58 am #23673
jmessersmithDo you have an example of how to "hack" it? I'm not sure how to do this, nothing has an ID assigned.
-
July 8, 2016 at 8:28 am #23674
errolIs this the actual Item sublist on a Transaction you are talking about? Or is is a Sublist from a Saved Search that it put on the form?
-
July 8, 2016 at 8:37 am #23675
jmessersmithIts the item sublist on a transaction.
-
July 8, 2016 at 10:43 am #23676
errolBelow is a quick example (not fully tested). This should at least give you an idea on one way this could be accomplished. I also want to reiterate that this is not a supported customization by NetSuite and would probably need more work to make it fully usable to what you need.
Code:
function beforeLoad(type, form){
//Execute the logic only when editing the record in the browser UI
if (nlapiGetContext().getExecutionContext() == 'userinterface') {if (type == 'edit' || type == 'view') {
form.addField('custpage_trans_itemcount_pagescript', 'inlinehtml');
form.getField('custpage_trans_itemcount_pagescript').setDefaultValue(getItemTotalPageLoadScript());
}
}
}function getItemTotalPageLoadScript(){
var itemCount = 0;
var lineCount = nlapiGetLineItemCount('item');
for (var i = 1; i <= lineCount; i++) {
//filter out only items you want to count, example below..
if (['Group', 'EndGroup', 'Description', 'Subtotal', 'Discount'].indexOf(nlapiGetLineItemValue('item', 'itemtype', i)) == -1) {
itemCount++;
}
}//below will add the row and id on the td. you will probably want to add some css styling and also update that count in edit mode when lines are added/removed from the sublist
var script_c = '';
script_c += '<script type="text/javascript">';
script_c += ' jQuery(document).ready(function() { ';
script_c += ' var colCount = 0;';
script_c += ' var rowCols = jQuery("#item_splits > tbody > tr:nth-child(1) td");';
script_c += ' if (rowCols) {';
script_c += ' rowCols.each(function(){';
script_c += ' if (jQuery(this).attr("colspan")) {';
script_c += ' colCount += +jQuery(this).attr("colspan");';
script_c += ' }';
script_c += ' else {';
script_c += ' colCount++;';
script_c += ' }';
script_c += ' }); ';
script_c += ' jQuery("#item_splits > tbody:last-child").append('<tr class="uir-machine-row"><td id="custom_item_total" class="listtexthl" align="right" colspan="' + colCount + '">' + itemCount + ' Items</td></tr>');';
script_c += ' }';
script_c += ' }); ';
script_c += '</script>';return script_c;
} -
July 8, 2016 at 2:01 pm #23677
jmessersmithI couldnt get your code to work but i like the concept. I ran into a snag. I'm just adding a div to the bottom of the page, but when I do that it messes up the adding more items to the form, it just says loading and doesnt give you a new line to select an item. Any idea why that would happen? I'm using page Int function.
Code:
var divCSS = "background:#d3d3d3;color: #000;opacity: 0.7;height: 100px;z-index: 1000";
document.body.innerHTML += "<div id='footer' style='" + divCSS + "'>Something in footer</div>"; -
July 8, 2016 at 2:29 pm #23678
jmessersmithI found a solution, I'll post my complete code when I'm done.
Code:
var node = document.createElement("div"); // Create a <div> node
var textnode = document.createTextNode("Water"); // Create a text node
node.appendChild(textnode);node.setAttribute("id", "footer");
node.style.cssText = "background:#d3d3d3;color: #000;opacity: 0.7;height: 100px;z-index: 1000";
document.getElementsByTagName('body')[0].appendChild(node); -
July 11, 2016 at 8:08 am #23679
jmessersmithIs there a way to execute javascript on the view part of a form? I don't see how its done.
-
July 11, 2016 at 6:31 pm #23680
michoelOriginally posted by jmessersmith
View Post
Is there a way to execute javascript on the view part of a form? I don't see how its done.
You would do this by creating a User Event script with a beforeLoad event, and then call form.setScript();
-
July 12, 2016 at 9:49 am #23681
jmessersmithThanks, I got it working. alert(nlapiGetLineItemCount('item')); returns -1 on the view, is some some other function I should use on the view part?
-
July 12, 2016 at 11:59 am #23682
errolThat's one of the reasons I put it server side in the beforeLoad, vs client side using setScript. What about my example didn't work? I just tested it in my development account and it worked. My suggestion is to build it server-side, then update it client side (only in edit mode would it be necessary as lines are added/removed). But you could use a normal validateLine client script to do that.
-
July 12, 2016 at 7:09 pm #23683
michoelOriginally posted by jmessersmith
View Post
Thanks, I got it working. alert(nlapiGetLineItemCount('item')); returns -1 on the view, is some some other function I should use on the view part?
In view mode you would have to load the record first:
Code:
var record = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId());
alert(record.getLineItemCount('item')); -
July 14, 2016 at 7:47 am #23684
jmessersmithNevermind, I need to use getLineItemValue.
-
July 15, 2016 at 8:52 am #23685
jmessersmithI got it working. Here is the code:
Put pageInit in User Event Script on the Purchase Order BeforeLoad function
Code:
function pageInit(type){
form.setScript('customscriptclient_po_item_summary');
}Add this script to the Client scripts for the Purchase Order, pageInit on Page Init and getItemTotalPageLoadScript on Line Init function.
The script is still a little messy but should work.
Code:
var node = document.createElement('div'); // Create a <div> nodenode.setAttribute('id', 'footer');
node.style.cssText = 'position: fixed; bottom: 0px; color: rgb(0, 0, 0); height: 100px; z-index: 1000;width: 50%;margin: 0 auto; ';
document.getElementsByTagName('body')[0].appendChild(node);var nodePad = document.createElement('div'); // Create a <div> node
nodePad.setAttribute('id', 'footerpad');
nodePad.style.cssText = 'color: #000;opacity: 0.7;height: 100px;z-index: 1000';
document.getElementsByTagName('body')[0].appendChild(nodePad);//var divCSS = 'background:#d3d3d3;color: #000;opacity: 0.7;height: 100px;z-index: 1000';
//document.body.innerHTML += '<div id='footer' style='' + divCSS + ''>Something in footer</div>';
document.addEventListener('DOMContentLoaded', function (event) {
var element = document.getElementById('container');
var height = element.offsetHeight;
if (height < screen.height) {
document.getElementById('footer').classList.add('stikybottom');
}
}, false);getItemTotalPageLoadScriptView();
function getItemTotalPageLoadScript(){
var totalQty = 0;
var totalBilled = 0;
var totalRec = 0;
var dollarTotal = 0;
var lineCount = nlapiGetLineItemCount('item');
var correctedLineCount = 0;for (var i = 1; i <= lineCount; i++) {
//filter out only items you want to count, example below..
//alert(Number(nlapiGetLineItemValue('item', 'amount', i)));if (nlapiGetLineItemValue('item', 'isclosed', i)=='F' || nlapiGetLineItemValue('item', 'isclosed', i)==null){
totalQty += parseInt(nlapiGetLineItemValue('item', 'quantity', i));
totalBilled += parseInt(nlapiGetLineItemValue('item', 'quantitybilled', i));
totalRec += parseInt(nlapiGetLineItemValue('item', 'quantityreceived', i));
dollarTotal += Number(nlapiGetLineItemValue('item', 'amount', i));
correctedLineCount += 1;
}
}
if (isNaN(totalBilled)) totalBilled=0;
if (isNaN(totalRec)) totalRec=0;
var dollarTotal = Math.round(dollarTotal * 100) / 100 //round to 2nd decimaldocument.getElementById('footer').innerHTML = '<center>';
document.getElementById('footer').innerHTML += "<table class='totallingtable' cellspacing='0' cellpadding='0px' border='1px' bgcolor='#d3d3d3 ' align='center' style='display: inline-block;'><tr><td>Line Count</td></tr><tr><td>" + correctedLineCount + "</td></tr></table>";
document.getElementById('footer').innerHTML += "<table class='totallingtable' cellspacing='0' cellpadding='0px' border='1px' bgcolor='#d3d3d3 ' align='center' style='display: inline-block;'><tr><td>Total Qty</td></tr><tr><td>" + totalQty + "</td></tr></table>";
document.getElementById('footer').innerHTML += "<table class='totallingtable' cellspacing='0' cellpadding='0px' border='1px' bgcolor='#d3d3d3 ' align='center' style='display: inline-block;'><tr><td>Total Billed</td></tr><tr><td>" + totalBilled + "</td></tr></table>";
document.getElementById('footer').innerHTML += "<table class='totallingtable' cellspacing='0' cellpadding='0px' border='1px' bgcolor='#d3d3d3 ' align='center' style='display: inline-block;'><tr><td>Total Recieved</td></tr><tr><td>" + totalRec + "</td></tr></table>";
document.getElementById('footer').innerHTML += "<table class='totallingtable' cellspacing='0' cellpadding='0px' border='1px' bgcolor='#d3d3d3 ' align='center' style='display: inline-block;'><tr><td>Total</td></tr><tr><td>$" + dollarTotal + "</td></tr></table>";
//document.getElementById('footer').innerHTML += '<table class='totallingtable' cellspacing='2' cellpadding='0px' border='2px' align='center' style='opacity: 1;display: inline-block;'><caption style='display: none'>Total Qty</caption><tbody><tr><td>' + totalQty + '</td></tr></tbody></table>';
//document.getElementById('footer').innerHTML += '<table class='totallingtable' cellspacing='2' cellpadding='0px' border='2px' align='center' style='opacity: 1;display: inline-block;'><caption style='display: none'>Total Billed</caption><tbody><tr><td>' + totalBilled + '</td></tr></tbody></table>';
//document.getElementById('footer').innerHTML += '<table class='totallingtable' cellspacing='2' cellpadding='0px' border='2px' align='center' style='opacity: 1;display: inline-block;'><caption style='display: none'>Total Recieved</caption><tbody><tr><td>' + totalRec + '</td></tr></tbody></table>';
document.getElementById('footer').innerHTML += '</center>';}
function getItemTotalPageLoadScriptView(){
var record = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId());
var totalQty = 0;
var totalBilled = 0;
var totalRec = 0;
var dollarTotal = 0;
var lineCount = record.getLineItemCount('item');
var correctedLineCount = 0;for (var i = 1; i <= lineCount; i++) {
//filter out only items you want to count, example below..
//alert(Number(nlapiGetLineItemValue('item', 'amount', i)));if (record.getLineItemValue('item', 'isclosed', i)=='F' || record.getLineItemValue('item', 'isclosed', i)==null){
totalQty += parseInt(record.getLineItemValue('item', 'quantity', i));
totalBilled += parseInt(record.getLineItemValue('item', 'quantitybilled', i));
totalRec += parseInt(record.getLineItemValue('item', 'quantityreceived', i));
dollarTotal += Number(record.getLineItemValue('item', 'amount', i));
correctedLineCount += 1;
}
}
if (isNaN(totalBilled)) totalBilled=0;
if (isNaN(totalRec)) totalRec=0;
var dollarTotal = Math.round(dollarTotal * 100) / 100 //round to 2nd decimaldocument.getElementById('footer').innerHTML = '<center>';
document.getElementById('footer').innerHTML += "<table class='totallingtable' cellspacing='0' cellpadding='0px' border='1px' bgcolor='#d3d3d3 ' align='center' style='display: inline-block;'><tr><td>Line Count</td></tr><tr><td>" + correctedLineCount + "</td></tr></table>";
document.getElementById('footer').innerHTML += "<table class='totallingtable' cellspacing='0' cellpadding='0px' border='1px' bgcolor='#d3d3d3 ' align='center' style='display: inline-block;'><tr><td>Total Qty</td></tr><tr><td>" + totalQty + "</td></tr></table>";
document.getElementById('footer').innerHTML += "<table class='totallingtable' cellspacing='0' cellpadding='0px' border='1px' bgcolor='#d3d3d3 ' align='center' style='display: inline-block;'><tr><td>Total Billed</td></tr><tr><td>" + totalBilled + "</td></tr></table>";
document.getElementById('footer').innerHTML += "<table class='totallingtable' cellspacing='0' cellpadding='0px' border='1px' bgcolor='#d3d3d3 ' align='center' style='display: inline-block;'><tr><td>Total Recieved</td></tr><tr><td>" + totalRec + "</td></tr></table>";
document.getElementById('footer').innerHTML += "<table class='totallingtable' cellspacing='0' cellpadding='0px' border='1px' bgcolor='#d3d3d3 ' align='center' style='display: inline-block;'><tr><td>Total</td></tr><tr><td>$" + dollarTotal + "</td></tr></table>";
//document.getElementById('footer').innerHTML += '<table class='totallingtable' cellspacing='2' cellpadding='0px' border='2px' align='center' style='opacity: 1;display: inline-block;'><caption style='display: none'>Total Qty</caption><tbody><tr><td>' + totalQty + '</td></tr></tbody></table>';
//document.getElementById('footer').innerHTML += '<table class='totallingtable' cellspacing='2' cellpadding='0px' border='2px' align='center' style='opacity: 1;display: inline-block;'><caption style='display: none'>Total Billed</caption><tbody><tr><td>' + totalBilled + '</td></tr></tbody></table>';
//document.getElementById('footer').innerHTML += '<table class='totallingtable' cellspacing='2' cellpadding='0px' border='2px' align='center' style='opacity: 1;display: inline-block;'><caption style='display: none'>Total Recieved</caption><tbody><tr><td>' + totalRec + '</td></tr></tbody></table>';
document.getElementById('footer').innerHTML += '</center>';}
function pageInit(){
var node = document.createElement('div'); // Create a <div> nodenode.setAttribute('id', 'footer');
node.style.cssText = 'position: fixed; bottom: 0px; color: rgb(0, 0, 0); height: 100px; z-index: 1000;width: 50%;margin: 0 auto; ';
document.getElementsByTagName('body')[0].appendChild(node);var nodePad = document.createElement('div'); // Create a <div> node
nodePad.setAttribute('id', 'footerpad');
nodePad.style.cssText = 'color: #000;opacity: 0.7;height: 100px;z-index: 1000';
document.getElementsByTagName('body')[0].appendChild(nodePad);//var divCSS = 'background:#d3d3d3;color: #000;opacity: 0.7;height: 100px;z-index: 1000';
//document.body.innerHTML += '<div id='footer' style='' + divCSS + ''>Something in footer</div>';
document.addEventListener('DOMContentLoaded', function (event) {
var element = document.getElementById('container');
var height = element.offsetHeight;
if (height < screen.height) {
document.getElementById('footer').classList.add('stikybottom');
}
}, false);getItemTotalPageLoadScript();
}
-
AuthorPosts
You must be logged in to reply to this topic.