AnsweredAssumed Answered

How do I update a WebLink field using the C# API Toolkit

Question asked by DanPoling1351581 on Feb 12, 2018

Does anyone know how to update a WebLink type field using the C# .Net API Toolkit?  I am trying the following code but it doesn't update the field - even though the code gets no errors.  Note, workItem is an HierarchicalRequirement. I am iterating through a query result. I have 3 Web Link fields, ParentFeature, ParentInitiative and ParentTheme that I am trying to populate.

 

DynamicJsonObject workItem = enumerator.Current;

DoubleObjID = workItem["ObjectID"];
ObjID = DoubleObjID.ToString();
NoUpdates = 1;
try
{
DynamicJsonObject parent = workItem["Feature"];
DynamicJsonObject updateTemplate = new DynamicJsonObject();
if(parent != null)
{
updateTemplate["c_ParentFeature.DisplayString"] = parent["_refObjectName"];
updateTemplate["c_ParentFeature.LinkID"] = parent["FormattedID"];
DynamicJsonObject parentObj = rallyAPI.GetByReference(parent["_ref"], "FormattedID", "Parent");
if (parentObj != null)
{
DynamicJsonObject initiative = parentObj["Parent"];
if (initiative != null)
{
updateTemplate["c_ParentInitiative.DisplayString"] = initiative["_refObjectName"];
updateTemplate["c_ParentInitiative.LinkID"] = initiative["FormattedID"];
parentObj = rallyAPI.GetByReference(initiative["_ref"], "FormattedID", "Parent");
if (parentObj != null)
{
DynamicJsonObject theme = parentObj["Parent"];
if(theme != null)
{
updateTemplate["c_ParentTheme.DisplayString"] = theme["_refObjectName"];
updateTemplate["c_ParentTheme.LinkID"] = theme["FormattedID"];

}
}
}
}
OperationResult updateResult = rallyAPI.Update(WorkItemType, ObjID, updateTemplate);
if (updateResult.Success == true)
{
WriteLog("Success", DateTime.Now, HierarchyField, workItem["FormattedID"], workItem["Project"]._refObjectName);
}
else
{
WriteLog("Error", DateTime.Now, "Update Failed", workItem["FormattedID"], workItem["Project"]._refObjectName);
}

}

}
catch (Exception Ex)
{
WriteLog("Fatal Error", DateTime.Now, Ex.ToString(), workItem["FormattedID"], workItem["Project"]._refObjectName);
throw new Exception("Fatal Error Encountered.");
}

Outcomes