I'm having trouble with a simple function in c# to update a workflow's form field. Below is the syntax I used that is hacked from the thread located here.
It looks like I'm not getting any form data back from the work package, and my "foreach" statement is crashing out since fdList is empty, but the error I'm getting is "Object reference not set to an instance of an object." (error attached). I'm not familar with the syntax and was just wondering what I was doing wrong?
public static void updateWFForm(OTAuthentication otAuth, ProcessInstance ProcessInt)
{
WorkflowServiceClient wfsc = new WorkflowServiceClient();
ApplicationData[] wfData;
wfData = wfsc.GetWorkItemData(ref otAuth, ProcessInt.ProcessID, ProcessInt.ProcessID, 1);
FormData wfFormData = new FormData();
wfFormData = ((FormData)(wfData[3]));
FormDataInstance[] fdList = wfFormData.Forms;
foreach (FormDataInstance f in fdList)
{
AttributeGroupDefinition agd = new AttributeGroupDefinition();
agd = f.Data;
for (int i = 0; i <= agd.Attributes.Length; i++)
{
if (agd.Attributes[i].Type == "String")
{
StringAttribute sAttr = (StringAttribute)agd.Attributes[i];
if (sAttr.Values != null)
{
Console.WriteLine("Attribute: " + sAttr.Values[0]);
}
sAttr.Values[0] = "Test Engagement"; //Error here as value is null.
}
Console.WriteLine("Attributes:");
Console.WriteLine(agd.Attributes[i].DisplayName + " - " + agd.Attributes[i].GetType());
}
return;
}
}
