2 Replies Latest reply on Apr 4, 2011 12:47 PM by philmodjunk

    Creating Parent record from Child Table

    PremMahtani

      Title

      Creating Parent record from Child Table

      Post

      Please note the screenshot I have posed of my Relationships.

      I have a layout that allows the user to create a new record in the POS Receipt Header.

      When this record is created I want to automatically create a parent record in the Daily Sales Summary table and the Channel Daily Performance table if it does not already exist.

      I allow the creation of records in the parent table from the child table.

      However, the creation does happen.

      Do I have a flaw in my database design or am I doing something else wrong?

      FM_screenshot.jpg

        • 1. Re: Creating Parent record from Child Table
          bumper

          If you have both sides of the relationship set to create records then the only thing I can think of is the Header record being created first and is the ReceiptDate being populated with a date prior to trying to create a new record in the parent table. Otherwise FM has nothing to create the related record on the other side.

          Also the user has to actually enter some data in a field in the parent table to trigger the record creation, if not, then you will probably have to script the new record creation and cause it to run with a script or layout trigger.

          • 2. Re: Creating Parent record from Child Table
            philmodjunk

            "Allow creation of records via this relationahip" on the child table does not automatically create any records in the child table. It enables it to happen in certain narrow circumstances. If you have a portal to that table, you can enter data in the bottom blank portal row and a new related record is automatically created. If you place a field to that child table on the parent layout and no related record already exists, a related record will then be created when data is entered into this related field.

            From a layout for POS Receipt Header, this script would create a new record in POS Receipt Header and a new related record in the two parent tables if such a related record does not already exist:

            Freeze Window
            New Record/Request   //creates new POS Receipt Header
            Go to layout [Channel daily performance]
            New Record/Request //creates new Channel daily performance record
            Set Variable [$CDPid ; value: Channel Daily Performance::_pk_date_plus_channel]
            Go To layout [POS Receipt Header]
            Set Field [POS Receipt Header::_sk_Date_plus_Channel ; $CDPid]
            Go To layout [Daily Sales Summary]
            New Record/Request  //creates new Daily Sales Summary record
            Set Variable [$DSSid ; value: Daily Sales Summary::_pk_Date ]
            Go To layout [POS Receipt Header]
            Set Field [POS Receipt Header::_sk_ReceiptDate ; $DSSid]