ExecutePrintDef with parameter from SQL query
Ronald Grentzius
Hello all,I have managed to execute a print definition with the new Easy Rule function thanks to the webinar. Only with the new rule I want to make, the parameter of the command must be filled with the results of simple sql query. Can somebody help me how I do this.
SQLQuery("MaxDocEntry|SELECT MAX(DocEntry) FROM OINV")
ExecutePrintDef("Email_Factuur|Preview|DocEntry;XXX")
How do I get the parameter (XXX) filled with the parameter "MaxDocEntry" which should be stored in the dictionairy from the sql query. Or do I have to do this a complete other way?
Thanks in advance for all help!
[attachment=283:MaxDocEntry.jpg]
Anders Olsson
Hi Ronald,Unfortunately it is not possible to do directly, but I would propose one of the following workarounds:
1. Store the query result in a UDF, pass it in to ExecutePrintDef and optionally remove the value from the UDF:
SQLQuery("MaxDocEntry|SELECT MAX(DocEntry) FROM OINV")
SetData("$[$U_SomeUDF.0.0]|MaxDocEntry")
ExecutePrintDef("Email_Factuur|Preview|DocEntry;$[$U_SomeUDF.0.0]")
SetValue("$[$U_SomeUDF.0.0]|")
2. Use a C# rule. In C# you have access to all EasyFunction commands. Example:
string maxDocEntry = SwissAddonFramework.Utils.SQL.ExecuteQueryScalar("SELECT MAX(DocEntry) FROM ORDR").ToString();
ExecutePrintDef("Email_Factuur|Preview|DocEntry;" + maxDocEntry);
return true;
I will create a development request for being able to use dictionary values in EasyFunction commands.
Ronald Grentzius
Hi Anders,Thanks for the quick respond! I was unable to use an UDF like the first work around (because the command is triggered by a 3rd party addon). But I managed to use the C# example. Works perfectly, thanks!
Best regards,
Ronald
Anders Olsson
The requested functionality was implemented in customize 3.65 (released October 2012).Dictionary keys can be retrieved using the following syntax: $[DICTIONARY.DictionaryKey].
Using the example from this forum post, this would be the way to do it:
SQLQuery("MaxDocEntry|SELECT MAX(DocEntry) FROM OINV")
ExecutePrintDef("Email_Factuur|Preview|DocEntry;$[DICTIONARY.MaxDocEntry]")
0
Please sign in to leave a comment.
Comments
0 comments