Business Process from Backend Script (C#)

Hi Team,

I have to run a business process from C# script. I used below code, unfortunately not wokring

UserConnection userConnection = Get<UserConnection>("UserConnection");
IProcessEngine processEngine = userConnection.ProcessEngine;
IProcessExecutor processExecutor = processEngine.ProcessExecutor;
processExecutor.Execute("UsrProcess2Custom1");
return true;

URL:  Service that runs business processes | Creatio Academy

Help me with invoking Business Process from Server-Side (C#)

Like 0

Like

3 comments

Hello Souresh,

1. Do you have compilation errors?

2. Ensure that the name of the process you are attempting to start matches in your code and process settings:
Process name in settings
Process name in code

3. Try to debug your code, more on that here:
https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platform/development-tools/debugging-tools/back-end-debugging/overview

Hi Artem & Eduard,

Thanks for the response,

I just want to be clear on the script you have provided, can we use that in custom web-services providing you the example of web-service below:
 

[OperationContract]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "TestDBConnection")]
        public string TestDBConnection()
        {
            string result = "{}";
        
            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
        
                    result = JsonConvert.SerializeObject(new {
                        Success = true,
                        IsError = false,
                        IsConnectionError  = false,
                        StatusCode = 0,
                        Message = "Database Connection Success",
                    });
                }
            }
            catch (Exception ex)
            {
                int statusCode = -1;
                string message = ex.Message;
            
                if (ex is SqlException sqlEx)
                {
                    statusCode = sqlEx.Number;
                    message = sqlEx.Message;
                }
            
                result = JsonConvert.SerializeObject(new
                {
                    Success = false,
                    IsError = true,
                    IsConnectionError  = statusCode == 64,
                    StatusCode = statusCode,
                    Message = message
                });
            }
        
            return result;
        }
 

Show all comments