topic Re: deleting queries in Developer Discussionshttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20418#M2201
<P>Is there anything else i can try?&nbsp; Should I be able to delete two queries from a toolbar command?</P><P>Thanks!</P>Wed, 31 Jan 2018 19:10:59 GMTgeoquery2018-01-31T19:10:59Zdeleting queries - SOLVEDhttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20220#M2156
<P><STRONG>****The code to delete the queries is fine but the query name can not be one that was previously deleted.&nbsp; The query will be deleted but the code will be interrupted so the next query will not delete.&nbsp; I now create each query with a unique name incrementing by 1 each time created and delete the previous named query before creating the new one.&nbsp; All works great!&nbsp; Thanks! *******</STRONG></P><P>&nbsp;</P><P>&nbsp;</P><P>&nbsp;</P><P>I am using the code supplied by Piotr Szrajber on this board<SPAN class="login-bold">&nbsp;to delete queries by name.&nbsp; I execute the code from a 'Clear Map' command I added to my toolbar i create in helloworld.js and access via gwmpub.aspx&nbsp; &nbsp; All works great when I have just one query to delete but if i have two queries to delete then i have to&nbsp;</SPAN></P><P><SPAN class="login-bold">run the command twice from the toolbar even though I make a call to deleteQuery twice (once with each query name ) from my Toolbar command.&nbsp; Details:&nbsp; I have a query named qa and one named qb.&nbsp; My tool bar command does a deleteQuery("qa"); and deleteQuery("qb");</SPAN></P><P><SPAN class="login-bold">I have to run the command twice to get query "qb" to delete.&nbsp; Is there any explaination?&nbsp; Thanks very much.&nbsp; Both queries are displayed in the legend.</SPAN></P><P>&nbsp;</P><PRE>function getAnalysisId(name) {<BR /> // GP.ui.info("Name of query is " + name);<BR /> var a = $analysisManager.findAnalysisByName(name);<BR /> // $GP.ui.info("Analaysis ID is " + a);<BR /> return a &amp;&amp; a.get_id();<BR />}<BR /><BR />function deleteQuery(myQuery) {<BR /> // $GP.ui.info("Deleting " + myQuery);<BR /> $GP.queries.find({<BR /> analysisId: getAnalysisId(myQuery)<BR /> }, function(q) {<BR /> q.analysis.remove();<BR /> }, function(e) {<BR /> // $GP.ui.info("Unable to find analysis for " + myQuery);<BR /> });<BR />}</PRE><P>&nbsp;</P>Tue, 06 Feb 2018 21:45:16 GMThttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20220#M2156geoquery2018-02-06T21:45:16ZRe: deleting querieshttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20244#M2158
<P>Hi Jane,</P>
<P>&nbsp;</P>
<P>I reformatted the code snippet a little bit. I see that you have some commented code for logging/ debugging.</P>
<P>&nbsp;</P>
<P>Could you please replace them with <STRONG>console.log</STRONG> calls, so that you could see which branch is taken when the script does not work correctly?</P>
<P>&nbsp;</P>
<P>Something like this:</P>
<P>&nbsp;</P>
<PRE>function getAnalysisId(name) {
// GP.ui.info("Name of query is " + name);
var a = $analysisManager.findAnalysisByName(name);
// $GP.ui.info("Analaysis ID is " + a);
return a &amp;&amp; a.get_id();
}
function deleteQuery(myQuery) {
console.log("Deleting query " + myQuery);
var analysisId = getAnalysisId(myQuery);
$GP.queries.find({
analysisId: analysisId
}, function(q) {
console.log("Analysis [" + analysisId + "] found: " + analysisId);
q.analysis.remove(function() {
console.log("Analysis [" + analysisId + "] deleted");
});
}, function(e) {
console.log("Unable to find analysis for " + myQuery);
});
}</PRE>
<P>&nbsp;</P>
<P>Does it work as expected when you are executing this code using the JavaScript console in the browser or do you have the same behavior as when executing using a custom toolbar button?</P>
<P>&nbsp;</P>
<P>One explanation I am thinking of is that maybe the legend is not refreshed.</P>
<P>&nbsp;</P>
<P>&nbsp;</P>Thu, 25 Jan 2018 10:40:18 GMThttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20244#M2158pszrajber2018-01-25T10:40:18ZRe: deleting querieshttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20248#M2159
<P>The debugging messages indicate the code is not failing - all code is processed, the query is found&nbsp; so it all appears to work successfully from the debug messages but the second query remains in legend and is not deleted.&nbsp; I tried adding multiple deletes of the same query and that didn't work.&nbsp; When i run the command a second time (clicking the tool bar button) then the 2nd query is sucessfull. Looking to see how to refresh legend after first delete...</P><P>&nbsp;</P>Thu, 25 Jan 2018 13:00:52 GMThttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20248#M2159geoquery2018-01-25T13:00:52ZRe: deleting querieshttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20258#M2160
<P>Do you observe the same behavior in these 2 situations:</P><P>(A) When hitting your custom buttons in the toolbar</P><P>(B) When manually&nbsp;invoking&nbsp;<SPAN>deleteQuery("qa"); and deleteQuery("qb"); in the Javascript Developer console in the browser</SPAN></P><P>&nbsp;</P><P><SPAN>?</SPAN></P>Thu, 25 Jan 2018 14:12:01 GMThttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20258#M2160pszrajber2018-01-25T14:12:01ZRe: deleting querieshttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20263#M2161
<P>Sorry - I see what you wanted me to do now - i made the change and ran from console and all worked - running deleteQuery("qa") followed by deleteQuery("qb") resulted in both queries being deleted and the legend was updated.</P>Thu, 25 Jan 2018 14:43:58 GMThttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20263#M2161geoquery2018-01-25T14:43:58ZRe: deleting querieshttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20264#M2162
<P>Could you please show the code that adds the buttons invoking these commands to the toolbar?</P>Thu, 25 Jan 2018 14:47:18 GMThttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20264#M2162pszrajber2018-01-25T14:47:18ZRe: deleting querieshttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20266#M2163
<P>When i run from console doing two deletes then both my highlited parcel and the query result to find all parcels owned by "Ludwig" are deleted.</P><P>When i run from toolbar button then only the the first query i specify in the code for the toolbar command is deleted.</P>Thu, 25 Jan 2018 14:51:06 GMThttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20266#M2163geoquery2018-01-25T14:51:06ZRe: deleting querieshttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20269#M2164
<PRE> $GP.ui.toolbar.add({
categoryIndex: 11,
xtype: "tbbutton",
tooltip: "Clear All",
iconCls: "x-btn-icon",
// icon: "img/clear58x29.gif",
icon: "img/clear.gif",
handler: clearall
});
function clearall() {
$GP.ui.info("Clearing queries...");
deleteQuery("hiliteQuery");
deleteQuery("QueryByOwner");
}</PRE>Thu, 25 Jan 2018 15:16:36 GMThttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20269#M2164geoquery2018-01-25T15:16:36ZRe: deleting querieshttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20288#M2175
<P>Jane,</P>
<P>&nbsp;</P>
<P>Could you please try the following code?</P>
<P>&nbsp;</P>
<PRE>function getAnalysisId(name) {
// GP.ui.info("Name of query is " + name);
var a = $analysisManager.findAnalysisByName(name);
// $GP.ui.info("Analaysis ID is " + a);
return a &amp;&amp; a.get_id();
}
function deleteQuery(myQuery, callback, errback) {
console.log("Deleting query " + myQuery);
var analysisId = getAnalysisId(myQuery);
$GP.queries.find({
analysisId: analysisId
}, function(q) {
console.log("Analysis [" + analysisId + "] found: " + analysisId);
q.analysis.remove(callback);
}, errback);
}
function errback(e) {
console.log("Unable to find analysis");
}
function success() {
console.log("Both queries deleted");
}
function clearAll() {
deleteQuery("hiliteQuery", function() {
deleteQuery("QueryByOwner", success, errback);
}, errback);
}</PRE>
<P>I added a callback to the&nbsp;<STRONG>deleteQuery</STRONG> function, so that in the <STRONG>clearAll</STRONG> function we can make sure that one deleteQuery is&nbsp;invoked after the first deleteQuery invocation is complete.</P>
<P>&nbsp;</P>
<P>This is of course just a workaround. In case this code works, we will have to investigate further what&nbsp;exactly happens when both asynchronous "deleteQuery" functions are invoked immediately one after another.</P>Fri, 26 Jan 2018 10:14:06 GMThttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20288#M2175pszrajber2018-01-26T10:14:06ZRe: deleting querieshttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20303#M2179
<P>Thanks for the update! I actually want to delete more than 2 queries but i am sticking with just two for now....</P><P>&nbsp;</P><P>I replaced clearall function with the new one and&nbsp;it is still taking two clicks to get both entries deleted</P><P>&nbsp;</P><P>&nbsp;</P><P>This is what i have on console after two tries and legend is then clear of the two entries.&nbsp; &nbsp;After the first click the hiliteQuery is gone but the QueryByOwner is there.&nbsp; After the second click, both are gone from legend.</P><P>&nbsp;</P><P><BR />Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&amp;e=en-US.release.js&amp;t=636525582912012934:2971 Deleting query hiliteQuery<BR />Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&amp;e=en-US.release.js&amp;t=636525582912012934:2976 Analysis [1cbe-64ad-ea11-6101] found: 1cbe-64ad-ea11-6101<BR />Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&amp;e=en-US.release.js&amp;t=636525582912012934:2971 Deleting query QueryByOwner<BR />Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&amp;e=en-US.release.js&amp;t=636525582912012934:2976 Analysis [cf14-24f2-11ee-29d1] found: cf14-24f2-11ee-29d1<BR />Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&amp;e=en-US.release.js&amp;t=636525582912012934:2986 Both queries deleted<BR />Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&amp;e=en-US.release.js&amp;t=636525582912012934:2971 Deleting query hiliteQuery<BR />Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&amp;e=en-US.release.js&amp;t=636525582912012934:2976 Analysis [undefined] found: undefined<BR />Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&amp;e=en-US.release.js&amp;t=636525582912012934:2971 Deleting query QueryByOwner<BR />Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&amp;e=en-US.release.js&amp;t=636525582912012934:2976 Analysis [cf14-24f2-11ee-29d1] found: cf14-24f2-11ee-29d1<BR />Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&amp;e=en-US.release.js&amp;t=636525582912012934:2986 Both queries deleted</P>Fri, 26 Jan 2018 16:46:56 GMThttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20303#M2179geoquery2018-01-26T16:46:56ZRe: deleting querieshttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20418#M2201
<P>Is there anything else i can try?&nbsp; Should I be able to delete two queries from a toolbar command?</P><P>Thanks!</P>Wed, 31 Jan 2018 19:10:59 GMThttps://community.hexagongeospatial.com/t5/Developer-Discussions/deleting-queries-SOLVED/m-p/20418#M2201geoquery2018-01-31T19:10:59Z