How to test whether a note exists or not


(Malcolm) #1

Sometimes the simple questions confound me. My question: how do you test whether a note exists or not ?

As a background I have a set of tasks in a container called “/Tasks” with I would like to move automatically with an agent from “/Tasks” to “/Projects/ProjectName” where ProjectName refers to the various on-going projects e.g. “Project 1”, “Project 2” etc… Each task has an attribute called $ProjectName so that the path to the project can be build using:

$path= “/Projects/”+$ProjectName

and the move is done by

container($path)

However I only want to do the move if the actual $path exists and refers to an existing note or container. I’m stuck on this.


(eastgate) #2

First, I’d call your user attribute $DestPath to avoid confusing it with the system attribute named $Path.

Then, you could do something like this:

$DestPath=$Path("/Projects/"+$ProjectName)

If the target not exists, you’ll get its path. If it doesn’t exist, you’ll get the default value of $Path, which is “”.

Then, when you want to move the note:

if($DestPath!="") {$Container=$DestPath;}


(Malcolm) #3

Seems so simple once written down. I was not aware of behaviour of $Path (or indeed that you could give the $Path attribute an argument). Thanks.


(eastgate) #4

You can use just about any attribute that will have a value for any note that exists. But $Path is probably the most logical choice, in case you return to this document after a time and are trying to remember what the action is doing.


(Andreas Grimm) #5

Could you @eastgate or @mdavidson kindly elaborate on what goes where – Agent-actionCode etc.