Skip to content
+1-888-319-3663

COMMUNITY FORUM

Cannot convert method group : Or why does SC think my first calculated field isn't a decimal?

Chad Bruels asked 3 years ago
“Cannot convert method group ‘_C_BANK_FEES’ to non-delegate type ‘decimal'”
Here is my script for C_BANK_FEES:
string fuzzyValue = _MAKSESELGITUS;
decimal bankFees = 0;
string cleanedCharge = “”;
 
string errorMessage = String.Empty;
string mapId = “SWEDBANK_IMPORT”;
string taskId = “Extract Bank Fee”;
string errorLog = @”C:\SmartConnect\Errors\” + taskId + “_” + System.DateTime.Now.ToString(“yyyyMMddHH”) + “.LOG”;
 
try
{
MatchCollection charges = Regex.Matches(fuzzyValue, @”/CHGS/[A-Z]{3}[0-9]+,.[0-9].”);
 
foreach (Match charge in charges)
{
Match justNumber = Regex.Match(charge.Value, @”[0-9]+,.[0-9].”);
cleanedCharge = justNumber.Value.Replace(‘,’, ‘.’);
bankFees += Convert.ToDecimal(cleanedCharge);
}
 
}
catch (Exception ex)
{
errorMessage = “–” + DateTime.Now.ToShortTimeString() + “–\r\n”;
errorMessage += “Map ID = ” + mapId + “\r\n”;
errorMessage += “Task ID = ” + taskId + “\r\n” + “\r\n”;
errorMessage += “MAKSE SELGITUS = ” + _MAKSESELGITUS + “\r\n” + “\r\n”;
errorMessage += “There was an error trying to identify a bank fee from the source data.”;
errorMessage += “\r\n” + “\r\n”;
errorMessage += ex.ToString() + “\r\n”;
 
using (System.IO.StreamWriter errorExcFile = new System.IO.StreamWriter(errorLog, true))
{
errorExcFile.WriteLine(errorMessage);
}
}
 
Here is the next calculated field in which I try to use the C_BANK_FEES value:
decimal sub = _SUBTOTAL;
decimal fees = _C_BANK_FEES;
decimal total = sub + fees;
 
return total;
Chad Bruels replied 3 years ago

The final return command in the C_BANK_FEES script did not copy. It ends with :
return bankFees;

Chris Dew replied 3 years ago

Chad, I have a couple of comments. The first is that you must fully qualify the Regex calls (ie System.Text.RegularExpressions.Regex.Matches) unless you have imported that assembly previously. Also, it does appear that the Microsoft compiler we are using for C# is interpreting the calculated field differently than the VB.NET method (I tried your script in both!) My recommendation for now is to simply use a Global Variable in the first script that you set to bankFees and then reference the Global Variable in the second script.

Chad Bruels replied 3 years ago

I have included System.Text.RegularExpressions in the Default Script Namespaces window. I’m assuming that is enough as I had validation errors cleaned up after doing so.

Chad Bruels replied 3 years ago

Well, now I have the problem that every row is calculating a bankFees of zero. I’ve tested the code in a Visual Studio project so I know it works.

Chad Bruels replied 3 years ago

I’ve implemented the global variable solution. However, even just mapping the first calculated field to the Cash Receipt’s transaction description to verify its results shows that it is always zero. Do you have any thoughts as to why?

Chris Dew replied 3 years ago

I have an interesting update. After digging in a bit further we found that if you pass in the calculated field with () on the end, the C# compiler with then compile correctly. Here is an example below with your code:
decimal fees = _C_BANK_FEES();

Chad Bruels replied 3 years ago

That is very interesting. I will try that and report back. Also, I found that my regex pattern was slightly wrong. I was using a period when I should have been using an asterisk in a few places.

Chad Bruels replied 3 years ago

I don’t find that to be working. Please advise. https://www.screencast.com/t/5cRrBeeae

Chris Dew replied 3 years ago

Can you simply set your first script to always return something like 10.00 and then try using that in the next calc field? Additionally, I took your second script and had to unbox it from the object to a decimal like below to get it to work: decimal fees = (decimal)_C_BANK_FEES();

Chad Bruels replied 3 years ago

Can I mark this as answered somehow?


If you would like to submit an answer or comment, please sign in to the eOne portal.