SQL SmartObject: Insert or Update?


Badge +8

I want to use a SQL SmartObject  to create or update existing data in a process.  The SmartObject itself works as expected.


 


The SQL table has a primary key that doesn't have any relationship to the process instance, and the SmartObject Update doesn't work correctly unless I have the primary key value.


 


How do I implement logic in the workflow to 1) check for an existing PK value, then 2) insert or update based on that value?


10 replies

Badge +6

Hi,


 


Have you tried setting the primary key to a property with an Auto-Number type? This would automatically generate a new unique value for each record.


 


Regards,

Badge +6

Hi,


 


I have not received any feedback regarding this post. Have you managed to work through the issue? A status update would be highly appreciated.


 


Thanks

Badge +3

Hello,

 

 

I try to update data from product table that already created by other system. The tables have relation as follow :

 

12661i00C5D626C2ED402E.png

What best practice to create the smartObject to cover CRUD and List method for product table that have SupplierName field?

 

 

Best Regards,

 

Hasyim

 

 

 

Badge +6

Hi Nur,


 


I would suggest creating SmartObjects with associations if you have not done so already. 


 


Have a look at the following guide on how to create a Composite SmartObject: http://help.k2.com/kb001304.


 


Regards,

Badge +3

 

Thanks Taariq for the response,

 


Could you please tell me how to get index from selected Radio Button?

So, when we chose an option and hit the update/create button the SupplierId will be filled with index instead of name.

 

15885i8386B0FBCE326926.png

 

Or could you please give me step by step to use Associated Smart Object correctly?

Please notice that the Supplier dan Product SmartObject already associated due to both created with SmartObject Tester Utility.

 

 

Many Thanks,

 

Hasyim

Badge +6

Hi, 


 


The drop-down list must be configured to display the SupplierID instead of the name when the datasource is configured. Currently the name is most likely selected that's why the name is being displayed. Run through the datasource configuration again to confirm this. 


 


An associated SmartObject follows the same principal of using Primary and Foriegn Keys. Has the guide I provided you with not suffiecient enough? I am unsure of whether associated SmartObjects can be created via the SmartObject Tester Tool.


 


Regards.

Badge +3

Your explanation is good enough, but I still can't found solution to Insert/ Update in related table.

 

The problem is when we use the ID, it will be not a user friendly UI due to in some case we use GUID format for security reason. When we use both Id and Name it also not good way to give user unused informations.

 

For Assiciated SmartObject, I just create a relational table first and generate smartObject from the "Table" folder, it automaticaly generate associated smartObject. But I don't know how to use it in my case.

 

Thanks,

 

 

Badge +6

Hi, 


 


Let's say you had two SmartObjects - SO1=Order and S02=Product.


 


Order contains the following properties:


-Order_ID


-Prod_ID


-Quantity


-Total


 


Product contains the following properties:


-Prod_ID


-Description


-UnitCost


 


In this case a many to many association would be used as multiple Orders can contain multiple Products. In this case the SmartObjects would be associated via the 'Prod_ID' property. 


 


In your case of using a Supplier and a Product SmartObject.


 


The following can be done:


 


Supplier:


-Supplier_ID


-Supplier_Name


 


Product:


-Prod_ID


-Supplier_ID


-Name


-Price 


-Qty


 


And these two SmartObjects would be associated using Supplier_ID.


 


When a new product is added - it would need to reference an existing Supplier.


 


I hope this provides more clarity.


 


Best Regards,

Badge +3

 

Thanks for your help,

 

 

I just found what I want in this configuration step. Thx.

 

11310i9CAD40A8EB1A1E9B.png

 

 

Best Regards,

 

Hasyim

 

 

Badge +6

Hi Hasyim,


 


Glad to hear that you managed to get through this issue. In future please remember to mark the appropriate post that helped resolve this issue as the solution.


 


Best Regards,

Reply