Execute SQL Query from Function Button
Steven Delombaerde
Hello,I am new to CoreSuite Customize. I would like to be able to launch an SQL Query that I have made and stored with Query Generator, from the "Function" button that I have added to the Item Master Data form. I have create the entry in CoreSuite Customize Function table but can only select VB or CS code. What code do I need to run the SQL query and display the results on the screen?
Thanks
Steven
Steven Delombaerde
Does anyone have any ideas?Thanks
Steven
Michael Egloff
Hi Steven,you need a bit of code to display your results. You have to choose CShARP for the type of the rule and enter the code below:
try
{
// GRID, WILL CONTAIN THE VALUES TO DISPLAY
SwissAddonFramework.UI.Components.Grid grid = SwissAddonFramework.UI.Components.Grid.CreateNew("COR_GR1");
grid.Width = 380;grid.Height = 260; grid.Top = 5; grid.Left = 5;
// SAP FORM, WILL CONTAIN THE GRID
SwissAddonFramework.UI.Components.Form form = SwissAddonFramework.UI.Components.Form.CreateNewForm("COR_CUS_SHOW1", "COR_CUS_SHOW1" + SwissAddonFramework.Utils.UniqueStringGenerator.Next());
form.Height = 300; form.Width = 400; form.Top = pVal.Form.Top; form.Left = pVal.Form.Left;
form.Value = "Results";
// ADD GRID TO THE FORM
form.AddItem(grid);
// LOAD FORM
form.Load();
// YOUR QUERY
string query= "SELECT ItemCode, ItemName FROM OITM";
// ATTACH QUERY TO GRID
grid.ExecuteQuery(query);
// SET COLUMNS NON EDITABLE (DISPLAY ONLY)
grid.Columns["ItemCode"].Editable = false;
grid.Columns["ItemName"].Editable = false;
}
catch(System.Exception ex)
{
SwissAddonFramework.UI.Dialogs.MessageBox.Show("Unexpected error happend while trying to display the values of the query!n" + ex.Message, "OK");
}
Replace the line
string query= "SELECT ItemCode, ItemName FROM OITM";
with your query.
And also the lines
grid.Columns["ItemCode"].Editable = false;
grid.Columns["ItemName"].Editable = false;
you have to modify and/or multiply with the columns of your result!
Good luck! :D
Steven Delombaerde
Michael,Excellent! Thank you for your help.
Regards
Steven
Steven Delombaerde
Michael,One more question: how do I have to code the selection criteria in my SQL query to list only records that match a screen field from the current form (in SBO queries you can do that by referring to $[$4.0] for example or to the table/field reference like in $[ordr.docnum])
Can you show in the example?
Thanks
Steven
Steven Delombaerde
Sorry, here again.I also notice that - because the query sits inside the code - you cannot click through on linked fields, say for instance when you have a cardcode in the query results, that you would be able to click through to get the Business Partner.
If this is not possible, is there a way you could reference a query that has been designed with the query manager, and just launch that one from the function button?
Steven
Steven Delombaerde
Michael,Can you have a look at the last 2 questions please?
Thanks
Steven
Michael Egloff
Hello Steven,there are differnet ways to modify this view.
You usally need a workshop to use the coresuite customize at its full power.
If you wish we can do a WebEx (contact me via email: michael.egloff@coresystems.ch) where I can show you some of the possibilities.
Sascha Balke
Hallo Michael,wenn ich einen "OK-Buttom" noch hinzufügen möchte, mit dem ich die Form wieder schließen kann, an welcher Stelle muss ich tätig werden?
Du hattest es mir am Telefon gesagt, nur irgendwie hab ich es vergessen. :(
VG
Sascha
Frank Romeni
Zur Frage von Sascha:Hier mein Code um einen Button unter das Grid zu positionieren.
Ich habe hierzu dai Grid-Höhe etwas reduziert, damit darunter in der Form noch Paltz genug ist.
Der Button selbst macht derzeit nichts.
// nur der geänderte bzw. hinzugefügte Code
// ...
grid.Height = 220;
SwissAddonFramework.UI.Components.Button buttonOK = SwissAddonFramework.UI.Components.Button.CreateNew("X_B1");
buttonOK.Value= "OK";
buttonOK.SetPosition(grid.Left, grid.Top+grid.Height+10);
form.AddItem(buttonOK);
// der restliche Code
// ...
Sascha Balke
Danke MichaelAn welcher Stelle kann ich ihm ein Ereignis z.B. schließen der Form mitgeben?
VG
Sascha
Michael Egloff
hallo Sascha,danke nicht mir, danke Frank! :D
Du kannst dem Button die UID "2" geben, dann ist der automatisch behandelte Schliessen-Knopf von SAP.
SwissAddonFramework.UI.Components.Button buttonOK = SwissAddonFramework.UI.Components.Button.CreateNew("2");
buttonOK.SetPosition(grid.Left, grid.Top+grid.Height+10);
form.AddItem(buttonOK);
Zusätzliche Info:
Der Button mit der UID "1" ist der OK/Aktualisieren Knopf
Sascha Balke
Ohh Mensch, gestern war echt nicht mein Tag ...Entschuldige Frank, mein erster Dank selbstverständlich dir und Michael.
Soweit funktioniert das super, nur würde ich gern den Namen des Buttons selbst benennen. Dazu habe ich noch buttonOK.Value= "schliessen"; hinzugefügt, jedoch wird das überhaupt nicht berücksichtigt.
Wo habe ich noch meinen Gedankenfehler?
VG
Sascha
Michael Egloff
Wenn du dem Button die UID "1" oder "2" gibst, dann ignoriert er den mitgegebenen Wert.Nimm eine andere ID, dann kannst du den Wert selber bestimmen, dann musst du aber auch die Funktionalität (Form schliessen) selber programmieren.
Gruss und ich bin die nächsten 3 Wochen in den grünen Ferien (Militärdienst) ...
0
-
You can use the following sentence to get the variable from the form id
string docnum = TextEdit.GetFromUID(pVal.Form, "8").Value;
Then use it in your query adding the variable
string query = "SELECT Docentry FROM ORDR where Docnum = " + docnum;
0
Please sign in to leave a comment.
Comments
1 comment