I'm terribly sorry but after spending some time on the following code I just can't seem to extrapolate from existing examples to make it work... Any help would be greatly appreciated.
I'm authenticated, I have a node and its metadata - that's where it all falls apart for me. Much MUCH appreciated.
private void UpdateAttributeForNode(Node node, string lookupString)
{
// ignore parameter "lookupString" as it isn't being used yet.
Metadata md = node.Metadata;
AttributeGroup[] itemAttributes = md.AttributeGroups;
// Actual instance of category associated with item
AttributeGroup myCategory = Array.Find(itemAttributes, e => e.DisplayName.Equals("myCategory"));
// Get the value of myCategory ID to retrieve DB record
StringValue myAttributeID = (StringValue)Array.Find(myCategory.Values, o => o.Description.Equals("myCategory ID"));
log.Info(String.Format("Retrieving lookup row for myCategory ID: {0}", myAttributeID.Values[0].ToString()));
// lookup for what I need in my DataTable
DataRow[] myDataTable = dtPatentLookup.Select(String.Format("PatentID={0}",myUniqueID.Values[0]));
if (myDataTable.Length == 0 || myDataTable == null)
{
// ERROR no record or more than one record found... Log the appropriate issue with message
log.Error("No myCategory record or more than one record found");
log.Error(String.Format("Failed to update {0}. Case Number: {1}, myCategory ID: {2}", node.ID, lookupString, patentID.Values[0]));
return;
}
// Get instance for the rest of the attributes
// patentID already retrieved above
log.Info("Initiating all attribute values");
StringValue attribute1 = (StringValue)Array.Find(myCategory.Values, o => o.Description.Equals("Attribute 1"));
StringValue attribute2 = (StringValue)Array.Find(myCategory.Values, o => o.Description.Equals("Attribute 2"));
StringValue attribute3 = (StringValue)Array.Find(myCategory.Values, o => o.Description.Equals("Attribute 3"));
StringValue attribute4 = (StringValue)Array.Find(myCategory.Values, o => o.Description.Equals("Attribute 4"));
StringValue attribute5 = (StringValue)Array.Find(myCategory.Values, o => o.Description.Equals("Attribute 5"));
StringValue attribute6 = (StringValue)Array.Find(myCategory.Values, o => o.Description.Equals("Attribute 6"));
StringValue attribute7 = (StringValue)Array.Find(myCategory.Values, o => o.Description.Equals("Attribute 7"));
//attribute1.Values[0] = myDataTable[0][attribute1.Description].ToString();// I happen to have conveniently named the columns in my DataTable the same as my attribute names
attribute1.Values[0] = "Test Modified Value";
log.Info(myCategory.Values[0].Key[0].ToString());
// Take the input node and category and assign the new values.
log.Info(String.Format("About to update: {0}", node.ID));
docManClient.UpdateNode(ref otAuth, node);
log.Info(String.Format("Updated: {0} with myCategory ID: {1}", node.Name,myDataTable[0].ItemArray[0].ToString()));
}