Opening (and executing) a User Query Form
mathieu jolivet
Hi.I'm currently trying to execute User Queries created into SAP.
I can do it like this :
try{
Menu.MainMenu.Activate("54291");
}
catch (Exception ex){
MessageBox.Show(ex.Message, "Ok");
}
return true;but the problem is that if I create another User Query in SAP, the MenuId changes, and therefore nothing works anymore.
I tried to use the QueryId while doing this :
try{
Form F = Form.GetFormFromType("285-U-R", 1);
F.Load();
}
catch (Exception ex){
MessageBox.Show(ex.Message, "Ok");
}
return true;but it only opens the form... if it's already open (which is quite useless... :roll: )
Does anyone have any idea of a reliable way to open and execute user queries (other than getting the query and re-creating entirely a form and a grid for display)?
Martin Ehrensberger
Hi Mathieu,Yes, there is another way. Finding the ID by passing the query-name, and activating the MenuItem of the found ID:
//val needs to be filled with a String containing the Query-Name
foreach (KeyValuePair keyval in SwissAddonFramework.UI.Components.Menu.MainMenu.MenuItems["53248"].SubMenus.MenuItems)
{
if (keyval.Value.Value.Contains(val))
keyval.Value.Activate();
}
Hth,
Martin Ehrensberger
Rene Sluiter
Hi martin, I'm completely new with C# and Customise.I just added this CSCODE to a button.
Problem I have is that I get an error when I try to parse the code.
The type or namespace name 'KeyValuePair' could not be found(are you missing a using directive or an assembly reference?)(CS0246)
Do you know what might be going wrong?
Also do I need to put the query name between quotes?
Anders Olsson
Hi Rene,Type System.Collections.Generic.KeyValuePair instead of just KeyValuePair.
Kind regards,
Anders Olsson
Rene Sluiter
Sorry about the late reply Anders, I've been ill the last week and I forgot to check the email notification button on the bottom of the topic. To bad I don't auto subscribe to topics I participate in.Thank you for your suggestion! It's getting past that error now. Tried adding an 'imports System.Collections.Generic' line but that didn't work. So close, but yet so far :lol:. Only problem now, nothing happens. I think it runs the code, but now query is being run. I quadruple checked the query name so that's not it. I got the following code:
For Each kvp As System.Collections.Generic.KeyValuePair(Of String, MenuItem) In SwissAddonFramework.UI.Components.Menu.MainMenu.MenuItems("53248").SubMenus.MenuItems
Ifkvp.Value.Value.Contains("My full USERQUERY name")
kvp.Value.Activate()
End If
Next kvpI had to place the MenuID for userqueries between parentheses instead of brackets. Not sure if that's right but when I use brackets the last bracket is always being removed by the coresuite customize editor. Any suggestions?
edit: why is the
option adding so much tabs to my code :S. Makes it harder to read.... :roll:Rene Sluiter
same problem with the original cscode:
//val needs to be filled with a String containing the Query-Name
foreach (System.Collections.Generic.KeyValuePair keyval in SwissAddonFramework.UI.Components.Menu.MainMenu.MenuItems["53248"].SubMenus.MenuItems)
{
if (keyval.Value.Value.Contains("My full USERQUERY name"))
keyval.Value.Activate();
}
I can execute my function but nothing happens...
the query works just fine as a user-defined-value setup but not as a function. Suggestions?Rene Sluiter
Dear experts,
Above code still doesn't work. When I change the menuid to the id of the submenu the lookup does work and launches the right query but If I use the menuid 53248 nothing happens.
My first guess is that I don't have the query name right, that the submenu name is also stored in the value of the keyvalue dictionary but how is it 'stored'? Is there a way I can see the whole keyvalue dictionary to see how my query name is stored?
Any help would be highly appreciated.
edit. It's important to use the menuid 53248 because the submenu ID also changes every time a new query is saved...Rene Sluiter
Okay, I finally figured it out. As you can't safe a query without a Query Category (at least, that's the case for our SAP BO 8.8 ) the code first needs to lookup the Category ID before it can use the KeyValuePair to find Query ID's. So here's the complete code:
//val needs to be filled with a String containing the Query-Category
//val2 needs to be filled with a String containing the Query-Name
foreach(System.Collections.Generic.KeyValuePair keyval in SwissAddonFramework.UI.Components.Menu.MainMenu.MenuItems["53248"].SubMenus.MenuItems)
{
if (keyval.Value.Value.Contains("val"))
foreach(System.Collections.Generic.KeyValuePair keyval2 in SwissAddonFramework.UI.Components.Menu.MainMenu.MenuItems[keyval.Key].SubMenus.MenuItems)
{
if (keyval2.Value.Value.Contains("val2"))
keyval2.Value.Activate();
}
}
edit: reason for all the edits: trying to cleanup the code without all the annoying taps. no luck :evil:
0
Please sign in to leave a comment.
Comments
0 comments