I tried executing the below code to execute K2 workflow task using REST API. The is running without any errors with status code 200 but task is not getting updated. I tried the URL which is generated by the code in a separate browser window, strange it is working fine. But when run through custom asp.net mvc page it still runs without any issue but there is no output, i meant task is not getting updated. Need help for this strange issue
URL generated by code :
completeTaskURL
Code
public async Task<JsonResult> ActionCR(int CRID, string SNID,string action)
{
ChangeRequest changeRequest =await db.ChangeRequests.FindAsync(CRID);
// post XML to process service
System.Threading.Tasks.Task<HttpResponseMessage> response;
System.Net.Http.HttpClientHandler handler = new HttpClientHandler();
string K2ServerURL = @"https://xyz.ddd.com/K2Services/REST.svc";
string worklistTasksEndpointURI = @"/Worklist/Items";
handler.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
{
using (HttpClient client = new HttpClient(handler))
{
string resourceAddress = worklistTasksEndpointURI;
//if you want to start sync, append ?synchronous=true to the URL;
client.BaseAddress = new Uri(K2ServerURL + "/");
string actionName ="("+action+")";
ViewBag.SNID = SNID;
string serialNumber = "(" + ViewBag.SNID + ")";
string completeTaskURL = K2ServerURL + worklistTasksEndpointURI + serialNumber + @"/Actions" + actionName + @"/Execute?format=JSON";
//start an async call to the service. Normally you would use more advanced threading for this approach
response = client.GetAsync(completeTaskURL);
response.Wait();
if (!response.Result.IsSuccessStatusCode)
{
throw new Exception(response.Result.StatusCode.ToString());
}
}
}
var redirectionURL = new UrlHelper(Request.RequestContext).Action("Details", "ChangeRequests", CRID);
return Json(new { ChangeRequestID = changeRequest.ChangeRequestID, Url = redirectionURL, Id = changeRequest.ID });
}