DMXzone Server Connect Support Product Page

Answered

Saving new record ID after insert to use in another action

Asked 24 Jun 2016 14:54:35
1
has this question
24 Jun 2016 14:54:35 Steven Irwin posted:
I have an insert into a database that I then want to save the new record ID to then build another query.

I discovered through reading questions here that I could catch the returned inserted record ID using .identity

I did this with a database insert action named insertOrder and saved insertOrder.identity to a Global Session variable.

I then used the behaviour from the insert action to run another query (queryService) but found that the Global Session variable did not appear in the Globals for that action.

I tried using the same name as the original global session (insertID) but it didn't work.

There doesn't seem to be anything in the manual about saving returned record ID's and using them so I am a bit lost.

Can you point me to some documentation or describe how to pass a returned record ID from an insert action to a query action?

Replies

Replied 25 Jun 2016 00:03:23
25 Jun 2016 00:03:23 Steven Irwin replied:
Update - I tried adding the query after the insert in the same action file and can see that I can access the Global session variable now. Now I can't see how to setup the action executor to bind first the insert to a form and the query to a table. Will play some more but looking for assistance please.
Replied 25 Jun 2016 06:04:22
25 Jun 2016 06:04:22 Steven Irwin replied:
Update - I managed to get this working by setting a hidden form field for the ID from the returned identity and then reading the hidden field in the query as a filter from a Global GET.
Hope this helps someone.
Replied 27 Jun 2016 07:17:02
27 Jun 2016 07:17:02 Teodor Kuduschiev replied:
Hello Steven,

The inserted ID can be used as a step in the same server action, after the insert step and ou do not even need to create session for this. So in your server action file you need the following steps in this order:
- Database Connection
- Database Insert
- Query (filtered by inserted ID)
Replied 27 Jun 2016 12:09:44
27 Jun 2016 12:09:44 Steven Irwin replied:
Thanks Teodor
Replied 01 Dec 2016 11:51:45
01 Dec 2016 11:51:45 David Woolley replied:
Thanks for this tip Teodor! Works well for redirecting to another page with the GoToURL behavior that uses the new inserted ID from the query.

I noticed that the Insert Record Server Data Bindings has:
A - Identity
# - affected

in the tree.

What is the 'affected' used for?
Replied 01 Dec 2016 12:34:22
01 Dec 2016 12:34:22 Teodor Kuduschiev replied:
It returns 1 or 0 depending on if there was a record affected by the action.
Replied 01 Dec 2016 12:53:20
01 Dec 2016 12:53:20 David Woolley replied:
Thanks Teodor

Reply to this topic