I have created a script to turn integers into words and it keeps compiling with errors.

 

heres the script:

 

using System;
using System.Text;
using Terrasoft.Core;
using Terrasoft.Core.Entities;
using Terrasoft.Core.Process;

public class ConvertCurrencyToTextTask : ProcessUserTask
{
   // ✅ Constructor
   public ConvertCurrencyToTextTask(ProcessExecutingContext context) : base(context) { }

   // ✅ Main execution method (Runs when the Script Task is triggered)
   public override bool CompleteExecuting(UserConnection userConnection)
   {
       try
       {
           // ✅ Retrieve the requested amount from the process parameter
           decimal requestedAmount = Get("DfcReqAmt");

           // ✅ Retrieve the dynamically fetched record ID
           Guid recordId = Get("Id");

           // ✅ Convert the numeric amount to words
           string convertedText = ConvertToWords(requestedAmount);

           // ✅ Store the result in the output parameter
           Set("DfcRequestedAmountText", convertedText);

           // ✅ Update the record in the FinApplication object
           UpdateRecord(userConnection, recordId, convertedText);
       }
       catch (Exception ex)
       {
           throw new Exception("Error in ConvertCurrencyToTextTask: " + ex.Message);
       }

       
   }

   // ✅ Converts numbers to words (DYNAMIC)
   private string ConvertToWords(long number)
   {
       if (number == 0)
           return "Zero";

       if (number < 0)
           return "Negative " + ConvertToWords(Math.Abs(number));

       string words = "";
       int thousandIndex = 0;

       while (number > 0)
       {
           if (number % 1000 != 0)
           {
               words = ConvertHundreds(number % 1000) + Thousands[thousandIndex] + " " + words;
           }
           number /= 1000;
           thousandIndex++;
       }

       return words.Trim();
   }

   // ✅ Converts hundreds, tens, and ones
   private string ConvertHundreds(long number)
   {
       string words = "";

       if (number >= 100)
       {
           words += Ones[number / 100] + " Hundred ";
           number %= 100;
       }

       if (number >= 10 && number <= 19)
       {
           words += Teens[number - 10] + " ";  // ✅ Corrected indexing for Teens
       }
       else
       {
           words += Tens[number / 10] + " ";
           words += Ones[number % 10] + " ";
       }

       return words.Trim();
   }

   // ✅ Updates the record with the converted text
   private void UpdateRecord(UserConnection userConnection, Guid recordId, string convertedText)
   {
       if (recordId == Guid.Empty) // ✅ Ensures ID is valid before updating
           throw new Exception("Record ID is empty, cannot update record.");

       var entitySchema = userConnection.EntitySchemaManager.GetInstanceByName("FinApplication");
       var entity = entitySchema.CreateEntity(userConnection);

       if (entity.FetchFromDB(recordId))
       {
           entity.SetColumnValue("DfcRequestedAmountText", convertedText);
           entity.Save();
       }
   }

