Problem with evaluateItemPath

Hey @jessegrosjean, I was using a script to create a TaskPaper file from a query using evaluateItemPath(itemPath, contextItem?).

In TaskPaper, the results show the parents. That makes it so that if I have a task that matches the query, the parent project is also returned with the query. But that is not the case with evaluateItemPath. I have been trying to add the parent project by using the ancestor. That works for simple queries, but once an exception more are added, you have to figure out how to patch things together.

I was wondering if there was an alternative to evaluateItemPath that works the same way the TaskPaper queries work within the program. That would be really helpful.

Can you give an example of a search you are trying to perform? Generally I think the right approach is:

QUERY union QUERY/ancestor::*
1 Like

I think that you can get a clue with my other post about my query hack of why this was so hard for me to figure out.

I am still at the same place and getting the same results, but things are a lot clearer and understandable now. The hack I mentioned in the previous post doesn’t work when using evaluateItemPath. That means that I still get some projects that have no children since all the children are tagged with an exception (In the example file below, the problem would be the Tenth project.)

This is my query

((task/ancestor::* union task)) except ((//@private///* union //@unanswered///*) union (archive///* union @done///*))

(Edit: I figured out that the task/ancestor::* is what is stoping the hack from working)

And I use my query with the amazing bash script Complexpoint created some time ago to query file and create another one with the result using bash and javascript

I worked around the issue by running the query once with the original file, and the second time with the result file to eliminate the folders with no children. Since I don’t have the ability to modify the original query, what I end up doing is running a bash file that runs another bash file that then call a ruby file I created to convert the task paper file into markdown->template->XeLaTex->PDF.

This is a sample file just in case you would like to test.

First project:
	- One
	- Two
	- Three
Second project: @private
	- One
	- Two
	- Three
Third project:
	- One
	- Two @private
	- Three
Fourth project:
	- One
	- Two @private
	- Three
Fifth project:
	- One
	- Two @private
	- Three
Sixth project:
	- One
	- Two
	- Three
Seventh project:
	- One
	- Two
	- Three
	Subproject:
		- One
		- Two @private
		- Three
Eighth project:
	- One
	- Two
	- Three
	Subproject: @private
		- One
		- Two
		- Three
Ninth project:
	- One
	- Two
	- Three
Tenth project:
	- One @private
	- Two @private
	- Three @private
Eleventh project:

Maybe @complexpoint could look at the original file and modify it to run the query twice without the hacks I have to do. Hahah. If you could help me, I would appreciate it but I understand if you can’t. Thank you very much for all of your help.

Have you written a (human language) definition somewhere of what you want the query to return ?

And perhaps a couple of examples of desired output from given input ?

( The simplest cases are the most eloquent and helpful )

1 Like

Hey @complexpoint thank you for taking the time to answer. Sometimes I need to figure out how much work it takes to accomplish something through automation instead of doing it myself. I think there is a xkcd comic about it.

I just needed to run the script twice to get the results I wanted. This is my query,

task///* except (( @private///* union @unanswered///*) union (archive///* union @done///*))

To get similar results using evaulateItemPath I use,

(task///* union task/ancestor::*) except ((//@private///* union //@unanswered///*) union (archive///* union @done///*))

But this gets some project names with no tasks under if all of the tasks under the project are tagged with any of the exceptions.

I solved the issue by just copying and pasting the bash code to run it twice and then modified the file name I was reading and writing to in the second script. I am now getting what I want. For some reason I thought that maybe there was a way to get the JavaScript to run evaulateItemPath twice when just copying the bash code and running it twice in bash works perfectly fine with no perceived delay.

Anyway. Thank you very much for the interest. At this time everything is working as intended and I think I should get back to other projects. I really appreciate the help and the community we have in this forum.

God bless you!

1 Like