AP26 - Javascript Help

 4 Replies
 0 Subscribed to this topic
 12 Subscribed to this forum
Sort:
Author
Messages
AG
Advanced Member
Posts: 29
Advanced Member
    Our Finance team asked us to add two total fields onto AP26. They want to see total dollars and invoice count, when an Inquiry is done on the form.
    I added the fields onto the form no problem. I also then added the JS script to loop thru all the lines on the form and display the total dollars and invoice count.
    The only issue I ran into is when they hit the page up or page down buttons. My JS only  displays the totals for the actual data displayed and does NOT count the invoices not displayed currently.
    Does anyone know how I can fix this? Am I going to have to execute a DME directly to the table and add up the totals that way?

    TIA.
    John Henley
    Posts: 3353
      You are going to have to do a DME against the backend tables.
      Thanks for using the LawsonGuru.com forums!
      John
      AG
      Advanced Member
      Posts: 29
      Advanced Member
        Can someone post a sample JS script that shows how to loop through the records that I get back from the DME Call? I have the code and syntax to make the call I just need the syntax for the loop
        Ragu Raghavan
        Veteran Member
        Posts: 476
        Veteran Member
          This code looks up APINVOICE for a specific company + invoice and populates a textarea box with the invoice details.

          function getAPI (vCompany, vVendor)
          {
          var s = portalWnd.DMEPath;
          s += "?PROD=" + sPDL;
          s += "&FILE=APINVOICE";
          s += "&FIELD=INVOICE;INVOICE-DTE;TRAN-INV-AMT";
          s += "&INDEX=APISET1";
          s += "&KEY=" + vCompany + "=" + vVendor;
          s += "&OUT=XML";

          var sReturn=portalWnd.httpRequest(s);

          if (!sReturn || sReturn.status)
          {
          alert("status s " + sReturn.status);
          return true;
          }

          var vObjXML = new portalWnd.DataStorage(sReturn);
          var vRecords = vObjXML.document.getElementsByTagName("RECORD");
          var str = "";
          for (var ix=0; ix < vRecords.length - 1 ; ix++)
          {
          var vCols = vRecords[ix].getElementsByTagName("COL");
          if (ix != 0)
          {
          str += "\r";
          }
          str += vCols[0].firstChild.data + "," + vCols[1].firstChild.data + "," + vCols[2].firstChild.data
          lawForm.setFormValue("textarea1",str);
          }
          return true;

          }
          Terry P
          Veteran Member
          Posts: 234
          Veteran Member
            Here is my code to add up the total of all distribution lines:

            //Construct DME for getting info
            sDME = "http://" + window.location.host + "/cgi-lawson/dme.exe?" // version 8
            sDME += "PROD=" + strPDL
            sDME += "&FILE=MMDIST&INDEX=MMDSET1"
            sDME += "&KEY=" + sCompany + "="
            + sSystemCD + "="
            + sLocation + "="
            + sDocType + "="
            + sPONumber
            sDME += "&FIELD=DIST-PERCENT"
            sDME += "&SELECT=LINE-NBR=" + sPOLine
            sDME += "&OUT=CSV&DELIM=~&NOHEADER"

            //Return value from table
            var objhttp = new ActiveXObject("Msxml2.XMLHTTP")
            objhttp.Open("GET", sDME, false)
            objhttp.Send("UserInfo")
            sReturn = objhttp.responseTEXT


            if(sReturn != "") //If there is data returned
            {
            //Remove the carriage return character, if any.
            while(sReturn.search("\r")>-1)
            {
            sReturn = sReturn.replace("\r","")
            }

            //Split into individual records on the line feed character.
            aRecs = sReturn.split("\n")

            //Remove the last blank record
            aRecs.pop()

            //Initialize Total counter
            nTotal = 0

            //Break the records into fields and Total
            for(i = 0; i < aRecs.length; i++)
            {
            aFields = aRecs.split("~")
            var num = formatCurrency((parseFloat(lawForm.getFormValue("textextamt")) * parseFloat(aFields[0])) / 100)
            nTotal += parseFloat(num)
            }


            var numTotalFormated = formatCurrency(nTotal)
            lawForm.setFormValue("distribtotal",numTotalFormated)

            var numRemainingFormated = formatCurrency(((parseFloat(lawForm.getFormValue("textextamt"))) - parseFloat(numTotalFormated)))

            if (numRemainingFormated == "0.00")
            numRemainingFormated = "";

            lawForm.setFormValue("undist-amt",numRemainingFormated)
            }
            else
            lawForm.setMessage("No distribution records found")