Is there any formalized documentation on how to create/modify script tasks.

 

To be more specific how would one make use of a process parameter inside a Script task?

Like 0

Like

4 comments

Hello Michael, 

Please, check the following link to find the required information: https://academy.bpmonline.com/documents/technic-bpms/7-14/script-task-process-element

Best regards,

Olga

Olga Avis,

Is there any additional documentation?

Michael Dorfman,

Script tasks - are c# methods inside a business process class. Please feel free to open a source code of a business process with a script task and you'll see a simple c# class. It works according to the native c# documentation.

https://www.oreilly.com/library/view/essential-c-70/9781509303595/

Your second question was completely covered by the article mentioned in the Olga's post.

Eugene Podkovka writes:

Michael Dorfman,

Script tasks - are c# methods inside a business process class. Please feel free to open a source code of a business process with a script task and you'll see a simple c# class. It works according to the native c# documentation.

https://www.oreilly.com/library/view/essential-c-70/9781509303595/

Your second question was completely covered by the article mentioned in the Olga's post.

 In addition to my question is there any documentation on the classes and methods available for use such as reading data in the system using a script task?

Previously I was directed to review existing script tasks but that only explains so much.

Show all comments

Is there a way to read all the users inside an organizational role and then send those email addresses to the next step of a process?

Like 0

Like

2 comments

The functionality can be implemented using a script task element in order to select all contact emails which are included in the role. The contact emails are selected from the database via EntitySchemaQuery. Then join all selected emails into a string using ";" as separator. After that use the newly built string of emails as an email for sending.

