Hi,
I'm working on Activities right now and I created my own activity.
I wanted to insert a New Activity with a press of a button which is located in the MainHeader. Question, what's the best way to insert my own activity?
I am currently trying to insert it via custom web service through
Insert insert = new Insert(UserConnection) .Set("","") .Into("Activity")
I'm afraid there are events, computations that won't be triggered.
Any comments?
Like
Solem Khan Abdusalam,
After you call activity.Save() you can get the created record Id using
// get primary Id value var id = activity.PrimaryColumnValue; // or get any of the column values using var title = activity.GetTypedColumnValue<string>("Title"); var start = activity.GetTypedColumnValue<DateTime>("StartDate"); // etc
Ryan
Using the Insert class does not trigger process events, etc. Instead, you can use the Entity class. Something like this:
var schema = UserConnection.EntitySchemaManager.GetInstanceByName("Activity"); // Create a new Activity object var activity = schema.CreateEntity(UserConnection); // Set any any default column values activity.SetDefColumnValues(); // Now set the column values as needed activity.SetColumnValue("Title", "This is a new activity"); activity.SetColumnValue("StartDate", DateTime.Now); // etc // Save when done activity.Save();
Hope this helps.
Ryan
Solem Khan Abdusalam,
One of possible ways is to create a SELECT query to the database using or the script task process element (if you are going to use a business process) or in the custom web service that is triggered upon clicking the button and select the last created activity (top 1 and ORDER BY CreatedOn conditions). Also the created activity can have some marker in its subject (like "created via web service" or so) that could be used in the filtering condition as well.
Insert query you've proposed won't return an Id of the record, but you can select it once the record is created.
Best regards,
Oscar
Solem Khan Abdusalam,
After you call activity.Save() you can get the created record Id using
// get primary Id value var id = activity.PrimaryColumnValue; // or get any of the column values using var title = activity.GetTypedColumnValue<string>("Title"); var start = activity.GetTypedColumnValue<DateTime>("StartDate"); // etc
Ryan
Is there any way to trigger the Creatio processes that happen when using the Entity class to insert data when using something like the Insert class/other operations that happen on the database more directly?
We have a need to do some atomic data operations in the table (create a record where it doesn't already exist, and with a high chance of 2 processes attempting to do so at the same time) which would be much simpler/actually possible to implement in SQL, but we still want the Creatio processes to occur after the record has been created.
The problem with the Creatio data operations, definitely in BPs but also in C# as well, is that the data checks happen and then a record is created, but in the meantime another process may have already created the record, so you get 2+ processes trying to create the same record. We can make it fail with a unique index, but this will just break a BP instance (cause it to error out and not be recoverable) and isn't the most ideal way of doing things in general.
Harvey Adcock,
In this case, you can call the business process through C# code using the IProcessEngine Interface from the Terrasoft.Core.dll namespace
Example of starting a process without transferring parameter values:
UserConnection userConnection = Get<UserConnection>("UserConnection");
IProcessEngine processEngine = userConnection.ProcessEngine;
IProcessExecutor processExecutor = processEngine.ProcessExecutor;
processExecutor.Execute("UsrProcess2Custom1");
return true;
The relevant documentation can be found at this link - https://academy.creatio.com/api/netcoreapi/7.18.0/api/Terrasoft.Core.IProcessEngine.html
Or you can also make a GET call to the endpoint
0/ServiceModel/ProcessEngineService.svc
The corresponding documentation can be found at this link -
https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platfor…