Getting value of custom data entry field


I’m still trying to do a seemingly simple math operation in applescript to omniplan. The line that is giving me the error is:

set numencumbered to value of custom data entry “Encumbered”

The error I’m getting is:

error “Can’t make missing value into type number.” number -1700 from missing value to number
so, it doesn’t seem to be picking up the value of the “encumbered” field (which is populated).
The entirety of the code at this point ls:

property numencumbered : 0
property Encumbered : 0
tell application “OmniPlan”
set total to value of custom data entry “ReallocationLast”
set spent to value of total cost
set numencumbered to value of custom data entry “Encumbered”
set remaining to total - (spent + encumbered))
set value of custom data entry “Budget_Remaining” to remaining
end tell

I’ve tried it on lines that have entries in the fields (no $, no decimal) or with 0, or with the field being empty.

This is profoundly frustrating, and any help would be appreciated. If anyone can suggest a source to learn (as this seems to be not just an applescript error, but an applescript error specifically tied to omniplan), I would be happy to continue to work on it myself. Thanks, K.


So, last time you posted the script, it was accessing custom data on a task in a document. Now your script is asking the application itself for custom data entries. The application does not have those properties. A document can have custom data. A task can have custom data. You need to talk to one of those objects.

For example, to look at some data stored on the whole document:

tell application "OmniPlan"
value of custom data entry "Current_Allocation" of front document
end tell

To look at data on each individual task (similar to what your script did before):

tell application "OmniPlan"
   repeat with t in tasks of front document
	value of custom data entry "Current_Allocation" of t
    end repeat
end tell

Perhaps you could back up and describe what you want the script to do?


Good Morning Lizard:

What I am trying to do get capture the current budget for a task (custom data entry) and subtract what has currently been spent (total cost) and task encumbrance (custom data entry) and render a remaining budget amount. From something I read yesterday, a custom data entry can only contain strings (and maybe that is the problem)? I’m trying every permutation that I can think of trying to find one that works (or alternately, might change the nature of the error so I can figure out how to make it work correctly). I am perfectly happy having the script work manually on one task at a time (as I highlight it), or automatically - that is a trivial detail at this point. Thanks, K.


Then you definitely need the second structure I posted. Replace the middle line with all the lines of accessing custom data and math you want to do.

Converting a string to a number should “just work” as long as the text doesn’t have a currency symbol in it or whatnot.

So, borrowing from the other thread, and using your current description…

tell application "OmniPlan"
	repeat with t in tasks of front document
		if task type of t is group task then
			set budget to value of custom data entry "Current_Allocation" of t
			set spent to total cost of t
                   set encumbrance to value of custom data entry "Task_Encumbrance" of t
			set remaining to total - (spent + encumbrance)
			set value of custom data entry "Remaining_Balance" of t to remaining
		end if
	end repeat
end tell

And the custom data entry names need to match exactly in your document:
(You can change them, but make sure to change them in both the OmniPlan document and the names in quotes in the script.)