Triggering a business process with parameter value from anonymous web-service
Hi there,
I have a requirement to trigger a business process with a parameter value from an anonymous web service and get errors while publishing the code in the Creatio environment. Below I have mentioned the complete code of the web service and the error screenshot of the error.
Note: I have pre-created the business process with the parameter and written the web service.
I referred other community articles such as
https://community.creatio.com/articles/web-service-without-authorizatio…
https://community.creatio.com/questions/calling-business-process-parame…
These codes currently seem to be outdated and not working in the Atlas version of creatio. Please give me suggestions to resolve this issue.
Code :
/* The custom namespace. */
namespace Terrasoft.Configuration.WSO2WSConfirmationServiceNamespace
{
using System;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.ServiceModel.Activation;
using Terrasoft.Core;
using Terrasoft.Web.Common;
using Terrasoft.Core.Entities;
using Terrasoft.Core.Process;
using Terrasoft.Core.Process.Configuration;
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class WSO2WSConfirmationService : BaseService
{
/* The link to the UserConnection instance required to access the database. */
private SystemUserConnection _systemUserConnection;
private SystemUserConnection SystemUserConnection
{
get
{
return _systemUserConnection ?? (_systemUserConnection = (SystemUserConnection)AppConnection.SystemUserConnection);
}
}
/* The method that returns the confirmation of buttons. */
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json)]
public string ConfirmationService(string guid, bool status)
{
new Guid(guid);
string result = "Guid is missing";
if (!string.IsNullOrEmpty(guid)) {
if (status == false)
{
var manager = UserConnection.ProcessSchemaManager;
var processSchema = manager.GetInstanceByName("WSO2Process_3c0d24a");
var moduleProcess = processSchema.CreateProcess(UserConnection);
if (processSchema.Parameters.ExistsByName("ProcessSchemaConfirmationId"))
{
moduleProcess.SetPropertyValue("ProcessSchemaConfirmationId", guid);
}
moduleProcess.Execute(UserConnection);
/*ProcessSchema schema = UserConnection.ProcessSchemaManager.GetInstanceByName("WSO2Process_3c0d24a");
//schema = UserConnection.ProcessSchemaManager.GetInstanceByUId(leadManagementProcessUId);
//different engines for interpretable and compiled BP
bool canUseFlowEngine = ProcessSchemaManager.GetCanUseFlowEngine(UserConnection, schema);
if (canUseFlowEngine)
{
var flowEngine = new FlowEngine(UserConnection);
var param = new Dictionary();
param["ProcessSchemaConfirmationId"] = guid.Id.ToString();
flowEngine.RunProcess(schema, param);
}
else
{
Process process = schema.CreateProcess(UserConnection);
process.SetPropertyValue("ProcessSchemaConfirmationId", guid.Id);
process.Execute(UserConnection);
}*/
result = "Response posting is cancelled, You can close this tab";
}
else {
result = "WSO2 endpoint intergration is pending";
}
}
return result;
}
}
}
Like
Found the answer for this mentioned issue, Please refer to the code below. Using IProcessExecutor, this can be simply achieved in the 8.0 version.
/* The custom namespace. */
namespace Terrasoft.Configuration.WSO2WSConfirmationServiceNamespace
{
using System;
using System.ServiceModel;
using System.Collections.Generic;
using System.ServiceModel.Web;
using System.ServiceModel.Activation;
using Terrasoft.Core;
using Terrasoft.Web.Common;
using Terrasoft.Core.Entities;
using Terrasoft.Core.Entities.Events;
using Terrasoft.Core.Process;
using Terrasoft.Core.Process.Configuration;
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class WSO2WSConfirmationService : BaseService
{
/* The link to the UserConnection instance required to access the database. */
private SystemUserConnection _systemUserConnection;
private SystemUserConnection SystemUserConnection
{
get
{
return _systemUserConnection ?? (_systemUserConnection = (SystemUserConnection)AppConnection.SystemUserConnection);
}
}
/* The method that returns the confirmation of buttons. */
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json)]
public string ConfirmationService(string guid, bool status)
{
try
{
new Guid(guid);
string result = "Guid is missing";
if (!string.IsNullOrEmpty(guid))
{
if (status == false)
{
{
// getting IProcessExecutor
IProcessExecutor processExecutor = SystemUserConnection.ProcessEngine.ProcessExecutor;
// List of input parameters
var inputParameters = new Dictionary<string, string>
{
["ConfirmationId"] = guid.ToString(),
};
//code of the process
string processSchemaName = "WSO2Process_3c0d24aCustom1";
//execute the process
ProcessDescriptor processDescriptor = processExecutor.Execute(processSchemaName, inputParameters);
//return processDescriptor;
}
result = "Response posting is cancelled, You can close this tab";
}
else
{
result = "WSO2 endpoint intergration is pending";
}
}
return result;
}
catch (Exception ex)
{
return "GUID error - " + ex.Message;
}
}
}
}
Thanks