Hexagon Geospatial
MENU

Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Regular Contributor
Posts: 243
Registered: ‎05-01-2016

deleting queries - SOLVED

[ Edited ]

****The code to delete the queries is fine but the query name can not be one that was previously deleted.  The query will be deleted but the code will be interrupted so the next query will not delete.  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.  All works great!  Thanks! *******

 

 

 

I am using the code supplied by Piotr Szrajber on this board

 

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 && a.get_id();
}

function deleteQuery(myQuery) {
// $GP.ui.info("Deleting " + myQuery);
$GP.queries.find({
analysisId: getAnalysisId(myQuery)
}, function(q) {
q.analysis.remove();
}, function(e) {
// $GP.ui.info("Unable to find analysis for " + myQuery);
});
}

 

Technical Evangelist
Posts: 128
Registered: ‎08-05-2015

Re: deleting queries

[ Edited ]

Hi Jane,

 

I reformatted the code snippet a little bit. I see that you have some commented code for logging/ debugging.

 

Could you please replace them with console.log calls, so that you could see which branch is taken when the script does not work correctly?

 

Something like this:

 

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 && 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);
    });
}

 

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?

 

One explanation I am thinking of is that maybe the legend is not refreshed.

 

 

Regular Contributor
Posts: 243
Registered: ‎05-01-2016

Re: deleting queries

[ Edited ]

The debugging messages indicate the code is not failing - all code is processed, the query is found  so it all appears to work successfully from the debug messages but the second query remains in legend and is not deleted.  I tried adding multiple deletes of the same query and that didn't work.  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...

 

Technical Evangelist
Posts: 128
Registered: ‎08-05-2015

Re: deleting queries

Do you observe the same behavior in these 2 situations:

(A) When hitting your custom buttons in the toolbar

(B) When manually invoking deleteQuery("qa"); and deleteQuery("qb"); in the Javascript Developer console in the browser

 

?

Regular Contributor
Posts: 243
Registered: ‎05-01-2016

Re: deleting queries

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.

Technical Evangelist
Posts: 128
Registered: ‎08-05-2015

Re: deleting queries

Could you please show the code that adds the buttons invoking these commands to the toolbar?

Regular Contributor
Posts: 243
Registered: ‎05-01-2016

Re: deleting queries

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.

When i run from toolbar button then only the the first query i specify in the code for the toolbar command is deleted.

Regular Contributor
Posts: 243
Registered: ‎05-01-2016

Re: deleting queries

  $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");
                                            }
Technical Evangelist
Posts: 128
Registered: ‎08-05-2015

Re: deleting queries

[ Edited ]

Jane,

 

Could you please try the following code?

 

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 && 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);
}

I added a callback to the deleteQuery function, so that in the clearAll function we can make sure that one deleteQuery is invoked after the first deleteQuery invocation is complete.

 

This is of course just a workaround. In case this code works, we will have to investigate further what exactly happens when both asynchronous "deleteQuery" functions are invoked immediately one after another.

Regular Contributor
Posts: 243
Registered: ‎05-01-2016

Re: deleting queries

Thanks for the update! I actually want to delete more than 2 queries but i am sticking with just two for now....

 

I replaced clearall function with the new one and it is still taking two clicks to get both entries deleted

 

 

This is what i have on console after two tries and legend is then clear of the two entries.   After the first click the hiliteQuery is gone but the QueryByOwner is there.  After the second click, both are gone from legend.

 


Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&e=en-US.release.js&t=636525582912012934:2971 Deleting query hiliteQuery
Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&e=en-US.release.js&t=636525582912012934:2976 Analysis [1cbe-64ad-ea11-6101] found: 1cbe-64ad-ea11-6101
Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&e=en-US.release.js&t=636525582912012934:2971 Deleting query QueryByOwner
Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&e=en-US.release.js&t=636525582912012934:2976 Analysis [cf14-24f2-11ee-29d1] found: cf14-24f2-11ee-29d1
Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&e=en-US.release.js&t=636525582912012934:2986 Both queries deleted
Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&e=en-US.release.js&t=636525582912012934:2971 Deleting query hiliteQuery
Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&e=en-US.release.js&t=636525582912012934:2976 Analysis [undefined] found: undefined
Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&e=en-US.release.js&t=636525582912012934:2971 Deleting query QueryByOwner
Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&e=en-US.release.js&t=636525582912012934:2976 Analysis [cf14-24f2-11ee-29d1] found: cf14-24f2-11ee-29d1
Compositor.WebClient.ashx?p=%2fportalSDK%2fgwmpub.aspx&e=en-US.release.js&t=636525582912012934:2986 Both queries deleted

Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.