DME call

 13 Replies
 0 Subscribed to this topic
 12 Subscribed to this forum
Sort:
Author
Messages
Lynne
Veteran Member
Posts: 122
Veteran Member
    Hello-
    I am wondering if someone could look at my DME function call and see if they can tell me what's wrong with it.  I've used Lawson DS user guide and posts from this forum to get it put together.

    I don't get an error when it sends the call to the server (none pop up anyway), but the sReturn.status comes back as undefined.  The alert that displays sReturn is blank.

    Here is what variable s displays as in my alert.

    /servlet/Router/Data/Erp?PROD=TEST&FILE=POLINESRC&FIELD=PO-NUMBER;LINE-NBR;SOURCE-DOC-N&SELECT=PO-NUMBER=1196824%26LINE-NBR=1&OUT=XML

    Here is my function:

    //  DME call to POLINESRC to get req# of PO
    function getReqNumber(po,line)
    {
    var sPDL = portalWnd.oUserProfile.getAttribute("productline");

    var s = portalWnd.DMEPath;
    s += "?PROD=" + sPDL;
    s += "&FILE=POLINESRC";
    s += "&FIELD=PO-NUMBER;LINE-NBR;SOURCE-DOC-N";
    s += "&SELECT=PO-NUMBER=" + po;
    s += "%26LINE-NBR=" + line;
    s += "&OUT=XML";
    //s += "&OUT=CSV&DELIM=~&NOHEADER";
    alert("s " + s);
    var sReturn=portalWnd.httpRequest(s);
    alert("sReturn " + sReturn);
    alert("sReturn.status " + sReturn.status);
    return true; 
    }

    Thanks you!

    Terry P
    Veteran Member
    Posts: 234
    Veteran Member
      Lynne - why do you have the PO number as part of your select? Why not use an index to the file?
      Lynne
      Veteran Member
      Posts: 122
      Veteran Member
        I followed Lawson's example in the DS User Guide. I could try setting up the index and see if that helps.
        John Henley
        Posts: 3353
          Posted By Terry P on 09/10/2013 02:43 PM
          Lynne - why do you have the PO number as part of your select? Why not use an index to the file?


          Actually, there is not an index that can be used based on the parameters that Lynne is passing into the function, so she has to use the select.
          In order to use the index, she also would need to pass in the company, po_code, and po_release.

          Lynne, what is the context of the DME query that you are attempting? do you also have those fields?
          Thanks for using the LawsonGuru.com forums!
          John
          Lynne
          Veteran Member
          Posts: 122
          Veteran Member
            I do have po_code and po_release (these are always blank and 0 respectively but I used fields that were available. I just didn't want you to think I hard-coded them), so I switched to the index. Unfortunately, I get the same results. sReturn is blank and the status is undefined. Below is my function and value of s variable:

            /servlet/Router/Data/Erp?PROD=TEST&FILE=POLINESRC&FIELD=PO-NUMBER;LINE-NBR;SOURCE-DOC-N&INDEX=PLSSET1&KEY=100==1196824=0=1&OUT=XML

            // DME call to POLINESRC to get req# of PO
            function getReqNumber(co,code,po,rel,line)
            {
            var sPDL = portalWnd.oUserProfile.getAttribute("productline");

            var s = portalWnd.DMEPath;
            s += "?PROD=" + sPDL;
            s += "&FILE=POLINESRC";
            s += "&FIELD=PO-NUMBER;LINE-NBR;SOURCE-DOC-N";
            s += "&INDEX=PLSSET1";
            s += "&KEY=" + co + "=" + code + "=" + po + "=" + rel + "=" + line;
            //s += "&SELECT=PO-NUMBER=" + po;
            //s += "%26LINE-NBR=" + line;
            s += "&OUT=XML";
            //s += "&OUT=CSV&DELIM=~&NOHEADER";
            alert("s " + s);
            var sReturn=portalWnd.httpRequest(s);
            alert("sReturn " + sReturn);
            alert("sReturn.status " + sReturn.status);
            return true;
            }
            Randy Jacoy
            Veteran Member
            Posts: 46
            Veteran Member
              Lynne,

              We don't use the PO functionality so I can't be too specific.  One thing I've found useful is to try the DME call in a browser window so I can get a better idea of what's returning.  To do that, log into Portal, and then in the address bar, replace everything after the domain portion of the URL with your DME call.  For example:

              https:///servlet/Router/Data/Erp?PROD=TEST&FILE=POLINESRC&FIELD=PO-NUMBER;LINE-NBR;SOURCE-DOC-N;&INDEX=PLSSET1&KEY=100==1196824=0=1=====&XCOLS=TRUE&XKEYS=TRUE&XRELS=FALSE&XCOUNT=FALSE&XIDA=FALSE&OUT=XML

              Press enter and you'll see the results of the call in your browser in XML form.

              I see that PO Number is defined as ALPHARIGHT14.  I'm wondering if perhaps you need to left pad your PO number with spaces.  Try prefixing 1196824 with 7 spaces and see if it makes a difference.
              Randy Jacoy
              Veteran Member
              Posts: 46
              Veteran Member
                I had surrounded the domain name in the URL with less than and greater than symbols and I see they were removed when I submitted the post.  Lets try again:

                https://yourdomain/servlet/Router/Data/Erp?PROD=USBAPC&FILE=POLINESRC&FIELD=PO-NUMBER;LINE-NBR;SOURCE-DOC-N;&INDEX=PLSSET1&KEY=100==+++++++1196824=0=1=====&XCOLS=TRUE&XKEYS=TRUE&OUT=XML
                John Henley
                Posts: 3353
                  Lynne, because of the way PO number is stored (alpha 14 but right justified), you need to add spaces to pad on the left for the PO number.
                  So, change this to prepend the correct number of spaces.
                  
                  s += "&KEY=" + co + "=" + code + "=" + "++++++++++++++".substr(0,14-po.length).concat(po) + "=" + rel + "=" + line; 
                   
                  Thanks for using the LawsonGuru.com forums!
                  John
                  Lynne
                  Veteran Member
                  Posts: 122
                  Veteran Member
                    I get the same results whether the PO# is pre-padded with spaces or not.

                    I ran my DME from the browser as Randy suggested (thanks, Randy , for the debugging tip), and it works perfectly. It works from the browser whether the PO# is padded with spaces or not.

                    This makes me believe that it is not even connecting to the server. We are coupled (federated), and it causes many problems. I wonder if that has something to do with it. Are any of you working on federated systems?
                    John Henley
                    Posts: 3353
                      Add an alert for sPDL and for portalWnd.DMEPath and make sure those are actually populated.
                      As for federation, that shouldn't matter, but just to make sure, what LSF version you on?
                      Thanks for using the LawsonGuru.com forums!
                      John
                      Randy Jacoy
                      Veteran Member
                      Posts: 46
                      Veteran Member
                        Lynne,

                        We don't use Federation here.

                        In your original post you mentioned Status was undefined.  I belive that is normal.  On return from DME calls if I get something in the Status field I consider it an error.  Try checking your record count and see if you are getting records back.

                        Here is my error checking code from a DME return:

                                if (!sReturn || sReturn .status)
                                {
                                    var msg="Error calling DME, ";
                                    msg += (sReturn ? "(status code): " + sReturn .status: "bad server response.");
                                    alert(msg);
                                    return true;
                                }
                        Lynne
                        Veteran Member
                        Posts: 122
                        Veteran Member
                          sPDL and protalWnd.DMEPath are correctly populated. We are on LSF 9.0.1.10.681

                          I put the error checking routine in, and it doesn't return the message. So, it appears that it must've worked.

                          I found some code about loading variables w/ records returned by a DME. I put this in and the only field I get data is vRecords.length=1. I don't fully understand what the code does, but it appears to parse out the xml data into the field. What is the property for record count? That would be a good one to display.


                          // create an XML object to contain the DME data
                          var vObjDMEXML = new portalWnd.DataStorage(sReturn);
                          //load a variable with the record returned by DME
                          var vRecords = vObjDMEXML.document.getElementsByTagName("RECORD");
                          alert("vRecords.length " + vRecords.length);
                          if (vRecords.length == 0)
                          {
                          alert("No req number found for PO");
                          return true;
                          }
                          var vCols = vRecords[0].getElementsByTagName("COL");
                          alert("vCols " + vCols);
                          lawForm.setElementValue("text37",vCols[0].firstChild.data);
                          Randy Jacoy
                          Veteran Member
                          Posts: 46
                          Veteran Member
                            The vREcord.Length property indicates how many records were returned for your search.  In your case you got one record back. 

                            This line of code:

                            var vCols = vRecords[0].getElementsByTagName("COL");

                            populates the vCols variable with all the "COL" elements (columns returned from the database) for the 1st record (vRecords[0]) that was returned.

                            This piece of code:

                            vCols[0].firstChild.data

                            Refers to the first field returned in the record.  In your case i believe the first field you returned was PO-NUMBER.  If everything went as planned, text37 should contain the PO-NUMBER.  Try using setFormValue instead of setElementValue.

                            You can verify that you are getting back COLs by using the debugging technique I mentioned earlier where you paste the call in the browser address bar.
                            Lynne
                            Veteran Member
                            Posts: 122
                            Veteran Member
                              I can't believe that it is finally working. I did see the COL rows in my browser and figured that was what it was doing. All along, I was thinking I should see all the returned data in the vRecords variable. I guess you can't see it until you do all the parsing and loading of the element. My text37 is in a detail section, so I had to add the row in the setFormValue.

                              Thank you Randy and John for all of your help. I have learned much and greatly appreciate your time.