I am trying to approve nintex worklfow flexi task by using the below code,and its working perfectly in Visual Studio 2012 Console application but when I am trying to incorporate the same code Sharepoint 2013 visual webpart its not working. I understand the problem with the logged in user credential,in order to call the webservice with system account permission I have used the RunWithElevatedPrivileges code and since this account is not the approver, so does not have any pending task.Then if I try to run the code with the logged in user(by commenting RunWithElevatedPrivileges code) permission who is the actual approver, in this case logged in user getting 401 unauthorized access to webservice error. My basic objective is to approve the nintex workflow flexi task from sharepoint visual webpart. How can do this any help would be much appreciated.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
try
{
using(SPSite mySPSiteObject=new SPSite(SPContext.Current.Site.Url))
{
using(SPWeb myWeb=mySPSiteObject.OpenWeb())
{
ProcessTaskResponseResult? result = null;
NintexApprovalService.NintexWorkflowWS objNintextClient = new NintexApprovalService.NintexWorkflowWS();
objNintextClient.UseDefaultCredentials = true;
NintexApprovalService.UserTask[] userTask =objNintextClient.GetRunningWorkflowTasksForCurrentUser(itemUrl); //This webmethod will give array of assigned tasks.
foreach (NintexApprovalService.UserTask objTask in userTask)
{
int taskID = objTask.SharePointTaskId;
result = CallProcessTaskResponse(taskID);
}
}
}
}
catch(Exception e)
{
Logger.write(e.message + "--" + e.stackTrace);
}
});