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
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:
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.