Duplicates in sales orders
theinvisibleduck
So I have spent to long messing with this and have been unable to get it to work. I want to use Easy Functions to return a list of the duplicate sales orders as they are entered and I keep running into issues with just getting the sql setup to tell if their are duplicate items.I have tried
SELECT CASE WHEN COUNT ('$[$38.1.0]') > '1' THEN '@@Condition1' ELSE '@@Condition2' END
and I have tried a few variations of:
IF '(select '$[$38.1.0]', Count (*)
FROM RDR1
Group By '$[$38.1.0]'
Having Count (*)>1)' SELECT '@@Condition1' ELSE SELECT '@@Condition2'
Anders Olsson
Hello,Unfortunately it is not so easy because the matrix has to be scanned (all lines) to check for item codes. Here is a solution using EasyFunctions and C#:
1. Create an Optimizer rule of type EasyFunction. Trigger form: 139, item: 38, column: 1. EventType: Validate. Tick Before event.
2. In the EasyFunction, use this SQL: SELECT '@@CheckDuplicateItems'
3. In the Parameters and Functions tab, click Get Parameters from Query to add a new row.
4. Set rule type to C#
5. Use the following code:
[CODE]
try
{
System.Collections.Generic.List<string> items = new System.Collections.Generic.List<string>();
Matrix matrix = Matrix.GetFromUID(pVal.Form, "38");
for (int i = 0; i < matrix.Rows.Count; i++)
{
string itemCode = matrix.GetValue("1", i);
if (items.Contains(itemCode))
{
MessageBox.Show("Duplicate items not allowed.", "OK");
SwissAddonFramework.Global.SAPAction = false;
return false;
}
items.Add(itemCode);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "OK");
}
return true;[/CODE]
Regards,
Anders
Paolo Manfrin
Hi "theinvisibleduck",we will investigate the use case you provided extending the EasyRowFunction possibilities to be able to cover it without code needed.
In the meantime the sample provided by Anders above gives you a solution.
Kind Regards,
paolo
theinvisibleduck
Thank you! This helps so much. I unfortunately have more experience programming in languages other than c# so this could be fun. Ideally I want this check to occur on attempt to save/update the form and to allow the duplicates, just display a message box that says which items are duplicates and click okay to proceed.I tried changing the following section to:
[color=#666600]{[/color]
[color=#660066]DialogResult dialogResult = MessageBox[/color][color=#666600].[/color][color=#660066]Show[/color][color=#666600]([/color][color=#008800]"Duplicate items not allowed."[/color][color=#666600],[/color][color=#000000] [/color][color=#008800]"OK", messageboxbuttons.YesNo[/color][color=#666600]);
dialogResult==(DialogResult.Yes)
[/color]{
MessageBox.Show("test1")
[color=#660066]}
else if(dialogResult==DialogResult.No)
{
MessageBox.Show("test2")
}
SwissAddonFramework[/color][color=#666600].[/color][color=#660066]Global[/color][color=#666600].[/color][color=#660066]SAPAction[/color][color=#000000] [/color][color=#666600]=[/color][color=#000000] [/color][color=#000088]false[/color][color=#666600];[/color]
[color=#000088]return[/color][color=#000000] [/color][color=#000088]false[/color][color=#666600];[/color][color=#000000]
[/color][color=#666600]}[/color]
and while the code parses fine it gives me an error when I run it and tells me else is an invalid expression term and that I am missing a ;
Any thoughts on how to move this towards where I am looking to get it, I would REALLY appreciate.
Thank you!
theinvisibleduck
I found this on the forum and realized I was going about it the wrong way. Now I just need to massage it into being on update, adding in a list of the duplicate ItemCodes, and change the code so that it saves instead of opening a new Sales Order.// click contains the passed parameter from the messagebox
SwissAddonFramework.UI.Dialogs.MessageBox.Buttons click = SwissAddonFramework.UI.Dialogs.MessageBox.Show("Do you want to allow duplicates?", "Yes", "No", SwissAddonFramework.UI.Dialogs.MessageBox.Buttons.Button2);
// Query of click, when 'yes' was clicked the fax-menu opens
if (click == SwissAddonFramework.UI.Dialogs.MessageBox.Buttons.Button1)
MenuItem.GetFromUID("6659").Activate();
return true;
theinvisibleduck
If I could just get ExecuteSAPAction=false to work, I think I would have this basically done.My Current Code Im working on looks like this(I have tried a few similar variations):
if (items.Contains(itemCode))
{
// click contains the passed parameter from the messagebox
SwissAddonFramework.UI.Dialogs.MessageBox.Buttons click = SwissAddonFramework.UI.Dialogs.MessageBox.Show("Do you want to allow duplicates?", "Yes", "No", SwissAddonFramework.UI.Dialogs.MessageBox.Buttons.Button2);
// Query of click, when 'yes' was clicked the fax-menu opens
if (click == SwissAddonFramework.UI.Dialogs.MessageBox.Buttons.Button2);
{
ExecuteSAPAction = false;
}
if (click == SwissAddonFramework.UI.Dialogs.MessageBox.Buttons.Button1);
return true;
}
0
Please sign in to leave a comment.
Comments
0 comments