I am trying to update the Target Groups conditions in the component presentations of a page using the Core Service. I am in SDL Tridion 2013 and here is the code I am using:
try
{
OpenSession(serviceInput.Server, serviceInput.User);
page = session.Read(context.PageUri, new ReadOptions()) as PageData;
if (page!=null)
{
page = session.CheckOut(context.PageUri, true, new ReadOptions()) as PageData;
List<TargetGroupConditionData> tgs = new List<TargetGroupConditionData>();
foreach (ComponentPresentationData cp in page.ComponentPresentations)
{
if (cp.Component.IdRef.Equals(context.ComponentUri) &&
cp.ComponentTemplate.IdRef.Equals(context.TemplateUri))
{
foreach (MobileTargetGroupInput input in groups)
{
TargetGroupConditionData data = new TargetGroupConditionData()
{
Negate = input.Negate,
TargetGroup = new LinkToTargetGroupData() {IdRef = input.Uri}
};
tgs.Add(data);
}
cp.Conditions = tgs.ToArray();
}
}
session.CheckIn(context.PageUri,true,string.Empty,null);
result.Success = true;
result.Message = String.Format("Page {0} updated.", context.PageUri);
}
return result;
}
catch (Exception ex)
{
result.Success = false;
result.Message = ex.Message;
return result;
}
finally
{
CloseSession();
}
The code does not fail at all, but the page in question, never gets updated. Can you guys help me out? I don't understand what I am missing.