1 Reply Latest reply on Aug 12, 2010 9:48 AM by John Cummins

    Automatically fill in field based on data from table rows

    snabbers

      hello,

      Users in our organization currently have to complete a number of different forms when an accident occurs. I am creating a .pdf that combines these fomrs into one, with the first portion being a data input section where the user inputs the data and then this populates other sections (pages of the form) that can later be saved and printed.

      The data input section contains subforms with tables. The tables have a row that has "add new item" and "delete this item" buttons.  The rows have dropdown list fields.

      I would like to create a field that will be automatically filled in with the values from the dropdown lists, including the values from the new rows that are added using the 'add new item' button.

      Any assistance in this regard would be most appreciated.  This is my first time on a forum, so I apologize if I have not been clear.

      Thank you.

        • 1. Re: Automatically fill in field based on data from table rows
          John Cummins

          This is pretty complicated. You'll have to use scripting for this and I'll tell you how I'd approach this with JavaScript.

           

          First of all you need to decide at what point you want to populate this field with the drop down selections. I think you have two options.

           

          Option 1 - Automatically calculate this field each time a user makes a drop-down selection. It's possible that a user will enter data and then change a drop down value so you'll have to account for this.

           

          Option 2 - Create an update button that users click to calculate this field. There is still a risk that users will change the value in the drop down after clicking update, so you would want to use scripting to lock those fields (e.g. make them protected) when the update button is clicked. You could then change the caption of this same button or have a second button that when clicked would unlock those drop down fields.

           

          The other thing you need to do is figure out how to calculate this field. It seems to me you would probably build a string together that mixes text with the drop-down values. So your JavaScript would look something like this:

           

          calculatedField.rawValue = "The accident occurred on " + table.row1.date.rawValue + ". It was witnessed by " + table.row1.witness1.rawValue +

                                                            " and " + table.row1.witness2.rawValue + ".";

           

          When you're in the LC Designer JavaScript editor, hold control for the relative path to those fields and control + shift for the absolute path and then click on the fields whose values you want to access.

           

          I hope this points you in the right direction!