You can see I was using my order number (pNumber) in the name:
parameter. This did return what appeared to be an OK order object,
but if applescript had to go back and reference the order as it did
in my example...
set myOrder to first order whose number is orderNumber
customer name of myOrder
...then it couldn't find the order since it used the order number
to try to find the order name.
Interestingly, the applescript:
customer name of first scheduled order whose id is orderNumber
...does not even cause the -objectSpecifier method to be called,
which it why it always worked, despite the poor form of my code in
that method previously.
That's because there's no reason to get the objectSpecifier. Only
when this object is used (e.g. to get a property) is the
objectSpecifier required.
So what made it work for me was to return the order name in the
"name:" parameter in my -objectSpecifier method, but I believe that
what I will do is consider to use NSUniqueIDSpecifier with my order
number.
The name is typically a string, not a number. See also the note below
about uniqueness.
I'm in kind of a funny spot because the primary identifier of an
order at my company is the production number or order number, which
I think best corresponds to the applescript "name" property, but
then we also have an order name such as "Cleveland Water Treatment
Plant Job" or similar, so I have to make a decision of which of
these properties is the best applescript "name" for an order.
Thanks again everybody, I feel I have a much better handle on this.
You can also have best of both worlds, and access both the unique ID
and name property, as well as accessors valueIn<Key>WithName: and
valueWith<Key>WithUniqueID: and perhaps an indexed one as well.
Though you have to make a choice for your object specifier. This
choice could be determined by the following considerations: 1. easy
lookup (e.g. through a dictionary), 2. the property (id or name or
index) must be unique for the object. So if your order number is
unique for the object, the best choice is probably unique ID =
production number, and add a name accessor that gives the more
descriptive name.