I am trying to update Profile data through C#. But I don't see the values getting updated in the profile of the user, below is my code for updating values.
if (!Tracker.IsActive || Tracker.Current == null)
{
Tracker.StartTracking();
}
if (Tracker.Current == null)
{
return;
}
var scores = new Dictionary<string, double>();
var profile = Tracker.Current.Interaction.Profiles["Persona"];
scores.Add("Empowered", 6);
scores.Add("Guidance", 3);
profile.Score(scores);
profile.UpdatePattern();
When I am going to the experience profile, I cannot see those values getting reflected:
The values remains 11 and 9, no matter how many times I run the above code.
I added the following code to submit the scores to xConnect as below:
private void submitInteraction()
{
var anyIdentifier = Sitecore.Analytics.Tracker.Current.Contact.Identifiers.FirstOrDefault();
using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
{
var contact = client.Get<Sitecore.XConnect.Contact>(new IdentifiedContactReference(anyIdentifier.Source, anyIdentifier.Identifier), new Sitecore.XConnect.ContactExpandOptions());
if (contact != null)
{
var interaction = new Sitecore.XConnect.Interaction(contact, InteractionInitiator.Brand, Tracker.Current.Interaction.ChannelId, Tracker.Current.Interaction.UserAgent);
var profilescore = new ProfileScores();
profilescore.Scores.Add(new Guid("{B5BDEE45-C945-476F-9EE6-3B8A9255C17E}"), new ProfileScore() { MatchedPatternId = new Guid("{C5EA4A36-B2BF-4505-95EE-4C07CA72EA09}"), ProfileDefinitionId = new Guid("{B5BDEE45-C945-476F-9EE6-3B8A9255C17E}"), Score = 10, Values = new Dictionary<Guid, double>() { { new Guid("{D539DA39-C19F-4E0A-B144-1A5DD3364E68}"), 7 }, { new Guid("{2DEA2E60-8D89-4FB8-BB4C-CAD1369D4BB5}"), 3 } } });
client.SetProfileScores(interaction, profilescore);
//interaction.ProfileScores().Scores.Add(Guid.NewGuid(), new ProfileScore() { MatchedPatternId = new Guid("{C5EA4A36-B2BF-4505-95EE-4C07CA72EA09}"), ProfileDefinitionId = new Guid("{B5BDEE45-C945-476F-9EE6-3B8A9255C17E}"), Score = 10, Values = new Dictionary<Guid, double>() { { new Guid("{D539DA39-C19F-4E0A-B144-1A5DD3364E68}"), 7 }, { new Guid("{2DEA2E60-8D89-4FB8-BB4C-CAD1369D4BB5}"), 3 } } });
//client.AddInteraction(interaction);
client.Submit();
}
}
}
The above code is throwing following exception:
Exception: Sitecore.XConnect.Operations.FacetOperationException
Message: Operation #0, ReferenceNotFound, Interaction, ProfileScores
Source: Sitecore.Xdb.Common.Web
at Sitecore.Xdb.Common.Web.Synchronous.SynchronousExtensions.SuspendContextLock[TResult](Func`1 taskFactory)
at Sitecore.XConnect.Client.XConnectSynchronousExtensions.SuspendContextLock(Func`1 taskFactory)
at Sitecore.Foundation.XConnect.Repositories.XConnectRepository.submitInteraction() in C:\projects\BUSSQ\src\foundation\XDB\code\Repositories\XConnectRepository.cs:line 362
at Sitecore.Foundation.XConnect.Repositories.XConnectRepository.SetProfileCard(String personas) in C:\projects\BUSSQ\src\foundation\XDB\code\Repositories\XConnectRepository.cs:line 345
at BUSSQ.Website.Repositories.SliderComponentRepository.SetProfileCard(String personas) in C:\projects\BUSSQ\src\Project\BUSSQ\code\Repositories\SliderComponentRepository.cs:line 39
at BUSSQ.Website.Controllers.SliderController.setProfile(SliderFormat sliderValue) in C:\projects\BUSSQ\src\Project\BUSSQ\code\Controllers\SliderController.cs:line 64
at System.Web.Mvc.ActionMethodDispatcher.<>c__DisplayClass1.<WrapVoidAction>b__0(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
HttpContext.Current.Session.Abandon();
. Note that you should not use the mention code on production. Only use this for testing purposes