Easy task i though, but it was actually more difficult that first suspected.
Not that the code is that complicated, but it's undocumented and in my opinion not very logic.
So i decided to share the solution i ended up with. Hope this might help some of you guys :-) Comments are as always very welcome. And if you have a better/easier way of doing it, i'm very interested in hearing about it.
There are easy work arounds for it. Using entity framework go Linq2Sql you can get the automation state ID very easy using this SQL query :
Select AutomationStateId from AutomationStates where AutomationId = (Select AutomationId from Automations where AutomationName = 'name of ECM email') and UserName = 'Emailcampaign\lasse@domain.com'
But i really wanted to avoid implementing custom data access to the analytics database, so i looked into using the analytics api to accomplice it.
The first solution that i found was simple enough.
Using the following code snippet you can indeed the the automation state id.
var dataTable = new VisitorDataSet.AutomationStatesDataTable();
AutomationManager.Provider.GetVisitorAutomationStates(dataTable, "Emailcampaign\\lasse@domain.com");
After that, you can loop through the collection and get the Automation state IDs.
foreach (var automationStatesRow in dataTable)
{
var state = automationStatesRow.AutomationStateId;
}
The problem for me in using this approach, was that i did not know the automationid for the engagement plan. The only two values i had was the name of the ECM email and the user account (email).
So that approach did not really solve my problem.
Strange that sitecore did not provide an overload for the AutomationManger.Provider.GetVisitorAutomationStates, that could limit it to a specific ECM email by name, but that is just the way it is.
The solution is to take a slightly different approach :
var dataTable = new VisitorDataSet.AutomationStatesDataTable();
AutomationManager.Provider.GetVisitorAutomationStates(dataTable, "Emailcampaign\\lasse@domain.com");
var itm = Sitecore.Configuration.Factory.GetDatabase("master").GetItem(new ID("{CH91BEE6-871F-13B6-AE58-53F9C8F74A58}")); // Could also be the path to the message item.
var message = ABTestMessage.FromItem(itm);
var i = new EngagementPlanItem (AnalyticsHelper.GetMessagePlan(message));
var statesList = dataTable.Where(s => s.AutomationId == i.ID.Guid);
statesList should contain only one entry, from witch you can extract the automation state ID as GUID.
That's it for now. Happy sitecore coding everyone.
Best
Lasse Rasch
That's it for now. Happy sitecore coding everyone.
Best
Lasse Rasch
Ingen kommentarer:
Send en kommentar