Attach approval workflow to a sharepoint library using CSOM c# -
i trying attach approval workflow through csom c#, getting exception saying 'value null' have debugged code , can see no values null, below code using
public void attachworkflow(clientcontext context, string listname, string workflowtemplatename, string workflowname, bool allowmanual, bool autostartonchange, bool autostartonnew, string tasklistname, string historylistname, string tasklisttemplate, string historylisttemplate, string[] approvers, bool expandgroup, string notification) { list list = context.web.lists.getbytitle(listname); context.load(list); context.executequery(); workflowtemplate wft = context.web.workflowtemplates.getbyname(workflowtemplatename); list tasklist = null; list historylist = null; string approver = ""; string associationdata = ""; principal prp = null; foreach (var app in approvers) { prp = trygetuserorgroup(context, app); if (prp != null) { approver = approver + "<pc:person><pc:displayname>" + prp.title + "</pc:displayname><pc:accountid>" + prp.loginname + "</pc:accountid><pc:accounttype>" + prp.principaltype + "</pc:accounttype></pc:person>"; } } tasklist = trygetlist(context, tasklistname); if (tasklist == null) { tasklist = createlistbytemplate(context, tasklistname, tasklisttemplate, tasklistname + " list"); } historylist = trygetlist(context, historylistname); if (historylist == null) { historylist = createlistbytemplate(context, historylistname, historylisttemplate, historylistname + " list"); } workflowassociationcreationinformation workflowassociationinfo = new workflowassociationcreationinformation(); workflowassociationinfo.template = wft; workflowassociationinfo.name = workflowname; workflowassociationinfo.tasklist = tasklist; workflowassociationinfo.historylist = historylist; workflowassociation association = list.workflowassociations.add(workflowassociationinfo); //context.load(association); //context.executequery(); association.allowmanual = allowmanual; association.autostartchange = autostartonchange; association.autostartcreate = autostartonnew; associationdata = @"<dfs:myfields xml:lang=" + "\"en-us\"" + " xmlns:xsd=\"http://www.w3.org/2001/xmlschema\" xmlns:dms=\"http://schemas.microsoft.com/office/2009/documentmanagement/types\" xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataformsolution\" xmlns:q=\"http://schemas.microsoft.com/office/infopath/2009/wsslist/queryfields\" xmlns:d=\"http://schemas.microsoft.com/office/infopath/2009/wsslist/datafields\" xmlns:ma=\"http://schemas.microsoft.com/office/2009/metadata/properties/metaattributes\" xmlns:pc=\"http://schemas.microsoft.com/office/infopath/2007/partnercontrols\" xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\"><dfs:queryfields><q:sharepointlistitem_rw><q:expandgroups xsi:nil=\"true\" /><q:duedateforalltasks xsi:nil=\"true\" /><q:durationforserialtasks xsi:nil=\"true\" /><q:durationunits xsi:nil=\"true\" /><q:cancelonrejection xsi:nil=\"true\" /><q:cancelonchange xsi:nil=\"true\" /><q:enablecontentapproval xsi:nil=\"true\" /></q:sharepointlistitem_rw></dfs:queryfields><dfs:datafields><d:sharepointlistitem_rw><d:approvers><d:assignment><d:assignee>" + approver + "</d:assignee><d:stage xsi:nil=\"true\" /><d:assignmenttype>serial</d:assignmenttype></d:assignment></d:approvers><d:expandgroups>" + expandgroup + "</d:expandgroups><d:notificationmessage>" + notification + "</d:notificationmessage><d:duedateforalltasks xsi:nil=\"true\" /><d:durationforserialtasks xsi:nil=\"true\" /><d:durationunits>day</d:durationunits><d:cc /><d:cancelonrejection>true</d:cancelonrejection><d:cancelonchange>true</d:cancelonchange><d:enablecontentapproval>true</d:enablecontentapproval></d:sharepointlistitem_rw></dfs:datafields></dfs:myfields>"; association.associationdata = associationdata; association.update(); context.executequery(); }
Comments
Post a Comment