Java Script Looping

 9 Replies
 0 Subscribed to this topic
 12 Subscribed to this forum
Sort:
Author
Messages
Eddie Smith
Advanced Member
Posts: 39
Advanced Member
    I'm new to using Design Studio and trying to make an IC user field a required field on the IC21.1 form (Inventory Issue screen). I'm able to get the script to check the first line on the detail section, but how do you get it to check all lines having an item being issued out? Below is my JAVA script. Any help would be appreciated.

    function FORM_OnBeforeTransaction(fc)
    {
    if (fc == "A" || fc == "C")
    {
    var sUserFld = lawForm.getFormValue("text22");
    if (sUserFld == "")
    {
    lawForm.positionInFieldById("text22");
    alert("Badge ID is required")
    return false
    }

    }
    return true;
    }
    Gary Davies
    Veteran Member
    Posts: 248
    Veteran Member
      Need to do a for loop for the number of detail lines and reference the field as such:

      for (var i=0.......
      var UserFld = lawForm.getFormValue("text22",i);
      ....
      David Williams
      Veteran Member
      Posts: 1127
      Veteran Member
        Check my blog for a couple of ideas:

        http://consultdavidw.blog...t-line-solution.html

        http://consultdavidw.blog...line-solution-2.html
        David Williams
        Eddie Smith
        Advanced Member
        Posts: 39
        Advanced Member
          Thanks Gary for the quick response. But when I add you code to my, it does not check the user field. I must be placing the code in the wrong section. Where should I insert your code?
          Gary Davies
          Veteran Member
          Posts: 248
          Veteran Member
            Example if there are 8 detail lines:

            if (fc == "A" || fc == "C")
            {
            for (var i=0;i<8;i++) {
            var sUserFld = lawForm.getFormValue("text22",i);
            if (sUserFld == "")
            {
            lawForm.positionInFieldById("text22",i);
            alert("Badge ID is required")
            return false
            }
            }
            }
            Gary Davies
            Veteran Member
            Posts: 248
            Veteran Member
              But I would code it:

              if (fc == "A" || fc == "C")
              {
              for (var i=0;i<8;i++) {
              if (lawForm.getFormValue("text22",i) == "")
              {
              lawForm.positionInFieldById("text22",i);
              alert("Badge ID is required")
              return false
              }
              }
              }
              Eddie Smith
              Advanced Member
              Posts: 39
              Advanced Member
                Gary, it still does not check to see if the user field is blank, it just adds the record anyways. Any ideas?
                Gary Davies
                Veteran Member
                Posts: 248
                Veteran Member
                  User fields are on IC21.3, did you add a new field to the detail area that is the text22. If yes then it is probably how you added it that you only see one occurance. You have to add WHILE in the detail area (select the area then click on Object button at bottom), if you just paste it on top you will get the field but it really is not part of the detail area.

                  You may have to fudge with the source as well becuase it really is not a field defined to the detail area.
                  Eddie Smith
                  Advanced Member
                  Posts: 39
                  Advanced Member
                    I did add the new text field to the detail area, but I was within the detail area before I added it (I was in the child object ). It assigned text22 to the text box and then I used the data source and selected USR_FLD_01 (which as you mentioned was named text1, feild=_f2 in IC21.3. We first tried adding the user field @ the header but it would not show as available under the data souce. Fudging the source sounds like it may be the only option. Thanks.
                    Gary Davies
                    Veteran Member
                    Posts: 248
                    Veteran Member
                      You can not just add the data source from other screens, you will have to populate the value in OnBeforeTransaction and do an AGS call to IC21.3 in OnAfterTransaction to update that User Field.