Hello mates !
I'm trying to create a script into a business process to check the SIRET (French Enterprise Number). But I'm having a basic problem: an identifier is expected when I try to compile on line 59
using System.Text.RegularExpressions; string siretNumber = Get<String>("siret"); bool siretValide = Get<bool>("siretValide"); int ttlAddition = 0, cpt = 1; string formatInput = Regex.Replace(siretNumber, "[^a-zA-Z0-9_]+", "", RegexOptions.Compiled); string reverseCard = new string(formatInput.ToCharArray().Reverse().ToArray()); int[] arrDigits = Array.ConvertAll<string, int>( System.Text.RegularExpressions.Regex.Split(reverseCard.ToString(), @"(?!^)(?!$)"), str => int.Parse(str) ); int[] arrMult = new int[arrDigits.Length]; // First Luhn step: // Start with the last digit (on the right) // and move to the left, doubling the value of all even-numbered digits for (int i = 0; i < arrDigits.Length; i++) { if (cpt == 1) arrMult[i] = arrDigits[i]; // the key is processed first, the number is not doubled else { if (cpt % 2 == 0) arrMult[i] = 2 * arrDigits[i]; else arrMult[i] = arrDigits[i]; } cpt++; } // Add together all the digits of each number thus obtained. // If digit > 10, then the digit to be added gives, for example: 18 = 1 + 8 for (int i = 0; i < arrMult.Length; i++) { if ((int)arrMult[i] >= 10) // if number > 9 you have to break down the number, e.g. 18 gives: 1+8 { int[] intList = Array.ConvertAll<string, int>( System.Text.RegularExpressions.Regex.Split(arrMult[i].ToString(), @"(?!^)(?!$)"), str => int.Parse(str) ); for (int j = 0; j < intList.Count(); j++) { ttlAddition += (int)intList[j]; } } else ttlAddition += (int)arrMult[i]; } // if modulo by 10 of the addition is zero then our figure is valid if (ttlAddition % 10 == 0) Set<bool>("siretValide", true); // set the variable siretValide to true in Creatio else Set<bool>("siretValide", false);
In VS Code, by replacing the last lines: Set<bool>("siret Valide", true);
with Console.WriteLine("Verification OK");
and Set<bool>("siret Valide", false);
with Console.WriteLine("Verification KO");
the program works fine.
Like
Hello,
You can add using statement in Usings section in Methods block Of BP like this:
Also here is the fixed example of your code without compilation errors:
string siretNumber = Get<String>("siret"); bool siretValide = Get<bool>("siretValide"); int ttlAddition = 0, cpt = 1; string formatInput = Regex.Replace(siretNumber, "[^a-zA-Z0-9_]+", "", RegexOptions.Compiled); var formatInputCharArray = formatInput.ToCharArray(); Array.Reverse(formatInputCharArray); string reverseCard = new string(formatInputCharArray); int[] arrDigits = Array.ConvertAll<string, int>( System.Text.RegularExpressions.Regex.Split(reverseCard.ToString(), @"(?!^)(?!$)"), str => int.Parse(str) ); int[] arrMult = new int[arrDigits.Length]; // First Luhn step: // Start with the last digit (on the right) // and move to the left, doubling the value of all even-numbered digits for (int i = 0; i < arrDigits.Length; i++) { if (cpt == 1) arrMult[i] = arrDigits[i]; // the key is processed first, the number is not doubled else { if (cpt % 2 == 0) arrMult[i] = 2 * arrDigits[i]; else arrMult[i] = arrDigits[i]; } cpt++; } // Add together all the digits of each number thus obtained. // If digit > 10, then the digit to be added gives, for example: 18 = 1 + 8 for (int i = 0; i < arrMult.Length; i++) { if ((int)arrMult[i] >= 10) // if number > 9 you have to break down the number, e.g. 18 gives: 1+8 { int[] intList = Array.ConvertAll<string, int>( System.Text.RegularExpressions.Regex.Split(arrMult[i].ToString(), @"(?!^)(?!$)"), str => int.Parse(str) ); for (int j = 0; j < intList.Length; j++) { ttlAddition += (int)intList[j]; } } else ttlAddition += (int)arrMult[i]; } // if modulo by 10 of the addition is zero then our figure is valid if (ttlAddition % 10 == 0) Set<bool>("siretValide", true); // set the variable siretValide to true in Creatio else Set<bool>("siretValide", false); return true;
Also please make sure that "siret" and "siretValide" parameters have the values assigned before this Script Task is executed.
Hello
In a task script, you're not allowed to add the using statements.
Also, the script must end with:
return true;
You can add the using statements at the Methods block in the BP.
Hope this helps!
Mohamed Ouederni,
Hello Mohamed,
Thank you for your help ! i m a newbie in C#.
So i followed your recommandations:
i removed the using System.Text.RegularExpressions; at the script beginning, because when i open the process source code there is allready a using System.Text
i added a return true at the end of the script.
and i added too System.Text.RegularExpressions on the formatInput string :
string formatInput = System.Text.RegularExpressions.Regex.Replace(siretNumber, "[^a-zA-Z0-9_]+", "", System.Text.RegularExpressions.RegexOptions.Compiled);
But now i have the following errors:
Line 65 is :
string reverseCard = new string(formatInput.ToCharArray().Reverse().ToArray());
Hello,
You can add using statement in Usings section in Methods block Of BP like this:
Also here is the fixed example of your code without compilation errors:
string siretNumber = Get<String>("siret"); bool siretValide = Get<bool>("siretValide"); int ttlAddition = 0, cpt = 1; string formatInput = Regex.Replace(siretNumber, "[^a-zA-Z0-9_]+", "", RegexOptions.Compiled); var formatInputCharArray = formatInput.ToCharArray(); Array.Reverse(formatInputCharArray); string reverseCard = new string(formatInputCharArray); int[] arrDigits = Array.ConvertAll<string, int>( System.Text.RegularExpressions.Regex.Split(reverseCard.ToString(), @"(?!^)(?!$)"), str => int.Parse(str) ); int[] arrMult = new int[arrDigits.Length]; // First Luhn step: // Start with the last digit (on the right) // and move to the left, doubling the value of all even-numbered digits for (int i = 0; i < arrDigits.Length; i++) { if (cpt == 1) arrMult[i] = arrDigits[i]; // the key is processed first, the number is not doubled else { if (cpt % 2 == 0) arrMult[i] = 2 * arrDigits[i]; else arrMult[i] = arrDigits[i]; } cpt++; } // Add together all the digits of each number thus obtained. // If digit > 10, then the digit to be added gives, for example: 18 = 1 + 8 for (int i = 0; i < arrMult.Length; i++) { if ((int)arrMult[i] >= 10) // if number > 9 you have to break down the number, e.g. 18 gives: 1+8 { int[] intList = Array.ConvertAll<string, int>( System.Text.RegularExpressions.Regex.Split(arrMult[i].ToString(), @"(?!^)(?!$)"), str => int.Parse(str) ); for (int j = 0; j < intList.Length; j++) { ttlAddition += (int)intList[j]; } } else ttlAddition += (int)arrMult[i]; } // if modulo by 10 of the addition is zero then our figure is valid if (ttlAddition % 10 == 0) Set<bool>("siretValide", true); // set the variable siretValide to true in Creatio else Set<bool>("siretValide", false); return true;
Also please make sure that "siret" and "siretValide" parameters have the values assigned before this Script Task is executed.
Hello Iryna !
This fixed the two first errors.
it looks like system can not find Count, so i added System.link to the method block of the BP and the process has been successfully compiled.
Thank you all for you help !