Skip to main content

Hi everybody,


I'm quite new in using K2 and so excuse me if this is a simple question.


I have an sql table that has a key of type Uniqueidentifier (Guid)


I've created a SmartObject that wraps that table, using the "SQL Server Service" as the ServiceObject.


Now there is a moment in my process where I need to invoke the Create method of this SmartObject and so I need to generate a new Guid and assign it to the corresponding property.


I've already tried:


1) Creating a custom inline function that simply returns Guid.NewGuid() from .Net:


Gives an error: Object must implement IConvertible


2) Creating a custom inline function that returns Guid.NewGuid().ToString:


Can't continue designing because it states that the data types do not match


3) Create an sp that simply executes SELECT newid():


Also can't continue designing because of the data types.


 


I'm pretty sure there must be a simple solution, however I have not figured it out.



Can anybody please explain how do I generate a new Guid in my process when I need it?


 


Thanks in advance


 


Eduardo


 

Hi Eduardo,


The good news is that there is an easy way to do this - you do not need to write a custom inline function, since that is not really what inline functions are aimed at. 


You can use the Smart Object reference event in your process to call any smart object method (including create) and the results returned from that method call such as the primary key can then be assigned to a K2 data field that can be used in the rest of your process as an identifier to this record you created. 


Hope that helps


GLouw,


First of all, thanks for your answer.


However I may have not clearly stated my problem. What I need is to generate a GUID to invoke the Create method of the Smart Object. (as the create method will insert a row in a SQL table that has an uniqueidentifier column). Not use the returned results of a create call to obtain a GUID.


I've already found a workaround to make it work, I've done the following steps:


1) created a Data Field in the insert row activity, and named it GeneratedGuid


2) before the smart object event, i've inserted a server event (code) with the following code:


K2.ActivityInstanceDestination.DataFields["GeneratedGuid"].Value = Guid.NewGuid();


3) in the smart object event i associate the Data Field GeneratedGuid to the guid of the column (this is the step I was unable to perform with inline functions and all the other workarounds)


 


It would be nice however to have a GenerateGuid inline function as I have lots of Guids over my database...


 


Best regards,


Eduardo


Hi Eduardo,


Cool, I understand what you mean, that makes more sense. One of the guys in my office here had the same requirement to have an inline function to generate a GUID so he is busy working on that and will upload it to the K2 blackmarket when it is complete. In the mean time your solution is a good one. :-)


Cheers,


G


Reply