Previous · Next | |
User | Message |
sysred
|
Date: 3/23/2016 7:15 am · Subject: ^SQL or ^SQLEx macro on JavaScript · Rating: 2
Hi, When I try to use the ^SQL otr the ^SQLEx macro from a javaScript method with a WHERE clause, I get an error which says "Cannot execute this type of query". I know the query is well builted. If I use it, for example, in a form, it works. Any clue? Regards --- (Edited on 3/23/2016 7:15 am [GMT-0500] by sysred) --- |
Back to Top |
Rate [ | ]
|
bartjol
|
Date: 3/23/2016 7:39 am · Subject: Re: ^SQL or ^SQLEx macro on JavaScript · Rating: 3
Hi, looking at the code, this comes from the macro itself. It checks whether a select, show or describe query is done, and if not, it returns this error. Is this one of these three type of queries?
--- (Edited on 23-March-2016 13:39 [GMT+0100] by bartjol) --- --- (Edited on 23-March-2016 13:40 [GMT+0100] by bartjol) --- |
Back to Top |
Rate [ | ]
|
sysred
|
Date: 3/23/2016 10:10 am · Subject: Re: ^SQL or ^SQLEx macro on JavaScript · Rating: 3
--- (Edited on 3/23/2016 10:10 am [GMT-0500] by sysred) --- --- (Edited on 3/23/2016 10:31 am [GMT-0500] by sysred) --- |
Back to Top |
Rate [ | ]
|
sysred
|
Date: 3/23/2016 12:12 pm · Subject: Re: ^SQL or ^SQLEx macro on JavaScript · Rating: 3
Ok, I've managed to enter the WHERE clause (must escape the ' chars with \). So, this works: <script> function RefreshGroup(group) { document.getElementById("familiaProducto").outerHTML='^SQL("SELECT DISTINCT Familly FROM db.Products WHERE Group=\'hardCodedGroupNotTheParameterButWorks\'", ^0;, "databaseLinkId");'; } </script> This doesn't work (and i need it working!): <script> function RefreshGroup(group) { document.getElementById("familiaProducto").outerHTML='^SQL("SELECT DISTINCT Familly FROM db.Products WHERE Group=\'' + group + '\'", ^0;, "databaseLinkId");'; } </script> I've alse tried to, unsuccessfully, use this function to format the string (similar ti C# .Net) <script> Regards --- (Edited on 3/23/2016 12:12 pm [GMT-0500] by sysred) --- |
Back to Top |
Rate [ | ]
|
roryzweistra
|
Date: 3/23/2016 12:30 pm · Subject: Re: ^SQL or ^SQLEx macro on JavaScript · Rating: 3
I don’t think you can use the sql macro the way you want it to. I haven’t used WebGUI in a while but as far as I can remember the macro’s are precompiled and therefore cannot be used to update stuff dynamically from javascript functions. Correct me if I’m wrong of course!
--- (Edited on 3/23/2016 12:30 pm [GMT-0500] by Visitor) --- |
Back to Top |
Rate [ | ]
|
bartjol
|
Date: 3/23/2016 2:00 pm · Subject: Re: ^SQL or ^SQLEx macro on JavaScript · Rating: 4
I thought in the same direction, but sysred gets an error from the macro itself, meaning it is getting processed as far as I can tell. Allthough, I think youŕe right on that the won't get evaluated again on a js input. --- (Edited on 23-March-2016 20:18 [GMT+0100] by bartjol) --- |
Back to Top |
Rate [ | ]
|
roryzweistra
|
Date: 3/23/2016 2:30 pm · Subject: Re: ^SQL or ^SQLEx macro on JavaScript · Rating: 3
Yeah I still think this is the case, I reckon the first error he got was because of the js ‘group’ vari which can’t be set because the page hasn’t initialised yet, so that must be where the macro error comes from. chatty-mode how’s the mongodb course going :P Will call you soon! /chatty-mode
--- (Edited on 3/23/2016 2:30 pm [GMT-0500] by Visitor) --- |
Back to Top |
Rate [ | ]
|
bartjol
|
Date: 3/23/2016 2:35 pm · Subject: Re: ^SQL or ^SQLEx macro on JavaScript · Rating: 4
|
Back to Top |
Rate [ | ]
|
bartjol
|
Date: 3/23/2016 2:32 pm · Subject: Re: ^SQL or ^SQLEx macro on JavaScript · Rating: 1
I think the concatenating goes awry: If I look at where the single quotes are placed, I think it only gets: '^SQL("SELECT DISTINCT Familly FROM db.Products WHERE Group=\'' (that are 2 sigle quotes on the end) and the next part falls off: + group + '\'", ^0;, "databaseLinkId");' Not sure whether the js variable within a macro gets evaluated properly, allthough nested macros are possible. You might want to try: document.getElementById("familiaProducto").outerHTML='^SQL("SELECT DISTINCT Familly FROM db.Products WHERE Group=\'" + group + "\'", ^0;, "databaseLinkId");'; but no garantuees, as I really doubt it will work :) --- (Edited on 23-March-2016 20:32 [GMT+0100] by bartjol) --- |
Back to Top |
Rate [ | ]
|
sysred
|
Date: 3/30/2016 9:43 am · Subject: Re: ^SQL or ^SQLEx macro on JavaScript · Rating: 5
First of all, thank you very much for all your replies! (:
--- (Edited on 3/30/2016 9:43 am [GMT-0500] by sysred) --- |
Back to Top |
Rate [ | ]
|