568
Views
10
Comments
Solved
Insert query in internal entity
Question

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]
2024-06-19 07-19-32
JitendraYadav
Solution

Please check attached oml

TableRecords.oml
2026-03-16 00-00-40
Palak Patel

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

UserImage.jpg
Rahmi

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])


2018-05-15 08-41-11
Davide Periquito

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,

UserImage.jpg
Rahmi

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 :)


2024-06-19 07-19-32
JitendraYadav

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!

2018-05-15 08-41-11
Davide Periquito

I don't know you goal there.


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

2024-06-19 07-19-32
JitendraYadav
Solution

Please check attached oml

TableRecords.oml
2024-06-19 07-19-32
JitendraYadav

and mark as solution this POST.

UserImage.jpg
Rahmi

JitendraYadav wrote:

and mark as solution this POST.

thanks and now i understand :)


2024-06-19 07-19-32
JitendraYadav

Thanks Ami.



Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.