Best Practice when inserting Activity

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 0

Like

4 comments
Best reply

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

Ryan Farley,



Is there a way to fetch the Id of the created Activity?

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

Show all comments