3 Replies Latest reply on May 7, 2012 10:54 AM by philmodjunk

    Script Commit file if fields have data.



      Script Commit file if fields have data.


      I am having a problem with a layout I created. It has 2 different tables involved.I am entering Tag information (Tag, Device, Manuf, Model, Serial) and I have location information (building room user etc.) Tag information and Location are linked by tblTag index. So when I enter all the information and got to the location information I get this error: This field cannot be modified until "__pkTagIndex" is given a valid value.

      I want to have a script that says if  tag, device manuf, serial have values commit the record. This way when I enter information and when I tab to the Location field the index record is already been created and the user doesnt have to hit save to enter location field. I do not what to auto commit, so that blank records are not created.

      But I dont understand were to place the script or how to write the script to work. I have tried but have been failing for the last couple of days now.

        • 1. Re: Script Commit file if fields have data.

          I don't think you need a script here and I think you should reconsider your auto-save settings. How is it that auto-save is going to result in a blank record? A validation rule on fields that must contain data can be used to catch cases where the user did not enter any data.

          That said,

          If [Not ( IsEmpty ( TagInfo::Tag ) or IsEmpty ( TagInfo::Device Manuf ) or ( TagInfo::Serial ) ) ]
             Commit Records [no dialog]
          End If

          Is the script that will commit the record only if the listed fields are not empty.

          • 2. Re: Script Commit file if fields have data.

            Well it is not a blank record but the index numbers are skipped if they are not committed. I maybe weird on it but would like to keep it so that I can tell if their are records deleted or am I just worrying for no reason?


            Where do I place this script? I would like to commit the record automatically after all fields are filed so that when a user goes to any of the other 10 fields for the location I do not get the " This field cannot be modified until __pkTagIndex is given a valid value."

            • 3. Re: Script Commit file if fields have data.

              Generally speaking, Primary Key serial numbers get gaps in their series all the time and it's no big deal. The exception to that are when the numbers are visible and represent actual financial transactions such as the number on an Invoice or Purchase Order. Financial auditors get real upset in those cases if you have a gap in the series.

              That error message indicates that you are trying to enter data into a related table when your primary key field is still empty--probably because you set it up with the "on commit" option in field options. You have two script triggers that you can experiment with: OnObjectExit--to be set on the fields in your layout's table. Or OnObjectEnter to be set on the fields where you are getting this error message. If you use OnObjectEnter, you may need to modify the script in order to get the focus into the correct field after committing the record.

              There are also ways you can use a related table and a script to generate a unique serial number "on demand". This can be an option that allows you to have an "on creation" serial number for your relationships, but also to have a second, "gap free" series of numbers for PO's, Invoices and the like in order to maintain proper "auditor friendly" control of your data.