Invoke business process using C# code

Hello,

I am trying to invoke a business process from C# script. Below is my code, 

ProcessSchema schema = UserConnection.ProcessSchemaManager.GetInstanceByName("Cw AI Process");

Process process = schema.CreateProcess(UserConnection);
process.SetPropertyValue("RecordId", Guid.Parse("e308b781-3c5b-4ecb-89ef-5c1ed4da488e"));
process.SetPropertyValue("RecordType", "Account");
process.Execute(UserConnection);
var result = process.GetPropertyValue("OutputVar");

 

And this is the error I am seeing. Both RecordId and RecordType are input parameters of the business process.

Property "RecordId" is missing in type "ProcessComponentSet".

Like 0

Like

3 comments

Hi,

 

You will find it in academy : https://academy.creatio.com/docs/developer/integrations_and_api/busines…

or do something like this : 

			var uc = Get<UserConnection>("UserConnection");
 
			var parameters = new Dictionary<string, string>() {
				{"vExerciceUsager", ExerciceUsagerId.ToString()},
				{"vRegleCalcul", RegleCalculId.ToString()},
				{"vBloc", BlocId.ToString()}
			};
 
			IProcessExecutor processExecutor = uc.ProcessEngine.ProcessExecutor;
			processExecutor.Execute(ProcessSchemaUId, parameters);
			return true;

 

Jerome BERGES,

Thank you I got that..
I have a question.. How do I read the value from output parameter.. Below is my code.. am I missing something?

UserConnection userConnection = UserConnection;
IProcessExecutor processExecutor = userConnection.ProcessEngine.ProcessExecutor;
/* Collection of incoming parameters.*/
var inputParameters = new Dictionary<string, string> {
   ["RecordId"] = "ecb-89ef-5c1ed4da488e",
   ["RecordType"] = "Account"
}; 
/* Collection of outgoing parameters.*/
var resultParameterNames = new string[] { 
   "strValue",
};
string processSchemaName = "UsrProcess_6ff6f";
/* Runs the process via the schema name using transferred incoming and received outgoing parameters.*/
ProcessDescriptor processDescriptor = processExecutor.Execute(processSchemaName, inputParameters, resultParameterNames);
string AiResponseValue = processDescriptor.ResultParameterValues["strValue"];


return true;

I never done this with output parameters, but it may be that your process is in background mode (which is not allowed), or your parameter is not of type "Output"

Show all comments