Hi!

 

I wanted to add a pop-up through a script task and i used this:

 

this.showInformationDialogue("Message");

return true;

 

The problem is that it says that it doesn't recognize showInformationDialogue. I tried to add Terrasoft libraries, but it says that I can't use "using Terrasoft..." in a script task.

 

Does anybody have any idea how I can add a pop-up?

 

Thank you!

Like 0

Like

1 comments
Best reply

The only way this can happen is to send a message to the UI/browser from the script task. On the page or somewhere in the UI you need to listen for that message. Then, when received, display the popup message. 

I have an article here about how to send the message from the backend process/script task to the client: https://customerfx.com/article/sending-a-message-from-server-side-c-to-…

And an article about displaying popup messages from client-side code here: https://customerfx.com/article/displaying-information-confirmation-and-…

Ryan

The only way this can happen is to send a message to the UI/browser from the script task. On the page or somewhere in the UI you need to listen for that message. Then, when received, display the popup message. 

I have an article here about how to send the message from the backend process/script task to the client: https://customerfx.com/article/sending-a-message-from-server-side-c-to-…

And an article about displaying popup messages from client-side code here: https://customerfx.com/article/displaying-information-confirmation-and-…

Ryan

Show all comments

Hi!

 

I found this article where you can add a 'Refresh page' through a script task in a process. It uses this: "Terrasoft.Configuration.MsgChannelUtilities.PostMessageToAll("FXRefreshContactPage", "");"

How to Refresh a Page from a Process in Creatio (formerly bpm’online) | Customer FX

 

Is there a way to do the same for adding a po-up?

I tried with "this.showInformation()" but it doesn't work.

 

Also, I tried the Add-on from the Marketplace but it doesn't work.

 

Thank You!

Like 0

Like

1 comments

Hello,

 

You need to add the client-side handler method for the received message from the server (using ClientMessageBridge described here) and in this method handler (like onNewUserSet in the example) call the showInformation method and display the popup.

Show all comments

Hi, 

 

I'd liket to create a script task in a business process, that given an email template, it executes it on a specific context. I mean, if the email template is based on a custom macro related with the Lead entity, I can pass the LeadID and the emailTemplateId to the script task, and the result is the text of the email template executed for that specific lead. 

Is there way to do that?

Thanks!
Ignacio 

Like 0

Like

4 comments

Hi Ignacio,

 

You can pass LeadId and the TemplateId as process parameters (create two Guid parameters in the process settings). Then you can use the "Read data" element and read specific columns of the lead record (use the LeadId parameter in the "Read data" filtration to get the value for needed columns). Then you can create additional text parameters and pass the read column values to them (using formulas for example). The same approach is for the "Email template" object and TemplateId parameter (you need to get the template body, so you need to read it in the "Read data" process element). And finally you can use string interpolation (or String.Replace method) in the script task to replace macroses (macorses, not their values, like [#UsrSomeColumn#], it's passed in the template body) with the actual values read from the "Lead" object using the "Read data" element (the ones that we wrote to the process parameters). To get process parameters values in the script task you need to use Get<string>("ParameterCode") (see more examples here) construction in the script task, then you can use String.Replace in the following manner:

string UsrStringParameterValueToUse = Get&lt;string&gt;("UsrStringParameterValue");
string EmailTemplateBody = Get&lt;string&gt;("UsrEmailTemplateBodyParamter");
EmailTemplateBody= EmailTemplateBody.Replace("[#UsrSomeColumn#]", UsrStringParameterValueToUse);

And then you can return EmailTemplateBody to some another string parameter value using Set<string> command and as a result you will get the result needed.

Thank you for your response Oleg!

 

Right, that would be the "manual" approach. I was hoping I could reuse the same service that is being used when creating an email from a template. For example, I can use a ReportService to generate a printable inside a business process. I was hoping that we have in Creatio something like "EmailService" that processes an email template and returns the generated text.

Pavel Shkomov,

 

You need to use the script-task to send the email from the code directly. Please see this Academy article that describes how to form and send the email from the code (this article also have examples of implementations, please use the "Examples" tab at the top of the article).

Ignacio Alvarez,

 

there is another approach:

var macrosHelperClassFactory = ClassFactory.Get&lt;MacrosHelperV2&gt;(new ConstructorArgument("userConnection", UserConnection));
 
string emailTemplateCode = Get&lt;string&gt;("ResultEmailTemplatePlain");
string templateEntityName = Get&lt;string&gt;("ContactEntityName");
Guid templateEntityId = Get&lt;Guid&gt;("ContactRecordId");
 
var replacementResult = macrosHelperClassFactory.GetTextTemplate(emailTemplateCode, templateEntityName, templateEntityId);
Set&lt;string&gt;("ResultEmailTemplateHTML", replacementResult);
return true;

There should be also the following parameter values:

1) the code is ContactEntityName - Text (50 characters) data type ("Contact" value by default) - represents the object from which data for macros is selected

2) the code is ContactRecordId - Unique identifier data type - represents the record Id to get data for macroses

