JavaScript Substring

Sort:
You are not authorized to post a reply.
Author
Messages
Nabil
Veteran Member
Posts: 61
Veteran Member

    Can someone help me use JavaScript and the Substring function to show only the last 4 digits of the SSN in my form?

    Thank you

    Nabil
    Veteran Member
    Posts: 61
    Veteran Member
      I don't see this topic on the Design Studio
      Jay Riddle
      Veteran Member
      Posts: 191
      Veteran Member
        There are some excellent online tutorials on using javascript that can be found with google. If you want to jump straight into how substring works you can search with google for "javascript substring" and the first link is probably what you are looking for. For debugging you can add in alerts to your code to see what you are doing. For example

        alert('Hello World');


        John Henley
        Senior Member
        Posts: 3348
        Senior Member
          Assuming you're using the Form/UI Designer, you would do something like this in the FORM_OnAfterTransaction event:
          lawForm.getDataValue("FICA-NBR").substring(7,11)
          Thanks for using the LawsonGuru.com forums!
          John
          Nabil
          Veteran Member
          Posts: 61
          Veteran Member

            The textBox still does not show the last 4 only...it shows the whole field


            function FORM_OnAfterTransaction(data)
            {
            lawForm.getDataValue("text168").substring(7,11) ;
            alert('Hello');
            }

            David Williams
            Veteran Member
            Posts: 1127
            Veteran Member
              Parsing data - see my blog: http://consultdavidw.blog...07/parsing-data.html
              A great source for JavaScript is: http://www.w3schools.com/js/
              David Williams
              Jay Riddle
              Veteran Member
              Posts: 191
              Veteran Member

                The code John has just gets the four digits. Try something like this out and it will probably give you a better understanding.

                var str = lawForm.getDataValue("FICA-NBR").substring(7,11);
                alert('The four digits are ' + str);
                Jay Riddle
                Veteran Member
                Posts: 191
                Veteran Member

                  What you may want to do is:

                  1. Hide the original SSN field
                  2. Add in a new field.
                  3. Use substring to get the last four digits out of the hidden SSN field.
                  4. Put the last four digits into the new field.
                  John Henley
                  Senior Member
                  Posts: 3348
                  Senior Member
                    You would need to use lawForm.setFormValue or lawForm.setDataValue in order to actually make the form show that...something like (off the top of my head):
                    lawForm.setDataValue("FICA-NBR",lawForm.getDataValue("text168").substring(7,11))
                    Thanks for using the LawsonGuru.com forums!
                    John
                    Gary Davies
                    Veteran Member
                    Posts: 248
                    Veteran Member

                      I agree with Jay,  you do not want to use the setDataValue or setFormValue if the Change function is available because it will try to update the SSN with the truncated number.

                      It is better to create a new field and display the truncated value of the SSN number in it.

                      Nabil
                      Veteran Member
                      Posts: 61
                      Veteran Member
                        How can I put the last 4 in the field? I can get them in an alert but the text box is empty...


                        function FORM_OnAfterTransaction(data)
                        {
                        //var str = lawForm.getDataValue("EMP-FICA-NBR").substring(7,11);


                        str = lawForm.setDataValue("EMP-FICA-NBR",lawForm.getDataValue("text168").substring(7,11));
                        document.text168.value = str;


                        //alert('The four digits are ' + str);
                        }
                        Jay Riddle
                        Veteran Member
                        Posts: 191
                        Veteran Member

                          What I think Gary is saying is you probably don't want to use setDataValue on the original SSN field but instead use setDataValue on a new field that you have created.

                          Hopefully the syntax here close to being correct.

                          strFourDigitsOfSSN = lawForm.getDataValue("text168").substring(7,11));

                          alert('I got the four digits ' + strFourDigitsOfSSN);

                          lawform.SetDataValue("YOUR_NEW_FIELD_THAT_YOU_HAVE_CREATED"),strFourDigitsOfSSN);




                          Nabil
                          Veteran Member
                          Posts: 61
                          Veteran Member
                            I'm able to get the 4 digits in the alert box, but not in the textbox.

                            'lawform undefined.
                            Jay Riddle
                            Veteran Member
                            Posts: 191
                            Veteran Member
                              Javascript is case sensitive. It is probably 'lawForm' instead of 'lawform'. It looks like you are very new to programming in javascript. If you are interested in programming I would encourage you to continue. You may want to pick up a javascript book and read through it. Good Luck.
                              You are not authorized to post a reply.