Marketcircle    Forums  Hop To Forum Categories  Extending Daylite  Hop To Forums  Scripting    Desperate with Scripting Problems in if clauses
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Apprentice
Posted
Hi (again),

this time I'm really stuck.

I have the following code, which should be - at least the beginning - of a litte routine to prepare the adresses for an address-book -> iPhone sync.

But whatever I try it looks like the whole block in

 
(a_country ~= nil) ifTrue:
[
    ...
].


seems never to be executed. No msg...log fires, nothing.

"This script gets all relevant contacts"

a_qual1 := BDQualifier qualifierWhereValueOfKey:'defaultGeoAddress.city' isEqualTo:(NSNull null).
a_qual2 := BDQualifier qualifierWhereValueOfKey:'defaultGeoAddress.street' isEqualTo:(NSNull null).
a_qual3 := BDQualifier qualifierWhereValueOfKey:'defaultGeoAddress.postalCode' isEqualTo:(NSNull null).

a_qualifiers := {a_qual1, a_qual2, a_qual3}.

a_andQual := (((BDAndQualifier alloc) initWithQualifierArray:a_qualifiers) autorelease).

a_qual4 := BDQualifier qualifierWhereValueOfKey:'defaultGeoAddress.note' isEqualTo:'automatic'.

a_qualifiers := {a_andQual, a_qual4}.

a_orQual := (((BDOrQualifier alloc) initWithQualifierArray:a_qualifiers) autorelease).

contacts := objectContext objectsForEntityNamed:'Contact' matchingQualifier:a_orQual.

a_index := 0.
a_total := contacts count.

a_msg := (a_total stringValue) ++ ' Contacts'.
sys log:a_msg.

[a_index < 1] whileTrue:
"[a_index < a_total] whileTrue:"
[
	a_contact := contacts objectAtIndex:a_index.

	msg := 'Name ' ++ (a_contact name).
	sys log:msg.

	a_defaultRole := a_contact defaultRole.
	(a_defaultRole = nil) ifFalse:	
	[
		msg := 'Role ' ++ (a_defaultRole name).
		sys log:msg.

		a_organization := a_defaultRole organization.
	
		(a_organization = nil) ifFalse:	
		[
			a_address := a_organization defaultGeoAddress.

			(a_address = nil) ifFalse:	
			[
				a_total_geos := (a_contact geoAddresses) count.

				msg := 'Total GeoAddresses = ' ++ (a_total_geos stringValue).
				sys log:msg.

				msg := 'making new geoAddress'.
				sys log:msg.

				a_newGeoAddress := a_contact defaultGeoAddress.

				a_newGeoAddress takeValue:(a_address valueForKey:'city') forKey:'city'.

				a_country := a_address valueForKey:'country'.

				a_country ~= nil ifTrue:
				[
					msg := 'Country ' ++ a_country.
					sys log:msg.

					a_country = '' ifTrue:
					[
						i := 0.
	
						msg := 'Deutschland!'.
						sys log:msg.
	
						a_newGeoAddress takeValue:'Deutschland' forKey:'country'.
					].
					a_country = '' ifFalse:
					[
						msg := 'Country ' ++ (a_address valueForKey:'country').
						sys log:msg.
	
						a_newGeoAddress takeValue:a_country forKey:'country'.
					].
				]
				ifFalse:
				[
					msg := 'Deutschland!'.
					sys log:msg.

					a_newGeoAddress takeValue:'Deutschland' forKey:'country'.
				].

				a_newGeoAddress takeValue:(a_address valueForKey:'directions') forKey:'directions'.
				a_newGeoAddress takeValue:(a_address valueForKey:'postalCode') forKey:'postalCode'.
				a_newGeoAddress takeValue:(a_address valueForKey:'state') forKey:'state'.
				a_newGeoAddress takeValue:(a_address valueForKey:'street') forKey:'street'.
				a_newGeoAddress takeValue:(a_address valueForKey:'typeString') forKey:'typeString'.
				a_newGeoAddress takeValue:'automatic' forKey:'note'.
				
				"cc deleteObject:(a_contact defaultGeoAddress)."

				"a_contact addObject:a_newGeoAddress toBothSidesOfRelationshipWithKey:'geoAddresses'."

				"a_contact takeValue:a_newGeoAddress forKey:'defaultGeoAddress'."

				objectContext saveChanges.
			].
		].
	].
	
	a_index := a_index + 1.
	
].
 
Posts: 10 | Registered: May 16, 2007Reply With QuoteEdit or Delete MessageReport This Post
AJ
Marketcircle Team
Picture of AJ
Posted Hide Post
Are you trying to test if a_country is nil or not nil?

And you are using a ~ (tilde) right (I can't tell with this font).
 
Posts: 893 | Location: Toronto | Registered: May 03, 2006Reply With QuoteEdit or Delete MessageReport This Post
Pro
Picture of Andrew Migliore
Posted Hide Post
I assume you are testing to see if a_country is actually set.

Are you sure you need to test for nil for the country? I believe (and could be wrong) that if you have an geoAddress the object will always have a country member and if not set will be equal to the empty string.

I'd suggest rewriting the block... drop the test for nil and just test for the empty string case.


Andrew Migliore
Lurker Films
http://www.lurkerfilms.com
 
Posts: 129 | Location: Portland, OR | Registered: August 15, 2007Reply With QuoteEdit or Delete MessageReport This Post
Pro
Picture of Andrew Migliore
Posted Hide Post
Oh one other thing to try:

This may be a problem between equality and assignment.

Try using '==' and '~~' to see if the object is equal to (or not equal to) the nil object.

(a_country ~~ nil) ifTrue:


Andrew Migliore
Lurker Films
http://www.lurkerfilms.com
 
Posts: 129 | Location: Portland, OR | Registered: August 15, 2007Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 

Marketcircle    Forums  Hop To Forum Categories  Extending Daylite  Hop To Forums  Scripting    Desperate with Scripting Problems in if clauses

© Copyright 2006 Marketcircle Inc. All rights reserved.