validating field for each row in the details section of a form

 8 Replies
 0 Subscribed to this topic
 12 Subscribed to this forum
Sort:
Author
Messages
mjcindc
Basic Member
Posts: 8
Basic Member
    Hi All,
    I'm working on and customizaton to PO39.1. I need to iterate through all rows in the details section and check to see if the 'FC' value is 'A' or 'C'.  If it is, I want to make sure there is something in the 'sublot' field.  With what I've written, it only checks the 'sublot' field on the first row even if the add or change is on another row.  As long as the 'sublot' field is populated in row one it accepts the change.  This is what I've got so far.  It's clear to me I'm missing the iterate through each row part, but I don't have a clue how.  Any help is appreciated.


    function FORM_OnBeforeTransaction(fc1)
        {
        if (fc1== "A" || fc1== "C")
        {   
            var sUserFld = lawForm.getFormValue("text3",formState.currentRow);
            if (sUserFld == "")
            {
            lawForm.positionInFieldById("text3");
            lawForm.setMessage("Field is required");
            return false
            }
        }
        return true;
    }
    Gary Davies
    Veteran Member
    Posts: 248
    Veteran Member
      The function code passed to OnBeforeTransaction is the Form function code, not the line function code.  you need to check the form value the same way you checked the user field

      If you only care about the currently selected row then use currentRow, otherwise you will need to loop through the lines with a do (var i=0;i<10;i++)

      function FORM_OnBeforeTransaction(FC)
          {
          if (FC == "A" || FC == "C")
          {   
              var sUserFld = lawForm.getFormValue("text3",formState.currentRow);
              var sLineFC = lawForm.getFormValue("fc1",formState.currentRow);
              if (sUserFld == "" && (sLineFC == "A" || sLineFC == "C"))
              {
              lawForm.positionInFieldById("text3");
              lawForm.setMessage("Field is required");
              return false
              }
          }
          return true;
      }

      If you only care about the currently selected row then use currentRow, otherwise you will need to loop through the lines with a do

      function FORM_OnBeforeTransaction(FC)
          {
          if (FC == "A" || FC == "C")
          {    
             for (var i=0;i<4;i++) {
                  var sUserFld = lawForm.getFormValue("text3",i);
                 var sLineFC = lawForm.getFormValue("fc1",i);
                 if (sUserFld == "" && (sLineFC == "A" || sLineFC == "C"))
                 {
                       lawForm.positionInFieldById("text3",i);
                       lawForm.setMessage("Field is required");
                       return false
                }
             }
          }
          return true;
      }
      mjcindc
      Basic Member
      Posts: 8
      Basic Member
        Thanks, Gary.  That second piece of code was exactly what I needed.  Of course, success leads to more work and I've got another related question.  I'm doing the same change to IC29.1 and it seems I can continue to add lines in the detail section by using page down.  I've added 36 lines and have given up the experiment to see if I run out of available lines to populate.  Is there a function to get the number of populated lines in the detail area?  Something like getRowCount?  That's a made up name.  It would look like this:

        function FORM_OnBeforeTransaction(FC)
            {
            if (FC == "A" || FC == "C")
            {   
               for (var i=0;i             var sUserFld = lawForm.getFormValue("text3",i);
                   var sLineFC = lawForm.getFormValue("fc1",i);
                   if (sUserFld == "" && (sLineFC == "A" || sLineFC == "C"))
                   {
                         lawForm.positionInFieldById("text3",i);
                         lawForm.setMessage("Field is required");
                         return false
                  }
               }
            }
            return true;
        }
        Gary Davies
        Veteran Member
        Posts: 248
        Veteran Member
          There is no stored value of the max lines of a detail area, but you can get it:

          var mDetail = lawForm.magic.formWnd.detailColl.getItem("DT0");
          if (mDetail) var detailMax = mDetail.rows;

          DT0 is the id of the detail area of this example.
          mjcindc
          Basic Member
          Posts: 8
          Basic Member
            Thanks again. This works just as I hoped.

            I'm new to JavaScript and Design Studio. I'm a strong SQL programmer with a bit of Java and a lot of Perl in my toolbox, so I figured I could work out the Javascript. I've attempted to find these answers on my own, but I'm a bit discouraged about my chances. When I google javascript and magic.formWnd there are no results. Therefore, I assume these are lawson created objects. Is there some documentation I should be reading to learn this stuff? It's certainly not in the training materials they gave me in my Design Studio class. I'd like to become proficient with Design Studio but the documentation just doesn't seem to be available.
            Gary Davies
            Veteran Member
            Posts: 248
            Veteran Member
              That is correct, "magic" is a Lawson specific object.   There are good examples at the end of the Design Studio user manual to get a feel of what things you can do. 

              The rest was learned on the job and with a lot of digging on my part. 
              John Henley
              Posts: 3353
                There is certainly no "definitive reference" but we consultants do try to share our examples in addition to the ones Lawson provides. One suggestion is that you "invest" in a browser plugin that will let you explore the DOM, etc. --that's how I figure out a lot of stuff.
                Thanks for using the LawsonGuru.com forums!
                John
                Terry P
                Veteran Member
                Posts: 234
                Veteran Member
                  John - can you be more specific when you talke about a browser plugin. Suggestions, examples of what you can do, etc.

                  Thanks!
                  John Henley
                  Posts: 3353
                    Here's a link to a blog showing the two tools I use:
                    - Firebug for firefox
                    - Developer toolbar for IE (built-in to IE8, addon for IE6/IE7)

                    http://elegantcode.com/20...8-developer-toolbar/
                    Thanks for using the LawsonGuru.com forums!
                    John