Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Copper Contributor
Posts: 69
Registered: ‎05-07-2012
Accepted Solution

checking a contactId string value agains null or empty fails

[ Edited ]

just to inform you:

 

it seems like sage has change some code somethere so it is not possible anymore to check somethin like this:

 

!string.IsNullOrEmpty(visitmember.ContactID)


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:

 

!string.IsNullOrEmpty(visitmember.Contact.Id.ToString()).

 

I hope, I can help someone of you with this information.

Bronze Super Contributor
Posts: 129
Registered: ‎06-09-2009

Re: checking a contactId string value agains null or empty fails

Sebastian:

 

  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)

 

  e.g.

 

  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)

 

Raul A. Chavez
http://raul.chavez.com
http://www.crmbi.com
Copper Contributor
Posts: 69
Registered: ‎05-07-2012

Re: checking a contactId string value agains null or empty fails

hi raul,

 

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.

Bronze Super Contributor
Posts: 129
Registered: ‎06-09-2009

Re: checking a contactId string value agains null or empty fails

You wrote:

 

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.

 

 

 

Raul A. Chavez
http://raul.chavez.com
http://www.crmbi.com
Bronze Super Contributor
Posts: 236
Registered: ‎03-30-2009

Re: checking a contactId string value agains null or empty fails

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.

Mike LaSpina
Professional Services Consultant

Sage
8800 N Gainey Center Dr Ste 200
Scottsdale AZ 85258
Tel: 480-383-5344
Cell: 480-321-6637
Fax: 480-556-4090
mike.laspina@sage.com

Your Business in Mind.
Copper Contributor
Posts: 69
Registered: ‎05-07-2012

Re: checking a contactId string value agains null or empty fails

as already mentioned, the problem is existing in hf 6, too.

 

thx for your answer, i'm adding this to my code!