3) the code is ResultEmailTemplateHTML - Unlimited length text data type - contains the template with filled macroses

4) the code is ResultEmailTemplatePlain - Unlimited length text data type - contains the template without filled macroses

 

Also you need to add the following namespaces to the process usings:

Terrasoft.Configuration.Utils

Terrasoft.Core.Factories

 

You need to use the "Read data" process element and read specific email template (the object is "Message template") and you need only the "Body" column value. Then the read body of the template should be passed to the "ResultEmailTemplatePlain" parameter using the "Formula" process element.

 

As a result of the script-task process element you will get the formed email template body with filled macroses in the ResultEmailTemplateHTML parameter that can be then displayed for example using the autogenerated page.

Show all comments

Hi,

I want to use function that are not included in System library/package.

I need to add the following in order to use the functions.

using System.Linq;

I tried adding this to the script but got an error message: " Feature 'using declarations' is not available in C# 7.3. Please use language version 8.0 or greater."

Is there a way to add the 'System.Linq' somewhere?

Thanks,

Chani

 

Like 0

Like

1 comments

Hi Chani,

 

This error means that either the .Net Framework version in your server where the app is hosted is not 4.7.2 and higher or .Net Core version is not 3.1.301 and higher. Also you need to double-check that all the required components were enabled in the IIS settings.

 

Best regards,
Oscar

Show all comments

In the previous versions of Creatio, In the User Task element there was the Script where you could implement the task logic, as shown in the image below

In which part of the User Task Source code , in the 7.18 Version of Creatio, should I implement the same logic ? 

 

Like 0

Like

3 comments

Hello Petrika,

 

Thank you for your question!

 

You can read more on this here:

https://academy.creatio.com/docs/user/bpm_tools/process_elements_refere…

 

Kind regards,

Anastasiia

Anastasiia Lazurenko,

Thank you Anastasia for your quick reply. But this is a different approach. I am not asking about the Script Task, but about the User Task.Because i want to use my logic in different bussiness processes.

Dear Petrika,

 

This logic is still the same. Please refer to the screenshots below:

 

 

Kind regards,

Anastasiia

Show all comments

Hi,

I read collection of records using this script:

var entities = Get<ICompositeObjectList<ICompositeObject>>("ReadDataUserTask2.ResultCompositeObjectList");
I want to loop through this list and set parameter with type contact to each object of the list.

The collection of records is a list of opportunityContact.

I tried converting each ICompositeObject to opportunityContact using this script:

