How do I process multiple records?

 2 Replies
 0 Subscribed to this topic
 12 Subscribed to this forum
Sort:
Author
Messages
wilcoxmad
Veteran Member
Posts: 87
Veteran Member

    I am trying to show all the jobcodes and start dates for an employee. I am getting only the first one. When I try to fill out data from the second record, or more, the form doesn't fill out and I get an error:  '2' is null or not an object.  Any suggestions?

    I think this has to do with using code designed to process one record and trying to process many.

    function FORM_OnAfterTransaction(data)
    {
     //was transaction successful?
     if (formState.agsError) return;
     
     var vCompany=lawForm.getFormValue("text1");
     var vEmpl=lawForm.getDataValueById("text2");

     // blank out all date and jobcode fields.
     lawForm.setFormValue("text229","");
     lawForm.setFormValue("text230","");
     lawForm.setFormValue("text241","");
     lawForm.setFormValue("text242",""); 

     s = "?XCOLS=TRUE&XKEYS=TRUE&XCOUNT=TRUE" +
     "&XRELS=FALSE&XIDA=FALSE&XNEXT=FALSE" +
     "&PROD=" + portalObj.getUserVariable("PRODLINE") +
     "&FILE=PAEMPPOS" +
     "&FIELD=EFFECT-DATE;JOB-CODE" +
     "&INDEX=PEPSET3" +
     "&KEY=" + vCompany + "=" + vEmpl + "=" + 1 + "=" +
     "&OUT=XML";

      var vDMEInfo = top.httpRequest(top.DMEPath + s);
     
     //Set the DME result data to an XML object to parse through.
     var DMEobj = new top.DataStorage(vDMEInfo);

     var vRecords = DMEobj.document.getElementsByTagName("RECORD");
     if (vRecords.length == 0)
     {
      alert("No PAEMPPOS record found.");
      return true;
     }
     else
     {
      var vCols = vRecords[0].getElementsByTagName("COL");
      vEffDt1 = vCols[0].firstChild.data;
      lawForm.setFormValue("text229",vEffDt1);

      var vCols = vRecords[1].getElementsByTagName("COL");
      vJobCode1 = vCols[1].firstChild.data;
      lawForm.setFormValue("text230",vJobCode1);
      
      var vCols = vRecords[2].getElementsByTagName("COL");
      vEffDt2 = vCols[2].firstChild.data;
      lawForm.setFormValue("text241",vEffDt2);

      var vCols = vRecords[3].getElementsByTagName("COL");
      vJobCode2 = vCols[3].firstChild.data;
      lawForm.setFormValue("text242",vJobCode2);
      }
    }

    John Henley
    Posts: 3353

      Perhaps you're confusing columns with rows.

      You are asking 2 fields in your DME:


       "&FIELD=EFFECT-DATE;JOB-CODE" +

      But you are trying to reference 4 rows by 4 columns in your logic:

        var vCols = vRecords[0].getElementsByTagName("COL");
        vEffDt1 = vCols[0].firstChild.data;
        lawForm.setFormValue("text229",vEffDt1);

        var vCols = vRecords[1].getElementsByTagName("COL");
        vJobCode1 = vCols[1].firstChild.data;
        lawForm.setFormValue("text230",vJobCode1);
       
        var vCols = vRecords[2].getElementsByTagName("COL");
        vEffDt2 = vCols[2].firstChild.data;
        lawForm.setFormValue("text241",vEffDt2);

        var vCols = vRecords[3].getElementsByTagName("COL");
        vJobCode2 = vCols[3].firstChild.data;
        lawForm.setFormValue("text242",vJobCode2);   }

      I think you really want something like this (assuming two rows are returned...)

        var vCols = vRecords[0].getElementsByTagName("COL");
        vEffDt1 = vCols[0].firstChild.data;
        lawForm.setFormValue("text229",vEffDt1);
        vJobCode1 = vCols[1].firstChild.data;
        lawForm.setFormValue("text230",vJobCode1);
       
        var vCols = vRecords[1].getElementsByTagName("COL");
        vEffDt2 = vCols[0].firstChild.data;
        lawForm.setFormValue("text241",vEffDt2);
        vJobCode2 = vCols[0].firstChild.data;
        lawForm.setFormValue("text242",vJobCode2);

      Ideally though, you should put this in a loop that looks at vRecords.length to see how many rows were returned.

      Thanks for using the LawsonGuru.com forums!
      John
      wilcoxmad
      Veteran Member
      Posts: 87
      Veteran Member
        Thanks John, know where I can find an example of that?