Hello Community,

I have a use case where Creatio App needs to be connected to a 3rd party system always. Please help with following questions



1. How to trigger source code that establishes the connection with the 3rd party system? Its possible to run a Business Process, but if there is any other way, it could help.



2. How to get AppConnection/ Userconnection? Since the code is not triggered from client/Business process or API service (no inheritance from BaseService), how can I get the AppConnection?



Would much appreciate your help!

Like 0

Like

4 comments

Hello Shivani, 

 

1. Usually such operations performing with Business Processes and script tasks and honestly we don't have much convenient options for that. 

 

2. Script tasks exist for this kind of operations. You may use next code to achieve your requirements: 

 

var userConnection = Get<UserConnection>("UserConnection");

 

Also please check out this link with web-services it might be useful: 

 

https://academy.creatio.com/docs/developer/back-end_development/configu…

 

Thank you!

Regards, 

Bogdan L.

Thank you Bogdan. I found a post: https://community.creatio.com/questions/esq-application-access-rights

 

and it advices to get systemUserConnection as follows :

private SystemUserConnection _systemUserConnection;
private SystemUserConnection SystemUserConnection {
	get {
	     return _systemUserConnection ?? (_systemUserConnection = 
        (SystemUserConnection)AppConnection.SystemUserConnection);
	}
}

 

But looks like AppConnection is not a static class and I get the error in IDE as below. Please advice if I am doing something wrong or if the above suggestion does not work





In short passing the user connection from script task to call a source code or using BaseService for Web APIs is the only way to get userconection? 

 

Shivani Lakshman,

 

Please use User Connection from the script task to achieve the task desired.

 

Best regards,

Oscar

Update : One can create a new source code schema with a class that inherits from AppEventListenerBase.

The class has UserConnection as a property.  The UserConnection can be set using methods given in the code below. The onAppStart is called everytime IIS (webserver) is restarted or after compilation. 

// Property
protected UserConnection UserConnection	{
	get;
	private set;
	}
 
public override void OnAppStart(AppEventContext context) {
            base.OnAppStart(context);
            UserConnection = GetUserConnection(context);
            SetupConsumerJob();
        }
 
 
protected UserConnection GetUserConnection(AppEventContext context)    {
            var appConnection = context.Application["AppConnection"] as AppConnection;
            if (appConnection == null) {
                throw new ArgumentNullOrEmptyException("AppConnection");
            }
            return appConnection.SystemUserConnection;
        }







 

Show all comments
Hi.

Our intention is create a console app (C#) using EntitySchemaQuery  that query an entity (like Account or Contact) and gets its rows to populate a local table. 

We are trying to connect our bpmonline using this example:

source: https://www.bpmonline.cz/bpmonlinesdken/UsingEntitySchemaQuery.html

//////////
// Creating a query instance, adding columns and a data source in the query.
Select selectQuery = new Select(UserConnection)
                    .Column("Id")
                    .Column("Name")
                    .From("Contact");
// Executing a database query and getting the resulting dataset.
using (DBExecutor dbExecutor = UserConnection.EnsureDBConnection())
{
    using (IDataReader reader = selectQuery.ExecuteReader(dbExecutor))
    {
        while (reader.Read())
        {
            // Handling the query results.
        }
    }
} 

/////////////

The problem is we do not know how to create the connection string (UserConnection) to our cloud services, https://mycompany.bpmonline.com.

 

How to create this UserConnection? Someone has an example or may guide us?

 

 

Like 0

Like

3 comments

Theoretically, it's possible to use bpm'online local .dll-s and create the connection. However, it's very hard and usually pointless. If you need to get data from bpm'online, please create a web service in bpm'online. The service should get the needed data and give it to the requested.

This is how to create a service. 

https://academy.bpmonline.com/documents/technic-sdk/7-14/creating-configuration-service

This is how to log in and call it

https://academy.bpmonline.com/documents/technic-sdk/7-14/executing-odata-queries-using-fiddler

Eugene Podkovka writes:

However, it's very hard and usually pointless.

I don't think it's useless.

I'm trying to achieve the same goal to increase our developers' productivity.

We usually use task script in the process designer to manipulate data using EntitySchemaQuery.

Each time, we have to update the process, run it and check the log or attach visual studio debugger (which is painful) to verify our code.

Imagine if we are able to get a UserConnection instance directly into a standalone app. we can test our functions faster and increase the overall productivity.

 @Eugene Podkovka: can you please help us!

Thank you

Mohamed

Show all comments

I try to run the script task in a business process to create a printable. If the business process is started by user, it'll work just fine, but when the process is started by another process or an event it'll break with an exception:

System.NullReferenceException: Object reference not set to an instance of an object.

   at Terrasoft.Configuration.ReportService.ReportService.GetSchemaNameByTemplateId(Guid templateId)

   at Terrasoft.Configuration.ReportService.ReportService.GenerateMSWordReport(String urlTemplateId, String urlRecordUId, Boolean convertInPDF)

   at Terrasoft.Core.Process.ProcessInvoiceAutoSendCustom1Custom21Custom2MethodsWrapper.ScriptTask2Execute(ProcessExecutingContext context)

   at Terrasoft.Core.Process.ProcessFlowElement.Execute(ProcessExecutingContext context)

The script task is like this:

var PrintableId = Get<string>("PrintableId2");
var ObjectIdInvoice = Get<string>("ObjectIdInvoice1");
var ConvertToPdf = Get<bool>("ConvertToPdf");
var AddInvoiceId = Get<Guid>("AddInvoiceId");
var AttachmentType = Get<Guid>("AttachmentType");
 
var userConnection = Get<UserConnection>("UserConnection");
 
var reportService = new Terrasoft.Configuration.ReportService.ReportService();
Terrasoft.Configuration.ReportService.ReportData report = reportService.GenerateMSWordReport(
    PrintableId, ObjectIdInvoice, ConvertToPdf);
var entity = userConnection.EntitySchemaManager.GetInstanceByName("InvoiceFile");
var fileEntity = entity.CreateEntity(UserConnection);
fileEntity.SetDefColumnValues();
fileEntity.SetColumnValue("InvoiceId", AddInvoiceId);
fileEntity.SetColumnValue("TypeId", AttachmentType);
fileEntity.SetColumnValue("Name", "Invoice.pdf");
fileEntity.SetColumnValue("Data", report.Data);
fileEntity.Save();
return true;

I guess ReportService doesn't obtain UserConnection from Supervisor user, so it can't get instance of "InvoiceFile". Is that the case?

How to change the script to make ReportService work with Supervisor or maybe with UserConnection of another user?

Like 0

Like

3 comments

In a script task in an interpretive business process you need to get "user connection"  with the following syntax:

var userConnection = Get<UserConnection>("UserConnection");

Additionally, please note that if you want to work with process parameters in a script task, you need to write in the following manner:

var parameter1 = Get<Guid>("Parameter1");

Set("Parameter2", parameter1.ToString());

var parameter2 = Get<string>("Parameter2");



Also, from exception message it seems that desired template not exists in the system, so you should check it.

I have a similar requirement to send report automatically to users at a certain frequency. We use Creatio 7.18.5 and the report was built using the old ReportDesigner for 7.14 and was carried over to the new version when we upgraded. 

I tried to follow this article to create the report as part of our process - https://community.creatio.com/articles/generate-printable-and-send-it-attachment-email

When the process is manually run by the user, the report gets generated. But when scheduled to run by Supervisor using timer, it gives below error - 

Terrasoft.Core.InstanceActivationException: Error creating an instance of the "Terrasoft.Tools.DevExpressReport.IReportProvider" class ---&gt; Ninject.ActivationException: Error activating UserConnection using binding from UserConnection to method
Provider returned null.
Activation path:
  3) Injection of dependency UserConnection into parameter userConnection of constructor of type DevExpressConfReportLocalizationReader
  2) Injection of dependency IDevExpressReportLocalizationReader into parameter reportLocalizationReader of constructor of type ConfigurationDevExpressReportProvider
  1) Request for IReportProvider
 
