Find by PrimaryKey

I’m working on a script that stores a reference to a project in a task. So far, I’ve been able to do it by name and look up the project using projectsMatching, but I’m concerned I’m going to run into name collision issues at some point. Short of just making sure my projects have unique names, is there some way to look up a project by its unique primary key, instead of by name?

Yes, quoting Omni-Automation website:

Projects are elements of the database, and like other elements possesses a unique identifier string to represent the project internally within the application.

For example, to get the unique identifier string of the first project in the database, enter in the Console:

projects[0].id.primaryKey

Thanks @unlocked2412. To be clear, I’m looking for the opposite: I’ve already got the primary key (using the code you quoted above), and I’m looking for some way to get back from there to the project. projectsMatching, for example, will only search by name, not by primary key.

Sounds like you want Project.byIdentifier(primaryKeyVariable)?

2 Likes

Yes!! I see it now in the API reference. I’m not sure how I missed it. Thank you!!