cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Restore query definition from history

BKroell
8-Gravel

Restore query definition from history

Hi,

From time to time it happens, that we have modified a query on our staging system because of an internal CR, but before we can migrate it to the production server in the meanwhile additional CRs might lead to more changes on the same query. So at the time of migration not only the reviewed changes from the first CR are part of the available query definition, also even not finished modifications might be included. Is there a way to restore former query definition from a specific query (e.g. as of 2013-09-02 10:16)?

I'm aware of those im commands like editquery, createquery etc, but I was not able to re-set a historical query definition. In the query history tab all changes were documented, even the complete modified query definition. But this is not usable because this is not a real query definition statement given there. This might be readable for humans but has the wrong syntax for a correct query definition statement. So if you try to re-use this in a command like "im editquery ....--querydefinition...." you'll have to replace a lot of elements manually. And for more complex queries this becomes real science. Most elements can be fixed by renaming the used field names to their identifier names. But there are also more complex statements which I'm not able to translate back into a working command line statement. (e.g. "Has no ALM_Work Items relationship" ). The Integrity CLI Reference is no real support. For some existing query options there is no information at all. Also this kind of meta language used there makes it not very easy to create correct query definitions.More complex examples would be helpful.

Is there any workaround available to restore an old query definition without rebuilding it manually in the gui?

Thanks &

Kind regards,

Bertram

2 REPLIES 2

Hi Bertram,

In the history for my queries, I see the definition in a syntax that the CLI accepts.

What may be causing you headaches is the escape characters in definition exploding all over the CLI (Windows really doesn't like single quotes, double quotes, and whitespace all rolled into a single argument)

The solution to this is to use the --queryDefinitionFile param instead of --queryDefinition.

Simply copy paste the query definition from your history tab into a plain text file, save the file, then use im editquery/createquery with --queryDefinitionFile={filename} and it should update the definition without any issues.

For example, one of the definitions for my queries is below:

((field[Type] = "Help Ticket") and (field[Force Review Path] is unspecified) and not (field[Ticket Type] is unspecified) and not (field[State] = "Complete","Not Needed"))

I pasted this into a text file called "tempdef.txt"

Then I ran the below CLI from the directory containing the file

im createquery --name="temp2" --queryDefinitionFile=tempdef.txt

And the system created the new query without any issues.

Hope that helps,

Matt

Hi Matt,

thanks for your wide answer!

Basically your suggestion is correct and this is more or less exactly what I did to solve this.

I copied the visible query definition from the history put it in my favorite editor and reworked the statement and finally update via CLI the respective query.

But it was not as easy as on your side. Unfortunately in the query history only the display name of the field is shown but not the real field name, which is the one necessary for a correct query definition statement. In our configuration we have several fields with differences in their name and display name. With some manual effort this can be solved by find 'n' replace function.

Also only simple statements are shown correct in the query history. In some cases more complex parts like "Has no xyz relationship", which are very easy to create with edit query gui, must be manually translated back into real Integrity syntax (not (relationship.exists forwards using ["xyz"])) to make it usable with CLI. This is not always a easy thing to do. With a combination of try and error and analysis of other queries I was finally able to do this. During this research I discovered, that you can grap a complete correct query definition out of your system environment variables. As soon as you run a query in your client a system variable MKSSI_QUERYDEFINITION is available which has nothing else than a full working query definition with correct syntax regarding field names and complex statements.

With the help of that I was able to save the current query definition very easy and a restore of it is very easy now. To restore older query definitions listed in the query history the only reliable way is to manually rework the statement until it is correct Integrity syntax.

The whole process produces much effort and should be better supported by a respective integrity feature in the medium term.

I would appreciate a integrity function which allows the administrator to restore a query directly out of the history. Maybe a matching RFC could be created by PTC!?

Nevertheless thanks a lot for your kind support!

Best regards,

Bertram

Top Tags