foreach (var entity in entities)
{
 ...
    OpportunityContact contactInOpp = (OpportunityContact)entity;

    Set("contact",contactInOpp.Contact);

but OpportunityContact is not a known object.

How do I access the types of the tables (no need to add data to DB or search just get the type in order to convert)?

Thanks,

Chani

 

Like 0

Like

2 comments

Hi Chani,

 

Here is a working example of two cases: set the string parameter value from the process that reads the collection and also modify contacts massively in the script task based on the received collection.

 

Here is the screenshot of the main process:

and the screenshot of the sub-process:

The idea of the sub-process is to read the collection of 4 records and their emails, Ids and Names if to be more specific. Then the read values are passed to the main process as a collection and go to the main process parameters (see that the "OutputParameters" parameter has the value of "[#SubProcess that will read all the needed data from Contacts 1.OutputRecordCollection#]").

 

The script task itself calls the ProcessContactNames method that is specified in the main process "Methods" tab:

The listing of the code is below:

public void ProcessContactNames() {
	string result = "";
	var contactsList = Get&lt;ICompositeObjectList&lt;ICompositeObject&gt;&gt;("OutputParameters");
	foreach (ICompositeObject item in contactsList) {
				item.TryGetValue&lt;string&gt;("FullNameParameter", out string ContactName);
				item.TryGetValue&lt;string&gt;("EmailParameter", out string ContactEmail);
				item.TryGetValue&lt;Guid&gt;("IdParameter", out Guid ContactId);
				result = result + " " + ContactName + " " + ContactEmail + ", ";
				ContactName = "Oscar Dylan from process";
					var contactSchema = UserConnection.EntitySchemaManager.GetInstanceByName("Contact");
					var entity = contactSchema.CreateEntity(UserConnection);
						entity.FetchFromDB("Id", ContactId);
						entity.SetColumnValue("Name", ContactName);
						entity.Save();
			}
Set&lt;string&gt;("StringParameter", result);
}

Also add the following usings to your main process:

System.Data
System.Security
Terrasoft.Configuration

The idea here is to pass the collection of records from the "OutputParameters" main process parameter, process each record in the foreach cycle, compose the result string that then will be displayed on the autogenerated page to check if the process worked and also find each contact by its Id that was passed from the collection and set the name column value for each contact as "Oscar Dylan from process".

 

As a result the process worked perfectly:

and contact names were modified:

Please analyze the process and use the same approach on your side.

 

Best regards,

Oscar

Oscar Dylan,

Thank you. 

Will try that.

Show all comments

Hi everyone,

I have created a script task to create new records from a csv.

I am trying to implement a method to search the db for a matching record and then update it (in case it exists).

The second part (the 'else' part, it's working fine) 

Does anybody know how to filter and search a DB table? What am I getting wrong?

 

 

void saveLine(string line, int rowNumber){
    if(rowNumber!=0)
    {
        string lineFormatted = line.Replace("\"", "");
        string[] lineSplitted = lineFormatted.Split(',');
        var LRNMBL = lineSplitted[0];
        var LRRIGA = lineSplitted[1];
        var LRDTBL = lineSplitted[3];
        var LRCANA = lineSplitted[6];
        // Creation of query instance with "Contact" root schema. 
       
        // An EntitySchemaQuery instance that accesses the UsrTestFTPCall table of the database.
        var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "UsrVedniteTestate");
        
       
        // Adding columns to the query.
        esq.AddColumn("UsrLRNMBL");
        esq.AddColumn("UsrLRRIGA");
        esq.AddColumn("UsrLRDTBL");
        esq.AddColumn("UsrLRCANA");

        // Filter the query data. according to LRNMBL and 
        var esqFirstFilter = esq.createColumnFilterWithParameters(Terrasoft.ComparisonType.EQUAL,"UsrLRNMBL", LRNMBL);
        var esqSecondFilter = esq.createColumnFilterWithParameters(Terrasoft.ComparisonType.EQUAL,"UsrLRRIGA", LRRIGA);
        
        esq.filters.logicalOperation = Terrasoft.LogicalOperatorType.AND;
        
        esq.filters.add("esqFirstFilter", esqFirstFilter);
        //esq.Filters.Add(esqSecondFilter);
          
      
        // Get the result of the query.
        var entities = esq.GetEntityCollection(UserConnection);
        // If the data is received.
        if (entities.Count > 0)//Record exists in the db --> update
        {
           var recordToUpd = entities[0];
           recordToUpd.SetColumnValue("UsrLRNMBL", LRNMBL);
           recordToUpd.SetColumnValue("UsrLRRIGA", LRRIGA);
           recordToUpd.SetColumnValue("UsrLRDTBL", LRDTBL);
           recordToUpd.SetColumnValue("UsrLRCANA", LRCANA);
        }
        else 
        {
            //the record doesn't exist --> Create one
               var TestObj = UserConnection.EntitySchemaManager.GetInstanceByName("UsrTestFTPCall").CreateEntity(UserConnection);
            //access the data position and assign it to its column
            TestObj.SetDefColumnValues();
            //Associate new column values to old Col values
            TestObj.SetColumnValue("UsrName", rowNumber.ToString());
            TestObj.SetColumnValue("UsrLRNMBL", LRNMBL);//riferimento testata di vendita
            TestObj.SetColumnValue("UsrLRRIGA", LRRIGA);//riferimento riga all'interno della stessa vendita
            TestObj.SetColumnValue("UsrLRDTBL", LRDTBL);
            TestObj.SetColumnValue("UsrLRCANA", LRCANA);
            TestObj.Save();
           }
    }
}
 

Like 0

Like

4 comments

Hello,

I don't see anywhere in the code where you're saving the updates made to the entity in recordToUpd. Try adding the following to have it save the values in the database:

recordToUpd.UpdateInDB();

Ryan

Hello Federica,

Yes, try to add the method that Ryan recommended you. It will help to resolve the issue.

Best Regards,
Tetiana

Hi Ryan,

 

The problem is to access and filter records in the db.

That part of the script ain't working.

Hi Tetiana Bakai,

The main issue atm lays in the filtering and db-access part.

Show all comments

Hi everyone, 

I am setting up a Business process in order to create new records in a custom section. The data is stored in a List<string[ ]> returned by a method. 

How can I loop through the collection and create new entities based on the values I need?

Like 2

Like

1 comments

Problem solved by moving the code block inside of a function called in the method that loops through the collection. 

Show all comments

При попытке добавления блока с пользовательским кодом возникает ошибка
An attempt to add a script task causes an error

System.InvalidCastException: Specified cast is not valid.
   at Terrasoft.Core.Process.ProcessModel.GetParameterValue[T](FoundParameterData result)
   at Terrasoft.Core.Process.Process1MethodsWrapper.ScriptTask1Execute(ProcessExecutingContext context)
   at Terrasoft.Core.Process.ProcessScriptTask.InternalExecute(ProcessExecutingContext context)
   at Terrasoft.Core.Process.ProcessFlowElement.Execute(ProcessExecutingContext context)

Сам код в блоке выглядит так: 
The code itself looks as following:

double result = Get&lt;double&gt;("amount") * Get&lt;float&gt;("rate") / Get&lt;int&gt;("division");
Set("result", result);
return true;

У меня нет опыта работы с BPMN, поэтому я не знаю, где именно я ошибся. Всё, что делают формулы - это запись данных из справочника в параметры процесса.
Заранее спасибо!

I'm totally new to BPMN so I have no idea where the error may be. The formulas only save lookup values into process parameters. 
Thanks in advance!

File attachments
Like 0

Like

2 comments

By the way, if there is a list of data type matches for decimal values (as I understood, float does not match all of them), I would really appreciate a link.
Кстати, если существует список соответствий типов данных для дробных значений (как я понял, float подходит не для всех), я был бы очень благодарен за ссылку.

Я нашёл необходимый тип данных, им оказался decimal. Вопрос можно закрыть
Вот ссылка на перечнь соответствующих типов:
Элемент процесса [Задание-сценарий] | Creatio Academy (terrasoft.ru)
I've found the necessary data type, it turned out to be decimal.
Above there is a link to a list of data type matches

Show all comments

Hi All,

Can some one suggest a better approach to loop through multiple records and modify them. Please note that the trigger is coming from Signal (Record Added).

 

Basically, I am trying to add multiple records using Multi-select lookup detail built using LookupMultiAddMixin.

Reference - https://academy.creatio.com/documents/technic-sdk/7-15/adding-multiple-records-detail?_ga=2.11560502.366292848.1628844467-134737415.1626226816 

This is configured in a custom detail and on add, business process places that many number of rows to that detail. Now based on the detail object specific column value, I want to update all the contact records that is mapped with that detail.

 

But what I notice is it is updating only 1 record. Kindly suggest how this could be achieved.

 

Like 0

Like

2 comments

Hi Anupama, 

 

One of the ways to create a loop in your process to work with the collection of records is  to create a sub-process and pass the collection into the subprocess. 
You can refer to the example below and create the process you need: 

 

 

Signal "Contact Added" element: 

Read Data "Read Contact" element:

 

 

For the sub-process, you would need to specify the [Parameters] of it:

 

 

And make a filter of the element within the sub-process based on the ID:

And finally, you would need to specify this parameter in the parent Business Process:

 

 

You may also find these academy Articles useful:

 

https://academy.creatio.com/docs/user/bpm_tools/process_elements_refere…

 

https://academy.creatio.com/docs/user/bpm_tools/bpm_process_examples/us…

 

Hope this helps!

 

Thank you!

 

Regards,

Yurii

Danyil 

Thanks Yurii Sokil for the detailed instruction and the sequential  Execution Mode is something I haven't tried it before. Would definitely try that.

 

In between I tried another approach where-in at the entry point where the Signal action is placed, I unchecked the option of "Run following elements in the background". With this, until the process is completed, I was able to read the required values and add/edit/delete multiple records.

 

 

Show all comments