This topic contains 14 replies, has 0 voices, and was last updated by jmessersmith 8 years, 4 months ago.

  • Author
    Posts
  • #2663

    jmessersmith

    Is 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.

  • #2664

    errol

    Do 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

  • #2665

    jmessersmith

    Do you have an example of how to “hack” it? I’m not sure how to do this, nothing has an ID assigned.

  • #2666

    errol

    Is 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?

  • #2667

    jmessersmith

    Its the item sublist on a transaction.

  • #2668

    errol

    Below 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.

    [js]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 ‘; 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(‘

    ‘ + itemCount + ‘ Items

    ‘);’; script_c += ‘ }’; script_c += ‘ }); ‘; script_c += ‘‘;

    return script_c;
    }[/js]

  • #2669

    jmessersmith

    I 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 += “

    “;

  • #2670

    jmessersmith

    I found a solution, I’ll post my complete code when I’m done.

    Code:
    var node = document.createElement(“div”); // Create a

    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);

  • #2671

    jmessersmith

    Is there a way to execute javascript on the view part of a form? I don’t see how its done.

  • #2672

    michoel

    Originally 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();

  • #2673

    jmessersmith

    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?

  • #2674

    errol

    That’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.

  • #2675

    michoel

    Originally 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’));

  • #2676

    jmessersmith

    Nevermind, I need to use getLineItemValue.

  • #2677

    jmessersmith

    I 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

    node

    node.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

    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 += ‘

    ‘;
    document.addEventListener(‘DOMContentLoaded’, function (event) {
    var element = document.getElementById(‘container’);
    var height = element.offsetHeight;
    if (height ‘;
    document.getElementById(‘footer’).innerHTML += “

    Line Count
    ” + correctedLineCount + “

    “;
    document.getElementById(‘footer’).innerHTML += “

    Total Qty
    ” + totalQty + “

    “;
    document.getElementById(‘footer’).innerHTML += “

    Total Billed
    ” + totalBilled + “

    “;
    document.getElementById(‘footer’).innerHTML += “

    Total Recieved
    ” + totalRec + “

    “;
    document.getElementById(‘footer’).innerHTML += “

    Total
    $” + dollarTotal + “

    “;
    //document.getElementById(‘footer’).innerHTML += ‘

    Total Qty
    ‘ + totalQty + ‘

    ‘;
    //document.getElementById(‘footer’).innerHTML += ‘

    Total Billed
    ‘ + totalBilled + ‘

    ‘;
    //document.getElementById(‘footer’).innerHTML += ‘

    Total Recieved
    ‘ + totalRec + ‘

    ‘;
    document.getElementById(‘footer’).innerHTML += ‘‘;

    }

    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 ‘;
    document.getElementById(‘footer’).innerHTML += “

    Line Count
    ” + correctedLineCount + “

    “;
    document.getElementById(‘footer’).innerHTML += “

    Total Qty
    ” + totalQty + “

    “;
    document.getElementById(‘footer’).innerHTML += “

    Total Billed
    ” + totalBilled + “

    “;
    document.getElementById(‘footer’).innerHTML += “

    Total Recieved
    ” + totalRec + “

    “;
    document.getElementById(‘footer’).innerHTML += “

    Total
    $” + dollarTotal + “

    “;
    //document.getElementById(‘footer’).innerHTML += ‘

    Total Qty
    ‘ + totalQty + ‘

    ‘;
    //document.getElementById(‘footer’).innerHTML += ‘

    Total Billed
    ‘ + totalBilled + ‘

    ‘;
    //document.getElementById(‘footer’).innerHTML += ‘

    Total Recieved
    ‘ + totalRec + ‘

    ‘;
    document.getElementById(‘footer’).innerHTML += ‘‘;

    }

    function pageInit(){
    var node = document.createElement(‘div’); // Create a

    node

    node.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

    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 += ‘

    ‘;
    document.addEventListener(‘DOMContentLoaded’, function (event) {
    var element = document.getElementById(‘container’);
    var height = element.offsetHeight;
    if (height

  • You must be logged in to reply to this topic.