The basic business process "Send email to case group" works in the same way. Please feel free to use the business process as an example. Pay attention to the script task element "Prepare Recipient Emails" (https://prnt.sc/p0tv3t).

Show all comments

I am trying to generate a printable from the opportunity object (which will be a quote) and attach this printable to an email after generating.

 

I am getting stuck on the generate and save printable script task. 

This is the error I am getting

Terrasoft.Common.ItemNotFoundException: Value "Name" was not found.
   at Terrasoft.Core.Entities.EntityColumnValueCollection.GetByName(String name)
   at Terrasoft.Core.Entities.Entity.SetColumnValue(String valueName, Object value)
   at Terrasoft.Core.Process.UsrlabSavePrintableAndEmailQuote1Custom6.ScriptTask1Execute(ProcessExecutingContext context)
   at Terrasoft.Core.Process.ProcessFlowElement.Execute(ProcessExecutingContext context)

 

I'm not sure what the issue is. I tried hardcoding the name in the script but that doesn't seem to work either. 

 

My script action that is failing.

var reportService = new Terrasoft.Configuration.ReportService.ReportService();
Terrasoft.Configuration.ReportService.ReportData report = reportService.GenerateMSWordReport(
    (PrintableId.ToString()), ObjectId.ToString(), ConvertToPdf);
var entity = UserConnection.EntitySchemaManager.GetInstanceByName("Opportunity");
var fileEntity = entity.CreateEntity(UserConnection);
fileEntity.SetDefColumnValues();
fileEntity.SetColumnValue("Id", OpportunityId);
fileEntity.SetColumnValue("TypeId", AttachmentType);
fileEntity.SetColumnValue("Name", "ExamplePrintable.docx");
fileEntity.SetColumnValue("Data", report.Data);
fileEntity.Save();
 
 
return true;

 

Let me know if you need any more information.

Also, any documentation where I can read up on this myself. Like the fileEntity variable, or just how this code works in general.

 

Any help is appreciated thanks!

Like 0

Like

1 comments

Hi Tyler,

Implemented this week a very similiar feature throw a business process.

I reversed engeneered this market place app: https://marketplace.bpmonline.com/template/creating-quotes-opportunities

But I used the user task instead of the script task in the processes as I was getting in trouble passing the process parameters to the script task.

 

Hope it helps,

Luis

Show all comments

I am running this code as a script task in a business process.

string POid = Get<string>("PurchaseOrderID");
var arParts = POid.Split('_');
 
 
		int i = Convert.ToInt32(arParts[1]);
		int newid = i + 1;
		string prefix = string.Empty;
		if(newid<10){
			prefix="00000";
		}
		else if (newid<100)
		{ prefix="0000";
		}
		else if (newid<1000)
		{
			prefix="000";
		}
		else if (newid<10000)
		{
			prefix="00";
		}
		else if (newid<100000)
		{
			prefix="0";
		}
 
		string intstringid = newid.ToString();
		string name = prefix + intstringid; 
		string newPOid = "PO_" + name;
		Set("NewPurchaseOrderID", newPOid);
return true;

I have "PurchaseOrderID" and "NewPurchaseOrderID" as the parameters that I've defined for this business process. They are spelled as in the code, I've checked that.

 

When I try to run this process, I get the error: Object reference not set to an instance of an object.

 

Can't seem to find which object I have not initiated.

 

Any help would be appreciated.

 

Thanks.

-AK

Like 0

Like

1 comments

It seems that  "PurchaseOrderID"  parameter has no value, so in the following row

var arParts = POid.Split('_')

the error "Object reference not set to an instance of an object" occurs because POid is null. To know for sure please debug the code. The article by the link below will be helpful in that: https://academy.bpmonline.com/documents/technic-sdk/7-13/server-code-debugging

Show all comments

Hi,

I have a EntityCollection and i would like to know how can i add Objects to that EntityCollection in my ScriptTask.

EntityCollection ec = Get("ProcessParameter1");

var entity;

ec.Add(entity);

Set("ProcessParameter1",ec);

Like 0

Like

1 comments

The Add method is correct. Additionally, I'd not recommend using a simple list instead. 

Show all comments

Hi,

I'm currently trying to obtain the "Id" from one of the contacts in my "Contact" table but I'm getting the same error:

Terrasoft.Common.ItemNotFoundException: Value "Id" was not found.

   at Terrasoft.Core.Entities.EntityColumnValueCollection.GetByName(String name)

   at Terrasoft.Core.Entities.Entity.InternalGetColumnValue(String valueName)

   at Terrasoft.Core.Entities.Entity.GetColumnValue(String valueName)

   at Terrasoft.Core.Process.UsrProcess2MethodsWrapper.ScriptTask1Execute(ProcessExecutingContext context)

   at Terrasoft.Core.Process.ProcessScriptTask.InternalExecute(ProcessExecutingContext context)

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

 

This is the script task i'm using for it:

var result = "";

var userConnection = Get("UserConnection");

    

EntitySchemaManager esqManager = userConnection.EntitySchemaManager;

var rootEntitySchema = esqManager.GetInstanceByName("Contact") as EntitySchema;

var esqResult = new EntitySchemaQuery(rootEntitySchema);

esqResult.AddColumn("Id");

esqResult.AddColumn("Name");

var entities = esqResult.GetEntityCollection(UserConnection);

result = entities[0].GetColumnValue("Id").ToString();



Set("ProcessSchemaParameter1", result);

return true;

Note: If i try to get the "Name" instead i dont get any error.

Like 0

Like

1 comments

Try this

var opportunityCarQuery = new EntitySchemaQuery(UserConnection.EntitySchemaManager,"OpportunityCar");
opportunityCarQuery.AddAllSchemaColumns();
 
var filter = opportunityCarQuery.CreateFilterWithParameters(FilterComparisonType.Equal, "Car", (Guid)carNodeId);
opportunityCarQuery.Filters.Add(filter);
 
var opportunityCarEntities = opportunityCarQuery.GetEntityCollection(UserConnection);
 
foreach (var opportunityCarEntity in opportunityCarEntities)
{
	var theId = opportunityCarEntity.GetTypedColumnValue&lt;Guid&gt;("Id");
}

 

Show all comments

I've created a webservice that passes the received data from my api to a "Collection of Objects with attributes" parameter inside my business process.

I would like to know how can i convert that business process parameter to a JArray.



JArray jarray = Get("ProcessSchemaCadastros");

This is the line i have in my script task to get my data from business process parameter.

Like 0

Like

2 comments
Best reply

I found a way to pass my problem, instead of trying to convert into a JArray i used:

var entities = Get<ICompositeObjectList<ICompositeObject>>("WebService1.UsrWBCadastros_Out");

then i just worked with the data from 'entities'.

 

It's much easier to transfer a JSON from the web service to a text variable in a business process. Then parse the JSON in the business process.

I found a way to pass my problem, instead of trying to convert into a JArray i used:

var entities = Get<ICompositeObjectList<ICompositeObject>>("WebService1.UsrWBCadastros_Out");

then i just worked with the data from 'entities'.

 

Show all comments

Hi, 

 

I want to call a business process from a script task of another business process. I did this because I want to send email to a collection of contacts, so I will do a foreach loop in the script task, and call the second business proces that will send the emails. 

The problem is that the second business process, its call from the first one, and appears in the process log as running, but it doesnt do anything, neither send the mail nor finish running. 

The script task code:

var _sendMailId = new Guid("451f9ef3-2a11-4ca8-9107-02e23e56f9f3");

var _manager = UserConnection.ProcessSchemaManager;

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

var _moduleProcess = _schema.CreateProcess(UserConnection);

_moduleProcess.Execute(UserConnection);



return true;

First business process: Mutiple email sender

 

 

Second Business process: MBS Send Email

Process log:

 

 

Thank you.

 

Javier Collazo

 

Like 0

Like

2 comments
Best reply

The problem here was that the business process that was call form the parent business process, wasn't receiving the parameter. The solution to this problem you can find it in the following question:



https://community.bpmonline.com/questions/calling-business-process-para…

 

Best regards, 

Javier

Hello,



At first you should be confident about business process that sends email is working properly. So, try to start it manually. If it will work, then something is wrong with your script task. Perhaps, you have just missed some parameters that are required in "MBS send email process" 

At second, try to save the process once again and compile the system.



Best regards,

Alex

The problem here was that the business process that was call form the parent business process, wasn't receiving the parameter. The solution to this problem you can find it in the following question:



https://community.bpmonline.com/questions/calling-business-process-para…

 

Best regards, 

Javier

Show all comments

I'm running into some trouble when trying to populate a lookup column from a script task.  I invariably get the error "System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'UsrVMProductCode'."

This is the column in question:

And here is the relevant part of the script task:

var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "UsrWaterplayVMProductCode");
 
