DME Field Changes

 16 Replies
 0 Subscribed to this topic
 12 Subscribed to this forum
Sort:
Author
Messages
Robert Spurr
Veteran Member
Posts: 130
Veteran Member
    I've been looking at enhancing some of my Portal Page DME calls with color.  Specifically changing the color of a specific field and or row (something like a green bar paper effect).   Has anyone ever done this and if so can you point me in the right direction.

    Thanks
    Robert
    wilcoxmad
    Veteran Member
    Posts: 87
    Veteran Member
      Robert,

      I too would like to be able to change the color of a field or the text in the field. Has anyone done this? I want to change the color of a field, Status Desc, depending on the value in the Status (select1) field.

      Thanks.
      Randy Jacoy
      Veteran Member
      Posts: 46
      Veteran Member
        We've done color changes on labels or fields to indicate required fields or validation errors.  We begin by defining a couple of color variables like so:

        var lawsonStandardColor = "#333333";  /* Default Lawson Label color */
        var mediumGreen = "#008000"; // Medium green color for labels on required fields.

        Then we change the color of the label text in the FORM_OnInit or FORM_OnBeforeTransaction as follows:

         lawForm.getFormElement("label3").style.color = mediumGreen; /* Vendor Class */
         lawForm.getFormElement("label5").style.color = lawsonStandardColor; /* Tax ID */

        If we discover an error when validating a field, we make it red as follows:

        lawForm.getFormElement("label5").style.color = "red";
        wilcoxmad
        Veteran Member
        Posts: 87
        Veteran Member
          Randy, Thank you for that info it is very helpfull.
          What I want to do is most like the example of validating a field. I am not sure when to check the value. I want to change the color of the field, on an Inquire, when it is being loaded but before it is displayed to the user. Is that possible and if so how?

          Thanks.
          Randy Jacoy
          Veteran Member
          Posts: 46
          Veteran Member
            For real time field validation you would do the color change in the TEXT_OnBlur() function (assuing you are validating a text field).  When the user enters a value and then leaves the text field the TEXT_OnBlur() event will fire.  If you are talking about validating when the user submits the form, you would do the color change in the FORM_OnBeforeTransaction() function.  That is the event that fires when the user clicks an action button.

            Lets say you want to make Tax ID a required field.  The entry field is called text1 and the label for that field is called label1.  You need to validate that the user entered something in that field.  In design studio you made label1 green to indicate it is required. (Alternately you could change it to green in the FORM_OnInit() function but it's easier to do it at design time).  For real time field validation you would place the following code in the TEXT_OnBur() function:

            if (  id == "text1" ) {  // The user just left the Tax ID input field.
                if ( lawForm.getFormValue("text1") == "" ) {  // The user didn't enter anything.
                    lawForm.getFormElement("label1").style.color = "red"; // Make the Tax ID label red.
                    alert( "Tax ID is a required field." );        // Tell the user it's required.
                } else {
                    lawForm.getFormElement("label1").style.color = "green";  // The user entered something so reset the label color.
                }
            }

            If you'd rather do the validation when the user clicks an action button you would place this code in the FORM_OnBeforeTransaction(fc) function:

                lawForm.getFormElement("label1").style.color = "green";  // Reset the label color before we do our validation.

                if ( lawForm.getFormValue("text1") == "" ) {  // The user didn't enter anything.
                    lawForm.getFormElement("label1").style.color = "red"; // Make the Tax ID label red.
                    alert( "Tax ID is a required field." );        // Tell the user it's required.
                    return false;  // Stop further processing until the user fixes this error.
                }

            Now, if you want to check the value of a field on an Inquire you would do that in the FORM_OnAfterTransaction(data) function.  That is the function that fires after a transaction (such as inquiry) completes.  In this case you are looking at the data that comes back to the screen; not what the user has entered so you'll need to look at the data values rather than the form values.  For example:

                if (lawForm.getDataValue("VEN-TAX-ID" == "") {
                    lawForm.getFormElement("label1").style.color = "red"; // Make the Tax ID label red.
                }

            You can't really stop processing so you'll have to rely on the fact that the lable is red to inform your user that he or she needs to do something with that field.

            Hope that helps!

            wilcoxmad
            Veteran Member
            Posts: 87
            Veteran Member
              Wow, thank you Randy! That was super helpful.

              I'll go give that a try!

              wilcoxmad
              Veteran Member
              Posts: 87
              Veteran Member
                Thanks again Randy.

                My field occurs so here is what I did, first occurance only:

                function FORM_OnAfterTransaction(data)
                {
                var vStatus0 = lawForm.getDataValue("QIC-STATUS",0);
                if (vStatus0 == "3")
                {
                // Make the Status red.
                lawForm.getFormElement("out10",0).style.color = "red"; //change the number red
                lawForm.getFormElement("select1",0).style.color = "red"; //change the desc red
                }
                }
                Randy Jacoy
                Veteran Member
                Posts: 46
                Veteran Member
                  Looks great.  Remember to change the fields back to their default color in the FORM_OnBeforeTransaction(fc) function so when the next transaction is invoked you are starting with "normal" label and field colors.
                  Lynne
                  Veteran Member
                  Posts: 122
                  Veteran Member
                    This has been very helpful to me also, Randy. Thanks for the detailed instruction. Can you tell me if this is where I'd put a query to pull a field that's not currently on my form? I would like the req# to display in the line detail section of PO20, but it is not available as a data source. I'm not sure what I would use to trigger it because whenever they click on another detail line of the section, I'd have to query again. Any guidance is appreciated.
                    Randy Jacoy
                    Veteran Member
                    Posts: 46
                    Veteran Member
                      PO20 is not a form we use so I can't give you specifics but in general, if the field is not one of the data fields passed to your form you either need to add it to the back end COBOL that feeds your form or you need to do a DME call to retreive the information. 

                      Is the req# something that you would display on every line in the detail section?  If so you would add your new req# field to the detail line and then make a DME call in the FORM_OnAfterTransaction(data) function for each detail line.  If you had 5 detail lines for example you could loop through them using something like:

                        var myREQNbrReturnValue = "";
                        var myDMEInputField = "";

                        for (i = 0; i <= 4; i++)
                        {
                          // This line gets a value from the detail line.  I assume you would get the req# field
                          // based on information contained in the detail line.
                          myDMEInputField = lawForm.getDataValue("MY_EXISTING_DETAIL_LINE_FIELD",i);

                          // Then do the DME call here using the value in myDMEInputField as input.  getReqNumber
                          // is a function name I made up that would contain the DME call that returns your request number.
                          myREQNbrReturnValue = getReqNumber(myDMEInputField ;

                          // Once you have the return value from your DME call, place it in the field you added to
                          // to the detail lline.  In the line below, "text7" is the text box you added to the detail line to
                          // hold the Req#.
                          lawForm.setFormValue("text7",myREQNbrReturnValue,i);
                        }

                      If you only want to retrieve the req# when the user clicks on a detail line you'll have to tie it to an event such as when they leave a text field in the detail line.  The TEXT_OnBlur(id, row) function will have a value in the "row" variable if the text box is in a repeatable section such as a Detail Area.  So if the field you were using to trigger the DME call was "text2", you would obtain the value of the field for that line using lawForm.getFormValue("text2",row);

                      Lynne
                      Veteran Member
                      Posts: 122
                      Veteran Member
                        Thank you, Randy. It is the last scenario that is what I need to do. I have a detail line section and then below that a detail area. As you click on different lines, the fields in the detai area change values to correspond to whatever line you're on in the detail line section. I want the req# for the line to display in the detail area. It could be different for different lines, so it should change correspondingly as you move through the lines in the detail line section.

                        So, to make sure I understand the row logic, I started with just pulling a data value from the line detail to display in the detail section when I switch lines. The problem is that it seems to be off by one line as to the data that it ends up populating. For example, if I click on line 2, it displays line 3's value. Line 3 displays line 4 etc. It also sometimes reverses and when I click on line 2, it will display line 1 etc. Here is my code. Could you take a look at it and see if you know what the problem could be? Thank you very much!

                        function TEXT_OnBlur(id, row)
                        {
                        var vReq = lawForm.getDataValue("PLI-QUANTITY",row); //retrieve the quantity from detail line
                        lawForm.setFormValue("text37",vReq,row); // put the quantity from line detail in new field text37 of detail section
                        return true;
                        }
                        Randy Jacoy
                        Veteran Member
                        Posts: 46
                        Veteran Member
                          The first thing I noticed is that your code is executing every time you leave any text field.  You need to surround your logic with a test so it only fires when you leave a specific text box.  For example, the code below will only fire when you leave the text37 field.

                          function TEXT_OnBlur(id, row)

                              if (id=="text37") {
                                  
                          alert("Row number is " + row);
                                  var vReq = lawForm.getDataValue("PLI-QUANTITY",row); //retrieve the quantity from detail line 
                                  lawForm.setFormValue("text37",vReq,row); // put the quantity from line detail in new field text37 of detail section 
                                  return true; 
                              }
                          }

                          When you leave text37, the value of "row" is going to represent whichever row you are leaving; not the row you are going to.  So, if your cursor is in a text box in the first row and you click anywere else on your page, the value of "row" will be 0.  (The rows indexes are zero based so the first row is row 0, the second is row 1 and so on).  Does that help any?  I added an Alert to the above code so you can see what I mean.
                          Lynne
                          Veteran Member
                          Posts: 122
                          Veteran Member
                            That helps a whole lot. I think I'm on the right path now. Thank you so much for taking the time to help.

                            I just thought of one more question- I want it to fire whenever I leave any field in the detal line section. I didn't know how to refer to those fields because they are occuring lines. Would I have to reference them for each line like ("text12",0) ("text12",1)... or can you just use "text12" and it would work no matter what line you're on in the section for "text12".

                            Randy Jacoy
                            Veteran Member
                            Posts: 46
                            Veteran Member
                              I'm glad I could help.

                              You wouldn't have to reference the fields for each line,  If you code your test as if (id=="text12") it will fire any time the user leaves a text12 field in the detail area regardless of row.  As discussed earlier, Lawson provides you with the row value so you'll know which row the user was in.  If you code that Alert I gave in the last example you'll see what I mean.
                              wilcoxmad
                              Veteran Member
                              Posts: 87
                              Veteran Member
                                Randy,

                                I am having a wierd result. I had already addressed the "reset the color issue" before I saw your suggestion. I did change my code to use the loop you showed above, made the code much shorter. Anyway, the issue is that the first occurance is not turning red. All the others work fine! Any suggestions?
                                Thanks, Mark.

                                function FORM_OnAfterTransaction(data)
                                {
                                for (i = 0; i <= 14; i++)
                                {
                                var vStatus = lawForm.getDataValue("QIC-STATUS",i);
                                if (vStatus == "3")
                                {
                                // Make the Status red.
                                lawForm.getFormElement("out10",i).style.color = "red"; // set the status desc to red
                                lawForm.getFormElement("select1",i).style.color = "red"; // set the status number to red
                                }
                                else
                                {
                                lawForm.getFormElement("out10",i).style.color = "blue";
                                lawForm.getFormElement("select1",i).style.color = "black";
                                };
                                }
                                }
                                Randy Jacoy
                                Veteran Member
                                Posts: 46
                                Veteran Member
                                  The first thing I would do is add an alert after you populate vStatus to ensure vStatus truely contains a "3" and nothing else (like an extraneous space).  The alert should display the value in quotes so you can see if there is a space such as

                                  alert("vStatus " + i + " contains '" + vStatus + "'");

                                  That will display the value surrounded by single quotes.

                                  I also notice you have an extraneous semicolon after your if-else closing brace.  Probably nothing but it would be best to remove it.

                                  Are the first occurance of out10 and select1 changing to blue and black respectively or are they not changing period?

                                  If everything checks out OK, make sure you are not resetting the color for those fields elsewhere in your code.
                                  wilcoxmad
                                  Veteran Member
                                  Posts: 87
                                  Veteran Member
                                    Thanks Randy!

                                    I can't explain what was happening but I added a second check of just occurance 0, after the other loop, and only changed the color to red, not back to black and blue and it works! So I will leave well enough alone.

                                    I cannot thank you enough for all your help on this.