How do I update one record and then create a new one automatically?

How do I update one record and then create a new one automatically?

  
Hello,
I am creating my first Outsystems app and am having a problem. I hope someone can help me.  I have EntityA which has related entries in EntityB.  I have created screens to create the first EntityA and display it, add related EntityB records, and display them on the same screen.  However, when the EntityA record gets to the point where it has 4 EntityB records, I need to change its state to Closed (an attribute) and create a new EntityA record with State=Current (an attribute).  So far I have trapped the fact that there are 4 EntityB entries and activated a button that executes a screen action to do the Close and Create New action.  I would like to do this without opening a new screen and requiring user input if possible. 

Currently the Close and Create New  screen action flow is:
     Start
     Assign (Closure data values to Current EntityA)
    Create or Update EntityA (this marks the current record as Closed and no longer Current)
    Refresh Query GetCurrentEntityA  (Queries for a record marked “Current” which should not exist)
    If (EntityA=Current, End, Create EntityA)
    Assign New Start Date (to the newly created EntityA record - this date is determined a value in the previous record)
    Create or Update EntityA (with new Start Date)
    (Current Screen)

It seems to work through the steps to change the values in the existing EntityA record, but not to create the new one.
I suspect my problem is with how I have defined the source for the CreateRecord action, but I am not sure how to make it be what it needs to be.
I appreciate any help or any suggestions for better ways to accomplish this.

Thanks in advance,
Carlene Neeley
Hello Carlene,

Regardless of your screen logic, when you use the "Create or Update EntityA (with new Start Date)" you will only get a new record if you have the Id = NullIdentifier().

So you dont need to use the "Create EntityA" and then "Create or Update". What you need is to get the id = NullIdentifier() in order to create a new record.

Also, when you use "Create EntityA" it will return the id of the newly created record. You need to use this id in future "Create or Update" in order to update the new record.

Hope this helps.

Regards,

Nuno Cavalheira Antunes
Nuno,

Thank you so much.  Your comments pointed me to the right approach and that part of my app is now working as desired. 

Thanks again,
Carlene Neeley