var ColId = esq.AddColumn("Id");
var ColName = esq.AddColumn("Name");
 
var entities = esq.GetEntityCollection(UserConnection);
var productCodes = new Dictionary<string,string>();
foreach (var entity in entities) {
	productCodes[entity.GetColumnValue(ColName.Name).ToString()] = entity.GetColumnValue(ColId.Name).ToString();
}
 
foreach (var pd in resultObj.UpdatedParts) {
	if (pd.PartId != "") {
		var code = "";
		if (pd.VMProductCode != "") {
			code = productCodes[pd.VMProductCode];
		}
		var update = new Update(UserConnection, "Product")
			.Set("Name", Column.Parameter(pd.Description))
			.Set("Price", Column.Parameter(pd.Price))
			.Set("UsrProductionCost", Column.Parameter(pd.Cost))
			.Set("IsArchive", Column.Parameter(pd.Inactive));
		if (code != "") {
			update.Set("UsrVMProductCode", Column.Parameter(code));
		}
		update.Where("Code").IsEqual(Column.Parameter(pd.PartId));
		if (update.Execute() > 0) {
			resultUpdate += "Product " + pd.PartId + " updated.\\r\\n";
		}
	}
}

I have confirmed through debug logging that the code variable contains a GUID.  The script also worked fine before I tried to set UsrVMProductCode, while attempting to set another lookup column in this way (Currency) gave a similar error.  Is there something special I need to do to set a lookup value with the Insert/Update objects?

Like 0

Like

2 comments

The use of Update just creates SQL statements that execute on the database directly (instead of using the object model,, like ESQ does). For a lookup column, the actual column name would have "Id" at the end of it. For example, use "UsrVMProductCodeId" instead of just "UsrVMProductCode".

Ryan

Ryan Farley,

Thanks much, that did the trick.

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