04-24-2013 01:09 AM - edited 04-24-2013 01:15 AM
just to inform you:
it seems like sage has change some code somethere so it is not possible anymore to check somethin like this:
some Web Hotfixes ago (aktually we are using 7.5.4 HF 6 in Prod. and HF 7 in Developtment) this statement returned a TRUE but now this fails and will return FALSE.
I solved that problem by checking the Id-Ojbect of the Contact Entity like this:
I hope, I can help someone of you with this information.
Solved! Go to Solution.
04-24-2013 03:43 AM
This all depends on what reference to an Entity you are working with.
If you cast the Object as an Entity, the ID Property is a String.
If you cast the Object as an Interface, then the ID Property is defined as Object.
(This applies to all Entities/Interfaces in SalesLogix, not just Contact)
Contact con = Binding.CurrentSource as Contact;
con.Id ( This is a String)
IContact con = Binding.CurrentSource as IContact;
con.Id (This is an Object)
con.Id.ToString() (This is a String)
04-24-2013 03:54 AM
i knew that already. but this is not the problem that i want to show. or I don't get what you try to explain
if I check the contactId, it seems to be empty. so I get FALSE in this case. If I don't use the ContactId but catch the reference Id throgh the Object of the Contact Entity, this Id is filled.
I'm only casting it to a string because of the sting.IsNullOrEmpty method. The right one would be to check the Contact.Id against NULL.
04-24-2013 04:38 AM
The right one would be to check the Contact.Id against NULL.
Yes, but keep in mind that String.IsNullOrEmpty takes a String as a Parameter, not an object.
So you can't do this:
string st = "My string";
object o = st;
String.IsNullOrEmpty(o); //This line will fail because you are using an Object Variable.
String.IsNullOrEmpty(o.ToString); //This will work
So again, it is just the difference between how the Interface and the actual Entity are defined.
04-25-2013 10:49 AM
Note that best practice is to hide the ID field in the entity properties page when you have a relationship in place - you should uncheck the 'include' box for ContactId.
Also note that doing a ToString() on a null value will result in an 'Object reference not set to an instance of an object' error. The safest way to do it (based on my personal paranioa of null objects) would be:
if (visitmember != null && visitmember.Contact != null && visitmember.Contact.Id != null && ! string.IsNullOrEmpty(visitmember.Contact.Id.ToString())
Since this is evaluated left to right, it would return False as soon as is came across a null object.
That being said, it is possible that HF7 changed the behavior in the ORM and leave the ContactId null when you have that relationship - wether or not is't exposed. In the future, hide the field you are creating a relationship on and use the Object's Id property to get the key.