   // ✅ Number arrays (DYNAMIC)
   private readonly string[] Ones = { "", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
   private readonly string[] Teens = { "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
   private readonly string[] Tens = { "", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
   private readonly string[] Thousands = { "", "Thousand", "Million", "Billion", "Trillion" };
} // ✅ Class correctly closed

 

 

return true; // ✅ Ensures method completes properly
 

 

 

 

these are the errors I am getting:

 

DfcProcess_25a93f1.DfcLoans.cs    Identifier expected    CS1001    34
DfcProcess_25a93f1.DfcLoans.cs    Identifier expected    CS1001    33
DfcProcess_25a93f1.DfcLoans.cs    Identifier expected    CS1001    35
DfcProcess_25a93f1.DfcLoans.cs    Type or namespace definition, or end-of-file expected    CS1022    151
DfcProcess_25a93f1.DfcLoans.cs    } expected    CS1513    36
DfcProcess_25a93f1.DfcLoans.cs    Identifier expected    CS1001    32
DfcProcess_25a93f1.DfcLoans.cs    Identifier expected    CS1001    36

 

Not sure what is missing as far as syntax goes, all bracket appear to be in place.

 

Appreciate the help in advance.

 

 

 

 

Like 1

Like

4 comments

Hi,

 

The error is related to the business proceess DfcProcess_25a93f1. Can you share a source code for the business process, not the user task you shared? You can get the source code of the business process here:

There was no source code?

Hello,
 

In this case, do you perform development on a local environment?

If so, could you search for the schema in the {rootAppFolder}\Terrasoft.WebApp\Terrasoft.Configuration\Pkg\DfcLoans\Autogenerated\Src\DfcProcess_25a93f1.DfcLoans.cs directory?

You can also find the location of the file that causes compilation errors if you look at the application logs (Build.log) for the day of compilation and errors.

Show all comments

Hello,

 

I have an API where I receive some data that I want to insert in a table. The problem is that the table is not in the default schema 'dbo'. The API fails because it says that it cannot find the object 'dbo.LIBRA.MBK_TABLE'. It should read only 'LIBRA.MBK_TABLE'.
 

}
       private int ExecuteInsert(string customerId, DateTime lastConnectionDate)
        {
            var select = new Select(SystemUserConnection)
                               .Column(Func.Count("RecId"))
                               .From("LIBRA.MBK_TABLE")
                               .Where("RecId").IsEqual(Column.Parameter(customerId)) as Select;
           int recordExists = select.ExecuteScalar();
            if (recordExists == 0)
            {
                var insertAccount = new Insert(SystemUserConnection)
                                        .Into("LIBRA.MBK_TABLE")
                                        .Set("RecId", Column.Parameter(customerId))
                                        .Set("LastConnectionDate", Column.Parameter(lastConnectionDate));
                int rowsAffected = insertAccount.Execute();
                if (rowsAffected == 0)
                {
                    throw new Exception("Insert failed: no rows affected.");
                }
                return rowsAffected;
            }
            return 0;
        }

I tried to put .From("LIBRA", "MBK_TABLE") and to put .SchemaName("LIBRA"), but the same error appears.

 

Is there another way of doing this?

Like 0

Like

2 comments

Perhaps you'll need to use direct SQL statements for this? You can see how to do that here: https://customerfx.com/article/executing-direct-sql-statements-in-a-process-or-configuration-web-service-in-creatio-formerly-bpmonline/

Ryan

An additional option to what Ryan proposed - create a table to which you can add data with an API and on the DB level create a trigger that will automatically insert record into the table from the needed namespace in the database.

Show all comments

Clio release 6.1.0.33 provides adding source code schemas to the package via Clio. It can be useful for working with C# code in IDE or Creatio embedded code designer,

 

// Adding source code schemas MySourceCodeSchemaName to package MyPackage
clio add-schema MySourceCodeSchemaName -t source-code -p C:\MyPackage

 

P.S: We plan to add more OOTB templates, the ability to create your own and add a set of different objects for complex cases like using virtual entity

1 comments

Really love the idea of using templates for this. Will make creating configuration services, entity event listeners, and other utility classes much quicker to not have to start from nothing. One of the best ideas!

Thanks ATF/Clio team!

Show all comments

Hi All, 

 

Greetings!

Attaching my source code file.

 

UsrDate -> Date 

UsrStartTime -> Time

CreatedOn -> Date/Time

 

I am getting following error in few records - 

Worklogs Integrations synchronized with errors: {"bd455ee2-8f6e-4aed-bafc-890304110ac3":"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.","3d4508d8-bf40-48b4-ab65-d836c7c0b3da":"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."}

screenshot from the source code is below - 


Screenshot of the record is below - 

 

 

Is it because Start time is NULL ?

If yes how can I handle this in the code so that the records gets synchronized with NULL ?


 

Thanks.

File attachments
Like 0

Like

1 comments

Hello.

I tried to do replicate the same situation. Activity table has a column SendDate which might be null. In business process i created a script task with the following code: 1

The result i got:
1
The values of SendDate columns in my Activity table were all null. All these values became the min value of datetime (1/1/0001 12:00:00 AM).

Your error message says that the datetime type in SQL Server has a limited range for dates it can store, specifically from January 1, 1753, to December 31, 9999. In .NET, the default value for DateTime is DateTime.MinValue, which is January 1, 0001. This default value is far outside the valid range for SQL Server's DateTime type.

After analyzing source code you provided i suggest taking a look at those lines of code and changing your sql command parameter types to SqlDbType.DateTime2:

insertCommand.Parameters.AddWithValue("@usrDate"...
insertCommand.Parameters.AddWithValue("@usrStartTime"...
insertCommand.Parameters.AddWithValue("@createdOn"...

Hope this helps

Show all comments

Is it possible to trigger the Freedom UI Live Data Refresh mechanism (LiveEditing feature) for a specific record from C# code? We have a C# process that is updating data directly in the database for performance reasons, but in certain circumstances we may want to trigger the Live Data Refresh of the record(s). Is this possible in any way? Or do we have to implement a workaround by refreshing from JS code when we think we may have to (so would be over-refreshing and not using the Live Data refresh mechanism).

Like 0

Like

1 comments
Best reply

You can see how that feature works by looking at the "LiveEditingBaseEntityEventListener" source code schema. In initial versions you could see they were just using MsgChannelUtilities.PostMessage and the message name, but in 8.1.2 that has been abstracted away. Still you could execute the same way as implemented in that schema.

Ryan

You can see how that feature works by looking at the "LiveEditingBaseEntityEventListener" source code schema. In initial versions you could see they were just using MsgChannelUtilities.PostMessage and the message name, but in 8.1.2 that has been abstracted away. Still you could execute the same way as implemented in that schema.

Ryan

Show all comments

Greetings Community,

 

     Could someone provide me with references for Script Task queries related to CRUD operations on Creatio objects?

 

      Are there any examples or references available for sample scripts and C# functions regarding the Script Task element suitable for beginners?

Like 0

Like

2 comments

Hello,

 

As the first step, we recommend you to check our Academy article on Script Task process element that includes both instructions and examples of working with it. You can also use Academy and Community for searching examples of implementation of some more specific requests using the key words.

https://academy.creatio.com/docs/8.x/no-code-customization/bpm-tools/pr…

Hello Mira,

 

Thank you for your reply. I have reviewed the Academy article on the Script Task Process element. Also, executed on Creatio platform.

 

I am now interested in learning more about what we can accomplish with the Script Task element. Is there any additional information or examples available for Script element? 

 

regards, 

Ajay

Show all comments

For instance, I've crafted a function to generate a contact:

 

void InsertContact(string contactName) {
   UserConnection userConnection = Get("UserConnection");

   contactName = contactName ?? "Unknown contact";


   var ins = new Insert(userConnection)
       .Into("Contact")
       .Set("Name", Column.Parameter(contactName))
       .Set("JobTitle", Column.Parameter("Consultant"))
       .Set("Notes", Column.Parameter("C# Script Test"));

 

   var affectedRows = ins.Execute();
}

 

However, I desire the function to be more versatile:

void InsertObject(string contactName, string ObjectName, var Object) {


   UserConnection userConnection = Get("UserConnection");

 

   // Generate a query dynamically using Object Name, Contact Object Columns, and Values

   var ins = new Insert(userConnection)
       .Into(ObjectName)
       .Set(Object["key"], Column.Parameter(Object["value"]));

 

   var affectedRows = ins.Execute();
}

This enhanced function can be dynamically utilized within the Script Element.

 

Is it possible to create the dynamic functions in Creatio like this?

 

Like 0

Like

1 comments

Hello, Ajay!

You can implement any logic with the code in the Creatio configuration, and any realization in C# is supported. Your code example looks logical and you can add it to the script task in business process, for example. 
More information about Script tasks:

https://academy.creatio.com/docs/8.x/no-code-customization/bpm-tools/process-elements-reference/system-actions/script-task-process-element

Back-end (C#) development basics:

https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platform/architecture/development-in-creatio/back-end-c-sharp

Also, you can register a background operation by following this article and use it in any part of application:

https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platform/back-end-development/data-operations-back-end/execute-operations-in-the-background/examples/register-a-background-operation

Show all comments

Hello community,

I'm interested in utilizing the Script element within Creatio. Where can I find reference materials or code samples for C#?

 

Additionally, is there a platform available to compile C# code snippets before directly uploading them to the Creatio Platform (in the Script Task Element)?

Like 0

Like

7 comments

Hello,

 

All available examples of using the code in the script task element can be found here. As for checking the C# code - there is no such platform for business processes script tasks. You can create a code in Visual Studio and check if it works. Then, using the provided article, implement the same functionality in the business process script task.

Is it also possible to create your Standard source code and call those from a script task?  Similar to Process to calculate actual working time in projects on schedule?  

Oleg Drobina,

Thanks for your response. Is it feasible to import Terrasoft packages into Visual Studio? If yes, could you provide the steps to do so ?

keith schmitt,

 

as in OOP you can create an instance of a class and use its methods in the logic of a business process. Use Terrasoft.Configuration in the business process (add it to the process usings in the process settings) and create an instance of your class as SomeClass nameOfTheInstance = new SomeClass().

Ajay,

 

You can enable development in the file system as described here and there won't be a need to manually import packages in the Visual Studio. You will be able to review the code and apply changes to it.

Oleg Drobina,

Is there any video reference available?

Ajay,

 

I'm afraid we don't have it, but I will ask our Academy team if they can create such a video tutorial. Thank you for this suggestion!

Show all comments

Is it possible to set the value of a System setting which has the "Save value for current user" setting enabled for a specified user from C# code, e.g. from a script task? I've found the below code for setting a System setting, but presume that if the checkbox for the above is selected, then it will only set the value for the current user (or the System User if running in the system context):

var settingCode = Get<string>("UsrSystemSettingCode");
var value = Get<string>("UsrSettingValue");
Terrasoft.Core.Configuration.SysSettings.SetValue(UserConnection, settingCode, value);
return true;

 

We need to be able to set the per-user system setting for a specific user (determined by data in the BP in our case) but looking at the (always hard to find) API documentation, it doesn't seem like there's an overloaded version of SetValue that allows you to do so as a specified user - except possibly one that is marked as being deprecated in a much older version:

 

Like 0

Like

3 comments

Anybody have any info on this?

Does anyone have any other methods for managing per-user system settings in Creatio? It seems like there aren't a lot of options besides setting them in JS code when a user does a given action, but then that feels like it defeats some of the purpose of system settings being that the value doesn't have to be calculated every time a user does something, and also means it can't reliably be used for tasks like setting a default field value on an entity.

Contemplating using this methodology for running code when a user logs in to set it, hopefully it will work. Would be nice to have some clean way of doing it though, especially since we don't really need to be calculating it every time a user logs in but just when certain data changes: https://customerfx.com/article/executing-code-in-creatio-application-an…

Show all comments

Hi!

 

I am currently working on a functionality that overrides and defines what needs to happen when clicking a button on a detail.

 

This means I am working on a "Source Code" type of file within the configuration, so only C# code involved.

 

I have some trouble debugging the code to see what's wrong besides this message that pops up:

 

I haven't found any debugging tips specifically for this type of "file"/task and I would like to display message boxes with values of variables and so on, just like the one above.

 

I know there is a way to achieve this using business processes and JS code inside the client module, but I haven't found any solution to programatically display this using C# code.

 

Can someone refer me to the class/library where this is located exactly?

 

Thanks,

Laurentiu

Like 1

Like

4 comments

Hello Laurentiu,

 

C# cannot be used to display the popup directly. What can be done is send a websocket message to the client side and display the popup when a websocket message is received. Like described here, but in the onNewMessage method you need to call this.showInformationDialog method (just check how it's called out-of-the-box) and pass the message to it.

If this is a local system you can use debugging with your C# code, see https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platfor…

If this is a cloud system, sending messages to the UI to display a message box isn't the best route since the message boxes aren't blocking, meaning if your code sends 3 messages, only the last one will show in the message box, plus it means you have to add client-side code to receive the message and display it. 

It would be far better to just create a lookup object to write your debug messages to, then you just check the lookup to see the messages. 

Ryan

Ryan Farley,

Do you have an example how to write into a lookup  object please ?

You can write to any object using the following: 

var schema = UserConnection.EntitySchemaManager.GetInstanceByName("AccountType");
var entity = schema.CreateEntity(UserConnection)
entity.SetDefColumnValues();
entity.SetColumnValue("Name", "Some new type");
entity.Save();

 

However, for debugging, even better than writing to an object would be to use logging, see https://customerfx.com/article/logging-information-and-errors-in-creatio-c-code-and-viewing-from-cloud-hosted-systems/

Ryan

Show all comments