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

I'm trying to pass a Guid from a script task to a subprocess.

Here is the entire process: http://prntscr.com/mc2cmv&nbsp;

The code of the script task is:

 

var pipelineId = Entity.UsrPipelineId;
 
//pass pipelineId to GenerateUBOPositionSubProcess
 
return true;

What would I have to write? The subprocess has a parameter defined that is named PipelineId (http://prntscr.com/mc2ej9).

Like 0

Like

5 comments

You can set process parameter in the script:

Set("PipelineId", pipelineId);

That sets the parameter for the process that contains the script task, but not for a subprocess that is further down the line from the script task (see the first link I included), I thought? Or do processes and subprocesses share parameters?

Dear Jonas,

You can use this coder to pass the value:

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

IProcessEngine processEngine = userConnection.ProcessEngine;

IProcessExecutor processExecutor = processEngine.ProcessExecutor;

var nameValues = new Dictionary<string, string>();

int parameter1Value = 100;

nameValues["parameter1"] = parameter1Value.ToString();

processExecutor.Execute("UsrProcessCustom", nameValues);

return true;

Best regards,

Dean

Thank you. I will start testing this today. 

Now I need to know how to get data back from that process. Is that possible?

Dear Jonas,

You can try to add another element in your subprocess and use the same script to pass the values back to the parent process. 

Dean

Show all comments

Hi Community,

This code below gets the Guid of the current user in client side code

Terrasoft.SysValue.CURRENT_USER.value

How about in script task, using C# code what is its equivalent?

 

 

Like 0

Like

4 comments

In a script task you have access to UserConnection. This exposes a  CurrentUser property (which provides an object of type SysUserInfo). 

var currentUser = UserConnection.CurrentUser;
var userId = currentUser.Id;
var userName = currentUser.Name;

BTW If this was code in a source code schema/configuration service, you'd need to get the UserConnection via the AppConnection first:

var appConnection = HttpContext.Current.Application["AppConnection"] as AppConnection;
var currentUser = appConnection.SystemUserConnection.CurrentUser;

 

Ryan Farley,

Thanks Ryan,

Is there any documentation about CurrentUser. I want to know everything about its properties and attributes for future use.

Thanks.

Fulgen Ninofranco,

I don't know of any documentation, it is in Terrasoft.Core.dll, however, the SysUserInfo object inherits from the SysAdminUnit object. This object you can see in the configuration. Search for SysAdminUnit in the configuration and you'll see what is available in the SysUserInfo. The SysUserInfo object itself only adds 5 additional properties for TimeZone, PageRowsCounr, Culture, ClientIP, and DateTimeFormatCode.

Dear Fulgen,

Please use the example mentioned by Ryan, it covers the way you work with UserConnection in Script Task. 

var currentUser = UserConnection.CurrentUser;

For more information on all .Net classes used in the system please see this article:

https://academy.bpmonline.com/api/netcoreapi/7.13.0/index.html#GeneralS…

Also, as for examples of UserConnection usage in web services you can check the examples here:

https://academy.bpmonline.com/documents/technic-sdk/7-13/how-create-cus…

 Regards,

Anastasia

Show all comments

Hello community



I am working with a business process using the process element [Call Web Service].

The web service configuration and the call are working correctly.

The JSON response is similar to:

{

"$ totalResults": 2,

"$ startIndex": 1,

"$ itemsPerPage": 100,

"$ resources": [

     {

      "$ clave": "t6UJ9A000001",

      "$ Static_state": 200,

      "$ etag": "Yi4EmiUg3xw =",

       "Account": {

             "$ clave": "A6UJ9A0001RU",

             "$ uuid": "00000000-0000-0000-0000-000000000000",

           }

      },

      {

      "$ clave": "t6UJ9A00000B",

      "$ Static_state": 200,

"$ etag": "wMpPUtrfgdA =",

"Account": {

"$ clave": "A6UJ9A0001RX",

"$ uuid": "00000000-0000-0000-0000-000000000000",

}

}

]

}



My goal is to iterate the JSON and finally create tickets in BPM with the source information.

Using a pre-configured page I was able to determine that the parameter where the information is returned is [#WS Step.Response body #]

How can I take this value in a Script Task and process the JSON? or what is the correct procedure to do this?

Previously I should be able to take the value of the parameter [#WS Setp.Success #] to determine if the execution was successful

Thank you!

Good weekend

Like 0

Like

1 comments

get/set a parameter value in a business process script task

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

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

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

get object of type UserConnection

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

Show all comments

I'm creating a process that reads data and then needs to update a text column on that data by appending some new text to the existing string. I can read the data fine but the script task throws a null reference exception. Here is the simplified version of my script:

var programs = Get("ReadDataUserTask1.ResultEntityCollection");

foreach(var program in programs) {
    program.SetColumnValue("Campaign Flags", "Test");
}

return true;

The programs is null when I run the process.

Like 0

Like

7 comments

Dear Scott,

Try another approach to overcome the issue. Please read the collection of the Read Data in the following way: 

 var entities = Get<ICompositeObjectList<ICompositeObject>>("ReadDataUserTask1.ResultCompositeObjectList");

Afterwards proceed further with collection result.

Regards,

Anastasia

Anastasia Botezat,

using trying the above script, when I convert the list to string by doing:

entities.ToString());

I get  - Terrasoft.Common.CompositeObjectList`1[Terrasoft.Common.CompositeObject] (looks like the type and not the value)

Can you help?

Chani Karel,

 

There is no need to cast object to string since you can get the value from some column of the object using GetCompositeObjectColumnValue (in my case I was reading the "Full name" column value from the collection of contacts):

 

string name = GetCompositeObjectColumnValue&lt;string&gt;(contacts, "Name");

and then process the value according to your needs.

 

Best regards,

Oscar

Hi Chani Karel,

I think there are 2 things in your scripts:

1. You ReadDataUserTask1 result could be empty.

var programs = Get&lt;EntityCollection&gt;("ReadDataUserTask1.ResultEntityCollection");

Therefore, before the "foreach Loop", you really need to check if the programs is null or not. Otherwise, you might get the exception as you mentioned.

 

2. Please use the column code instead of column title to set value.

For example, in Contact there is column with code "JobTitle" and title "Full job title". If you need to set the value, you need to use the code "JobTitle".

 

regards,

 

Cheng Gong

Oscar Dylan,

using the tostring method was just to understand why I don't get the values as needed. 

What I need to do is this:

I get a list of 'contact in opportunity' by the read collection of records element. I need to get the contact as lookup  value and not as string (the Id and not name) in order to set parameters with the contacts and send email to them.

How do I do it?

Thank you.

Cheng Gong,

using the tostring method was just to understand why I don't get the values as needed. 

What I need to do is this:

I get a list of 'contact in opportunity' by the read collection of records element. I need to get the contact as lookup  value and not as string (the Id and not name) in order to set parameters with the contacts and send email to them.

How do I do it?

Thank you.

Chani Karel,

How did you end up solving this?

 

Kind regards,

Yosef

Show all comments

Hi Community,

How can I debug a script task from like setting some break point and tracing codes line by line.

Thanks

Like 0

Like

6 comments

See this

Dear Fulgen,

You can use the link provided in the previous comment by Grigory:

https://academy.bpmonline.com/documents/technic-sdk/7-12/working-server…

Since Script Task is the chunk of C# code, it can be treated as other C# code in the system.

The article provides steps to perform debugging, please use them to debug Script Task.

Regards,

Anastasia

Anastasia Botezat,

Hi Anastasia,

When I do download package to file system there is no .cs file under my business process folder, this business process should contain the script task of my business process for me to debug it in visual studio

Dear Fulgen,

I am sorry to hear that you experiences difficulties with this approach. I would like to offer you another approach to debug server code. I hope you will find it more suitable to work with:

https://academy.bpmonline.com/documents/technic-sdk/7-12/server-code-debugging

Regards,

Anastasia

Anastasia Botezat,

Hi Anastasia,

I already done this application setup below

I also made sure that the value of CompilerSourcesTempFolderPath directory is existing. But no schema source code was exported.

 

Dear Fulgen,

Please revert all that you do on the screenshot, this approach is deprecated. Afterwards, please change only one thing from the main article https://academy.bpmonline.com/documents/technic-sdk/7-12/visual-studio-… and this thing is setting:

<fileDesignMode enabled="true" /> in the main Web.config file and <add key="UseStaticFileContent" value="false" />



After that compile the application, and within the compilation following folder will be populated with all of the .cs files that you need:

your_path_to_bpmonline\Terrasoft.WebApp\Terrasoft.Configuration\Autogenerated\Src

Taking the file that you need into the new visual studio library project, you can attach the project to the IIS bpm'online process and debug the file as it described in the old article:

https://academy.bpmonline.com/documents/technic-sdk/7-12/server-code-de…

but skipping the part of the configuration. This will be the simplest approach: To take configuring steps from the new article but debugging from the old one.

Also, you may need to compile the system twice, before and after connecting to the IIS process in order to .cs files be exactly the same, in another case if files will be different, the breakpoints in visual studio will be gray and will not work.

Moreover, try to copy the file to a new project and place breakpoints in them, and try to drag and drop the original file from Terrasoft.WebApp\Terrasoft.Configuration\Autogenerated\Src to the main window of visual studio and place breakpoints in them too, after the attaching to the process and compiling the system, one of the approaches will definitely work for you.

 

Show all comments

Hello community,

I am trying to perform the following command from a Script Task element:

DELETE FROM [dbo].[UsrListDocuments] WHERE [Opportunity] = @P1 AND [Product] = @P2

Currently, the C# code is similar to this:

var opportunityId = Get("Read opportunity product.Opportunity");
var productId = Get("Read opportunity product.Product");
var delete = new Delete(userConnection)
        .From("UsrListDocuments")
        .Where("Opportunity").IsEqual(opportunityId)
        .Where("Product").IsEqual(productId);
        
return true;

Is this accurate? What would be the best practice in this case? The code is not working properly that´s why I am looking for your assistance.

Thanks.

Like 0

Like

2 comments

Hello,

As far as I understood your business goal, you are trying to fetch some parameters via [Read Data] element in your script task and pass it further to the Delete query.



Firstly, you need to get parameters in the [Script Task] from the [Read Data] element.

For the interpreted process the algorithm is the next:

1) Create a business process parameters and map it to the needed Read Data element. You can learn more about business parameters in our guide - https://academy.bpmonline.com/documents/technic-bpms/7-12/how-add-param…

In your example it will be something like:

[#Read opportunity product.First item of resulting collection.Opportunity#] and [#Read opportunity product.First item of resulting collection.Product#]

2) Use business-parameters in your Script-task.

var opportunityId = Get<Guid>("ProcessParam1");

var productId = Get<Guid>("ProcessParam2");

Then you need to get the userConnection in order to pass it in the Delete query:

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

After that you can create a delete query:

var delete = new Delete(userConnection)

        .From("UsrListDocuments")

        .Where("Opportunity").IsEqual(opportunityId)

        .Where("Product").IsEqual(productId);

        

And execute it:

 delete.execute();

Tetiana Markova,

Thanks, Thetiana. It worked.

Show all comments

Let's say I read one object using Read data step and I choose to only read columns First name and Last name. How do I reference that data in Script task? I know I can copy those strings from step parameters to process parameters using Formula step but maybe there is a better way.

Like 0

Like

15 comments

Dear Carlos,

For the [Script-task] elements and methods that have the [For an interpreted process] checkbox selected, the wrapper class is generated that contains the initialization and declaration of methods. This wrapper enables you to access the process values. 

The Get method returns the value of an item or process.

Method signature:

Get<T>(string path)

where:

  • T — parameter value type.
  • path — a string that specifies the path to a parameter or property. The path is built according to these rules:
  1. “parameter name”
  2. “property name”
  3. “element name.parameter name”
  4. “element name.property name”

Oliver

Oliver,

I don't see a parameter First name though. The only related parameter that I see is Columns to read.

Carlos Zaldivar Batista,

You don't need any parameters and select any specific columns to read in the element Read Data, simply use “element name.property name” to get the field value in the Script task.

Oliver

Oleh Chudiiovych,

Ok, so I have a step with code ReadSomeData and I try to read the columns of returned object like this:

Get&lt;Entity&gt;("ReadSomeData.ResultEntity").GetTypedColumnValue&lt;string&gt;("UsrFirstName")

I get NullReferenceException though because the Get method returned null.

Try read data from all columns. Also possible for your query (filter) no records? Do it work if you remove the filter

Grigoriy,

I read data from all columns and the query returns records.

Dear Carlos,

As far as we can see from your method you are trying to read values from the "UsrFirstName" column and we don't know what data is stored there and what are you trying to read. Please re-check all your columns and also try Grigoriy's suggestion about filters.

Oscar

Ok, so I created a new trial environment with default test data and in that environment I created a process:

 

The Read data step looks like this:

I set up the step name too:

And that is my Script task code:

Name is a process parameter that is shown in the auto-generated screen. That's what the screen shows after running the process:

There are no filters in the read data step and the data is there. What should I change to make the script task work?

Hi by default read data have code "ReadDataUserTask1".

Try this:

var entity = Get<Entity>("ReadDataUserTask1.ResultEntity"); 

 

See read data advanced mode for get elenent code (

In the advanced mode, the element setup area contains additional parameters and connections with system records

To access the advanced mode, click the btn_advanced_mode.png button in the element setup area and select the [Advanced mode] menu command

)

Sory. For interpretable processes, you can only directly work with the methods and parameters of the elements through the formula.

In autogenerate page set page item via formula like:

[#Read data 1.First item of resulting collection.First name#] 

Grigoriy,

Thank you. And is it possible to use this formula in a script tasks?

Yes

1. Create a process parameter of type String - TestParam.

2. In the parameter value specify [#Read data 1.First item of the resulting collectionFirst name#].

3. In the Task-script element, work with the parameter.

     var contactFullName = Get<string> ("TestParam");

Grigoriy,

Ok, thank you.

Does anyone know if this is still the case? i.e. that it's necessary to save each individual field to a parameter in order to access them inside a Script Task element of a Business Process? It seems like it really should be simpler to access data on any of the fields!

 

I am aware of being able to query the entity directly within the Script Task, but I'd like to keep as much of the business logic in easy-to-read BP steps as possible, including reading data.

Dear Harvey,

 

Yes, the logic remains the same. There is still to call for read data element through the script task without the intermediate process parameters or settings. This logic will be review by our developers, it is confirmed by our R&D but we do not know when it will be done.

 

Regards,

Dean

 

Show all comments

I know that we can use Get to read process parameters in C# scripts but I don't know how to use this method to read process elements' properties, like for example Created record ID. So far what I'm doing is making a new process parameter and setting its value with Formula block. Is there a better way?

Like 0

Like

2 comments

Dear Carlos,

You can access the process elements parameters in following ways. Lets say I have a ReadData element before my ScriptTask and I want to obtain the CaseId from it in my ScriptTask. First, I click "Advanced mode" (tree dots in the right top corner of right panel):

 

There you can find the Code of the element, so to address it with. Also, in the parameters tab you can see all available parameters of the element. In my example this is ReadDataUserTask1.

Here I can obtain the collection of entities from ReadData and set them to parameter, if needed:

EntityCollection entities = Get&lt;EntityCollection&gt;("ReadDataUserTask1.ResultEntityCollection");
Set("Param1", entities);

The other approach is to access properties though the dot, like any other properties retrieval:

var parameter = Get<Guid>(ReadDataUserTask1.CaseId);

Also, there is still working approach with read data element and setting value to the process parameter through formula element you have mentioned.

Hope you find it helpful,

Anastasia Botezat

 

Anastasia Botezat,

Thank you very much.

Show all comments

Hi everyone,

I need to call a sub-process from a C# script task, I found this code:

var showAdressProcessUId = new Guid("abfbf7ee-e499-45e9-9d22-b9e91a46683d");
var manager = UserConnection.ProcessSchemaManager;
var schema =  (ProcessSchema)manager.GetInstanceByUId(showAdressProcessUId);
var moduleProcess = schema.CreateProcess(UserConnection);
moduleProcess.SetPropertyValue("PageInstanceId", PageInstanceId);
moduleProcess.SetPropertyValue("ActiveTreeGridCurrentRowId", ActiveTreeGridCurrentRowId);
moduleProcess.SetPropertyValue("TreeGridSelectedRowsIds", TreeGridSelectedRowsIds);
moduleProcess.SetPropertyValue("SchemaName", "Contact");
moduleProcess.SetPropertyValue("RouteMode", false);
moduleProcess.Execute(UserConnection);

From ShowContactAddressOnMapProcess

If I use it for my process:

var _sendMailId = new Guid("84e96844-b0ae-4edc-8b5e-20d1ba13fb8b");
var _manager = UserConnection.ProcessSchemaManager;
var _schema = (ProcessSchema)_manager.GetInstanceByUId(_sendMailId);
var _moduleProcess = _schema.CreateProcess(UserConnection);
_moduleProcess.SetPropertyValue("Test1", "Something");
_moduleProcess.Execute(UserConnection);

Throws this exception :

Terrasoft.Common.InvalidObjectStateException: missing property "Test1" of type "ProcessComponentSet".

 

I would need to know how it works or another way to do it, I need to call a sub-process inside a for loop.



Thanks.

Like 0

Like

6 comments

Dear Ezequiel,

It is nor recommended to use sub-processes and the processes in general for such purpose. Technically you can call a business process from a business process. But if you correct the code above and execute it  the system will freeze and the processes will block each other. All users meanwhile will not be able to use the system properly.

Please adjust the business-purpose you want to achieve in order to avoid using business-processes or find another architecture solution.

Oliver

Hi, 

I see, I'm trying to send an email inside the loop, but I can't find in any of the existing process how to send an email with a template though a script task.

If someone knows how to do it or has an example, I would appreciate it if you could explain it or show it to me.

Thanks.

Dear Ezequiel,

There is "Send email" BP element you can use to reach your goal. Just select in a message input "Template message" and you will be able to choose what template to use.

 

 

Peter Vdovukhin,

Yes I know, but like I said I need to use it in a for loop, with that I could use it if I had the code to call a sub-process from a script task.

Dear Ezequiel,

As you wrote to bpm'online support, let's continue our conversation there. After resolving your task I will post an answer here.

Here is a simple example I have successfully tested:

A first business process contains only script task with such code:

for(int i = 0; i < 2; i++) {

    var _sendMailId = new Guid("cc1b3e27-4d11-4957-ac40-b22ff5b11aff");

    var _manager = UserConnection.ProcessSchemaManager;

    var _schema = (ProcessSchema)_manager.GetInstanceByUId(_sendMailId);

    var _moduleProcess = _schema.CreateProcess(UserConnection);

    _moduleProcess.SetPropertyValue("UsrTestParameter", "Letter number " + i);

    _moduleProcess.Execute(UserConnection);

}

A second business process with GUID = cc1b3e27-4d11-4957-ac40-b22ff5b11aff contains only Send email element that has a text parameter UsrTestParameter and use this parameter for email subject. The second business process HAS to be compiled to be called from the first business process.

Show all comments