I came to the page looking for an answer, but found that all answers use a static field name or some other approach that is very limited.
So, finally do my own restart, and this is how I form the name of the workflow field
string WFColumnName = string.Empty; foreach (SPWorkflowAssociation assoc_wf in ReqList.WorkflowAssociations) { if (assoc_wf.BaseTemplate.Id.ToString() == "63e32cd3-2002-4b2f-81b0-4a2b4c3ccafa") { string str_workflowName = assoc_wf.Name; Regex rgx = new Regex("[^a-zA-Z0-9]"); str_workflowName = rgx.Replace(str_workflowName, ""); if (str_workflowName.Trim().Length >= 8) WFColumnName = str_workflowName.Substring(0, 8); else WFColumnName = str_workflowName.Substring(0, str_workflowName.Length); break; } }
The column name is formed based on this (the name is misleading, but it's just the column name): How to get the status of a SharePoint workflow for each SP element using a PowerShell script?
and then i use it in my caml request
if(WFColumnName != string.Empty) viewFields += "<FieldRef Name='" + WFColumnName + "' />";
and in my case, I just need to check if it is complete or not, so I get the string value and compare it with "5".
user669915
source share