Suggestions:
  1) Ensure that the provider handles creation requests properly.
 
   at Ninject.Activation.Context.ResolveInternal(Object scope)
   at Ninject.Activation.Context.Resolve()
   at Ninject.KernelBase.Resolve(IRequest request, Boolean handleMissingBindings)
   at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Ninject.Activation.Providers.StandardProvider.Create(IContext context)
   at Ninject.Activation.Context.ResolveInternal(Object scope)
   at Ninject.Activation.Context.Resolve()
   at Ninject.KernelBase.Resolve(IRequest request, Boolean handleMissingBindings)
   at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Ninject.Activation.Providers.StandardProvider.Create(IContext context)
   at Ninject.Activation.Context.ResolveInternal(Object scope)
   at Ninject.Activation.Context.Resolve()
   at Ninject.KernelBase.Resolve(IRequest request, Boolean handleMissingBindings)
   at Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters)
   at Terrasoft.Core.Factories.ClassFactory.GetInstance[T](Func`1 action)
   --- End of inner exception stack trace ---
   at Terrasoft.Core.Factories.ClassFactory.GetInstance[T](Func`1 action)
   at Terrasoft.Configuration.DevExpressReportGenerator.Generate(UserConnection userConnection, ReportGeneratorConfiguration configuration)
   at Terrasoft.Core.Process.TAIAutoSendOrderLogSummaryMethodsWrapper.ScriptTask1Execute(ProcessExecutingContext context)
   at Terrasoft.Core.Process.ProcessScriptTask.InternalExecute(ProcessExecutingContext context)
   at Terrasoft.Core.Process.ProcessFlowElement.ExecuteItem(ProcessExecutingContext context)
   at Terrasoft.Core.Process.ProcessFlowElement.Execute(ProcessExecutingContext context)

Below is the report generation part of the code -  

//ReportService reportService = new ReportService(userConnection);
//ReportData report = reportService.GenerateDevExpressReport(entitySchemaUId,reportSchemaUId,null,reportParamaters);
 
DevExpressReportGenerator reportGenerator = new DevExpressReportGenerator();
var configuration = new ReportGeneratorConfiguration {
				ReportTemplateId = !string.IsNullOrEmpty(reportSchemaUId) ? new Guid(reportSchemaUId) : Guid.Empty,
				EntitySchemaUId = !string.IsNullOrEmpty(entitySchemaUId) ? new Guid(entitySchemaUId) : Guid.Empty,
				RecordId = !string.IsNullOrEmpty(recordId) ? new Guid(recordId) : Guid.Empty,
				ReportParameters = !string.IsNullOrEmpty(reportParameters)
					? JsonConvert.DeserializeObject&lt;Dictionary&lt;string, object&gt;&gt;(reportParameters)
					: null
			};
ReportData report = reportGenerator.Generate(userConnection, configuration);

I understand it's an old version of the report but I would appreciate if anyone can provide any insights on what I'm missing.

Hello Nirupama, Can you check if the run elements in the background is disabled ? If that is enabled, then the process will not get the User Connection.

Show all comments