Question

Handling of Asynchronous tasks in Script Task

var request = new HttpRequestMessage(HttpMethod.Post, SPrelativeURL + "/_api/web/folders");
   var requestobj = CreateRequest();
   string payload = JsonConvert.SerializeObject(requestobj);
   var payloadstr = new StringContent(payload);
 
   var content = new StringContent(payload, Encoding.UTF8, "application/json");
   content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json;odata=verbose");
 
   HttpResponseMessage response = await client.PostAsync(SPrelativeURL + "/_api/web/folders", content);
   int statuscode = (int) response.StatusCode;
   var result = await response.Content.ReadAsStringAsync();

Hello Team,

 

We currently run a business process to create folders in SharePoint for each Customer Account. This process is crucial because if this folder is not created, we cannot upload related files into that folder. We have noticed that the PostAsync call in the business process script task takes time sometimes and ends in a timeout error because the main thread of the business process does not wait for that long.

 

I have attached source code snippet and screenshot of the business process for your reference. Could you please help us out with suggestions and best practices to handle such time outs? What are the best ways to retry this process and how best to handle Asynchronous tasks in script task?

 

Thanks

 

Like 0

Like

4 comments

You'll need to change the calls to synchronous. For example, change lines using await from this: 

var result = await response.Content.ReadAsStringAsync();

To this:

var result = response.Content.ReadAsStringAsync().Result;

 

Ryan

Hello Shivani, 

 

You can also take a look at the Creatio Academy article that describes the execution of an asynchronous operation: https://academy.creatio.com/documents/technic-sdk/7-13/background-opera…

 

Please, let us know in case any additional information is required.

 

Best regards, 

Olga.  

Thank you folks for your suggestions. If incase the folder creation fails, how do we retry the business process? I understand we can handle it through script task as well. But is there a way to retrigger the business process?

Shivani Lakshman,

You can set up process with a timer so it would start periodically regardless of previous result. Currently, there are no other solutions to this task.

 

Best regards,

Angela

Show all comments