Object Dispatch error when using $G or $D
Hello,
I assume there is a simple explanation for this, but I do get <OBJECT DISPATCH> error, when I am trying to set a global to a value.
My example is huge, but I reproduced it using Samples namespace:
First I delete the Title from ##class(Cinema.Film) - 3
Secondly:
SAMPLES>s ref=##class(Cinema.Film).%OpenId(3)
SAMPLES>w ref.Title
SAMPLES>set ^AK(1)=$G(ref.Title)
SET ^AK(1)=$G(ref.Title)
^
<OBJECT DISPATCH> *Property 'Title' in class 'Cinema.Film' must be MultiDimensional
$D also does not work, same error, however this works fine: if ref.Title S ^AK(1)=ref.Title
I am almost 100 % certain it's working as it should, but wanted to double check.
Thank you
Docs of $G say
similar Docs of $D say
but Title in your case is $li(^CinemaooFilmD(3),1). So neither $G() nor $D() is approriate.
Thank you Robert.
Thank you for clarifying, that is what I ended up doing.
You can't use $get or $data on an object property. What you should do is as follows,
If $IsObject(ref) {set ^AK(1)=ref.Title}
Else {set ^AK(1)=""} // or whatever you want to do if ref is not an object
You could also do this:
If $IsObject(ref),$l(ref.Title) {set ^AK(1)=ref.Title}
Else {set ^AK(1)=""} // or whatever you want to do if ref is not an object or ref is an object but the property title is null