Hi All,
We need to link an email (Send email manually) to an activity from the business process.
In the process element, we can not select the activity and fill in the parameter. It seems all the parameter is predefined in the process element (send email).
From the advanced mode we see that we can add piece of code in the function:
protected override void AfterActivitySaveScriptExecute(Entity activity)
However, after the element is executed this function is not triggered.
If you have the same experience, could you help us to make it work?
Thanks.
regards,
Cheng
Like
Hello Cheng,
The email that is generated from the business process in case this email is being sent manually is an activity itself and we can use this to bind it to another activity. It is way more easier to do using the following process rather than creating a code that could do it:
This is more relevant approach since you let the end user to select an activity to which the email should be connected (you can also add other conditions so to automatically bind the sent email to another activity, this process can be modifed in the way you need).
Best regards,
Oscar
Hi Oscar,
Thanks for the info. The solution will work technically , but on user level it is difficult to use that because:
1. Usually, activity will be a big list. Sometime, lots of fields have the same value. It is really difficult for users to do this manually.
2. The autogenerated page element will only be executed after the email is sent. Before that, the business process will remain on running (on the send email element).
Is there anyway we can get the created email Id right after the email (activity) is created in the database?
Cheng Gong,
Thank you for the clarifications!
As for the first point - it depends on the way activities are generated in the system. Yes subjects of activities can be similar and it would be difficult to select the correct one so we can use an automatization in the process using the "Read data" element and filters inside this element so to get the activity needed in our case (that should be connected to the email-activity). That's why I mentioned that the process can\should be modified.
As for the second point - that's also a good notice, in this case the user can select the activity directly in the list of activities in this field on the email page:
Or let the automated process to connect this email to the activity that the process selects (for example using the "Read data" process element).
You can get a created activity Id in the database directly for example by its creation date, subject of the email, sender of the email or other parameters and for example start another process that will apply needed connections to the email in case you don't need the activity to be connected to the email after the email is sent.
Best regards,
Oscar
Hi Oscar,
We can generate the name of activity, however, it still leaves the select to the user, and this might cause the email is linked to the wrong activity.
We know we can let user to select the connect to activity from the UI of the email. but again, same story as above. User can make mistake there.
You can get a created activity Id in the database directly for example by its creation date, subject of the email, sender of the email or other parameters and for example start another process that will apply needed connections to the email in case you don't need the activity to be connected to the email after the email is sent.
Yes, we can get it by using few field, but the certainty is not 100%. Also, if we connect the email and activity in another process, we will lose the original activity which triggered process.
Is there any way we can add custom code in the SendEmail element?
Cheng Gong,
Yes there is a possibility to add a custom code in the advanced settings of the element:
but the code will be executed after any changes to the email are applied and the record is saved, but not when it is created.
Best regards,
Oscar
Hi Oscar,
Thank you for the information and eventually the issue and solution is found.
Due to the local dev is still old version 7.12 and I am using file design mode, Visual Studio's stop point is not hit, but actually the function is fired. After I switch on the "Force Compile" option, it is working properly.
On the later version, the function is trigger right after the email activity is created by the element. I post the code in case anyone who need realize the same function (for example, connect the email to the custom section via process element).
var id = activity.PrimaryColumnValue; var userConnection = this.Get<UserConnection>("UserConnection"); Activity fromDb = new Activity(UserConnection); fromDb.FetchFromDB(id); Guid linkedActivityId = fromDb.ActivityConnectionId; var originalActivityId = this.Get<Guid>("UsrActivityId"); if (linkedActivityId == Guid.Empty && originalActivityId != Guid.Empty) { using (DBExecutor executor = UserConnection.EnsureDBConnection()) { Update updateActivity = (Update)new Update(userConnection, "Activity") .Set("ActivityConnectionId", Column.Parameter(originalActivityId)) .Where("Id").IsEqual(Column.Parameter(id)); updateActivity.Execute(executor); } }
Here "UsrActivityId" is process parameter's code for the activity which triggers the process.
Be careful with the update query, you would better not update any field which is in your process trigger.
Cheng Gong,
Fantastic! Good job and thank you for sharing the code!
Best regards,
Oscar