Insert query in internal entity

Insert query in internal entity

  

Hi, i want to ask how to make custom query, in this case i have entity 'A', i want when i insert the data to entitiy 'A' in entitiy 'B' inserting the entitiy 'A' primary key. Please help me, thanks in advance :) 

my query :

SyntaxEditor Code Snippet

insert into {gatePass} ,{approval_tbl} values {gatePass}.[Id],{approval_tbl}.[Id]

Hi Ami,

I don't fully understand your question, but I think you want want to do following :
- Insert data in 'Entity_A' then
- Insert data in 'Entity_B' with 'Entity_A' primary key

To achieve this, you need to first insert your record inside 'Entity_A'.
Once you will insert record in 'Entity_A', you can get its last inserted Primary_Key using following command:

Scope_Identity()

This value will be your Primary_Key of 'Entity_A', which you can now use in your 'Entity_B'

Example: 

INSERT INTO dbo.Entity_A ([Name], Email, Phone) 
VALUES (@Name,@Email,@Phone)    

SET @CustomerID = CAST(SCOPE_IDENTITY() AS INT)

INSERT INTO dbo.Entity_B (Address,Entity_A_ID) 
VALUES (@Address,@CustomerID)    

You need to change the syntax according to OutSystems format.

Let me know if you want any more information on this.

Regards,
Palak Patel

Palak Patel wrote:

Hi Ami,

I don't fully understand your question, but I think you want want to do following :
- Insert data in 'Entity_A' then
- Insert data in 'Entity_B' with 'Entity_A' primary key

To achieve this, you need to first insert your record inside 'Entity_A'.
Once you will insert record in 'Entity_A', you can get its last inserted Primary_Key using following command:

Scope_Identity()

This value will be your Primary_Key of 'Entity_A', which you can now use in your 'Entity_B'

Example: 

INSERT INTO dbo.Entity_A ([Name], Email, Phone) 
VALUES (@Name,@Email,@Phone)    

SET @CustomerID = CAST(SCOPE_IDENTITY() AS INT)

INSERT INTO dbo.Entity_B (Address,Entity_A_ID) 
VALUES (@Address,@CustomerID)    

You need to change the syntax according to OutSystems format.

Let me know if you want any more information on this.

Regards,
Palak Patel

i've made like this but it still doesn't work for me
my query :

SyntaxEditor Code Snippet

insert into {gatePass}({gatePass}.[DescGood]) values (@In1) set {gatePass}.[Id]= CAST(SCOPE_IDENTITY() as int) insert into {approval_tbl}({approval_tbl}.[Id]) values ({gatePass}.[Id])


Hello Guys,


Please don't forget that Outsystems is a low-code platform, and you shouldn't be writing SQL in that way.


So my suggestion would be that you use standard platform actions instead of advance queries to insert data into the tables.


Regards,

Davide Periquito wrote:

Hello Guys,


Please don't forget that Outsystems is a low-code platform, and you shouldn't be writing SQL in that way.


So my suggestion would be that you use standard platform actions instead of advance queries to insert data into the tables.


Regards,

yes, but i don't get the logic so i have to use that way. do u have any suggestion for me so i can complete my task bcs i need that, thanks in advance :)


Hi All,


Yes as we are using low code platform,


Please use entity action and it will return the identifier inserted in entity which u can used for other entity to store same identifier.


Thanks!

I don't know you goal there.


But take a look into the the actions provided by the tables 

Solution

Please check attached oml

Solution

and mark as solution this POST.

JitendraYadav wrote:

and mark as solution this POST.

thanks and now i understand :)


Thanks Ami.