Local Variable and Form Record ID is reinitialized

On a traditional web, I have a screen (a popup if it matters) and has two buttons Save (Ajax Submit, Client & Server) and Print (Submit, Server).

Both Save and Print action both do a RecordCreateOrUpdate although the latter action does the extra print to PDF functionality.

In between the RecordCreateOrUpdate and Print functionality I assign the variable back to the form. RecordCreateOrUpdate's parameter is the form record.

The problem is when you try to click the print button twice or more, the form record's Id is always 0 or null entering this action. The idea is to only generate one record (printed document) only. And since parameter Id is 0, it creates multiple records.

Options tried:

- Used a local variable for the same purpose but it doesn't retain the value. Entering the action, it is back to 0 or null. I was assuming that the variable keeps the value but then it was somehow reinitialized.

- Used an aggregate or refresh aggregate but it doesn't pick up the new record created by the CreateOrUpdate, meaning the aggregate return empty

- Changed the buttons' method and validation to test but same behavior

Hi Juan.

Can you show the Assign, please?

You say you changed from Submit to Ajax Submit and the problem persists?
Are you getting any exception? This would rollback the transaction.
When debugging, the action returns a valid Id?
And after the assign, the Form has the ID in it? Does the form has multiple entities (sometimes we assign to the wrong one).


P.S. What do you have in the preparation? The submit will execute the preparation again.

Hi Eduardo,

I actually fixed the issue, however I still don't know how my change fixed this. To your question below is the assign:

PatientProcedureNoteId and AddPatientProcedureNote.Record.Id goes null when you trigger the action again. I guess that is because "the submit will execute preparation again". When we say it executes again, will it be hit by debug? I actually have a breakpoint in the Start in debug but it wasn't hit. And what do you need to do so that a local variable will keep its value as long as the screen is up?

The fix:

For this one, I believe I tried assigning the record result of the Refresh Aggregate but I ended up having a record with a Id field with null value. Again, I am not sure why this one worked.

I am sorry if this doesn't make sense because I myself doesn't know what happens behind the scenes that is why I can't explain it very well.

Hi Juan

If you submit (with Submit method), the preparation will be executed again IF you finish the action being executed with an END node.

For what I am seeing in the FIRST image, you are assign to the FORM record the ACTUAL value of the Aggregate (from preparation, I assume).
Assigning to the form is correct, as it will not be updated (not even if the preparation runs again), but you are doing this with a record (from the aggregate) that initially is "empty". 

So, my suggestion. Remove the "new" assign (and the refresh), and change your Assign (after the create or update server action) with this:

1. AddPatientProcedureNote.Record.PatientProcedureNote.Id
= PatientProcedureNote_CreateOrUpdate.ProcedureNoteId
2. ProcedureNoteId
= PatientProcedureNote_CreateOrUpdate.ProcedureNoteId
3. URL
= whatever you are putting there

This way, the ID will be placed in the Form (that will NOT loose the other data that is there, even if you are using Submit and ending with an END node.

And don't use the aggregate from the preparation to anything else than initialize the Form in the preparation.

This should solve your issue in the "right" way. :)

Hi Eduardo,

Unfortunately, it didn't work for me

Initial Run at Start: As expected no values

Initial Run at Assignment: As expected it got the ID of the CreateOrUpdate function

Second Run at Start: Variables are "reinitialized"

Second Run at Assignment: It created a new record because of the null Id

I really wanted to solve this the right way but it won't allow me to do so. Lol.

Hum... This does not make any sense.

If you are setting the values of the local variable AND the Form ID after creating the record, and are not changing them later on, they should keep the value.

Let me ask a couple things. 

1. You are not "leaving" the popup, right? (is this a popup?)
2. Is this being executed with Submit?

Can you provide a working module (no dependencies) that reproduces the behavior?

I'll try to do some tests here. 


So, I have this small example (attached).

It works as expected. I have a form being filled when the popup is open by the aggregate in the preparation. As I am passing NullIdentifier() to the input parameter, the aggregate is empty, so, the form is empty as well.

This means that when I press save and stay, it will create a new record. After creating a new record, I am updating both the input parameter (not really necessary here) and the ID in the FORM (that will be used by the create or update action to define if I am creating a new record or updating. 

So, every subsequent call to the save and stay will update the record.

I tested and it works as expected.

Can you tell what you are doing differently here?


It didn't really. I initially this ticket is a quick one but took me a while because of this. To answer your question:

1. I didn't leave the popup, just clicked the button again that is on it.

2. The print button is a Submit.

It is not possible because it has a lot of dependencies. I guess I will have to leave it for now. If you are asking, I am not the one who started the module.

It's ok :)

If you have the chance, take a look into the module I provided. It's a basic one but it can cast some light over your problem. :)


I saw your example and I know that it is that easy to do it. Unfortunately, I don't know what this one isn't doing it. As per what's different, well, there is a lot. I don't want to break it some more just to insert a should be tiny change.

Thanks again for your time Eduardo!