Using Datafield to action K2 workflow Task in Rest Api and Asp.net MVC C# - Need help

  • 8 January 2019
  • 1 reply
  • 16 views

I have the below code to execute without datafield

 

Need advise to run the same task with datafield

 

[HttpPost, ActionName("ActionCR")]
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://k2d.asm.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 });


1 reply

Badge +11

It doesn't seem likely that anyone on the forum will be able to invest as much time stepping through that code and debugging as you.  You may wish to use K2's remote mentoring service for more detailed assistance looking at something of this level of detail.

Reply