IF EXISTS and Context

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
vinsnash
Posts: 415
Joined: Sun Oct 07, 2007 4:58 pm

IF EXISTS and Context

Post by vinsnash »

Does a successful "IF EXISTS" put an instance in context so that it can be updated?

I have a need to update attributes of an object that exists or creating the object and then updating the attributes such that for a first time user logging on instance of the object is created and attributes updated but for subsequent log on the existing instance is updated.

Sort of:

IF EXISTS ObjectA WHERE (ObjectA.ID = LoggedInRecularUser.LoginName)

THEN ObjectA.Date = CURRENT_DATE

ELSE

CREATE ObjectA WITH

ObjectA.ID = LoggedInRegularUser.LoginName
ObjectA.Date = CURRENT_DATE

Creating a process like above passes the rule editing but saving causes the warning message that attributes may be the wrong ones.

Thanks for any help with this.
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Post by tford »

Did you try putting a FIND in also?
Tom - V8.8 build 3137 - MySql / PostGres
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Post by tford »

Ignore my question.
Tom - V8.8 build 3137 - MySql / PostGres
aware_support
Posts: 7536
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Post by aware_support »

EXISTS doesn't put an object into Context.

Try this:
FIND ObjectA WHERE (ObjectA.ID = LoggedInRecularUser.LoginName)

If SEARCH_COUNT = 1 THEN ObjectA.Date = CURRENT_DATE

ELSE

CREATE ObjectA WITH

ObjectA.ID = LoggedInRegularUser.LoginName
ObjectA.Date = CURRENT_DATE
Aware IM Support Team
vinsnash
Posts: 415
Joined: Sun Oct 07, 2007 4:58 pm

Post by vinsnash »

That looks like a winner!

Thank you.

Vins Nash
vinsnash
Posts: 415
Joined: Sun Oct 07, 2007 4:58 pm

Post by vinsnash »

I just got to try your suggestion today.


"If SEARCH_COUNT = 1 THEN .....

Causes the syntax error

"Syntax error at token "If" (column 1)."
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Post by tford »

What build are you using? Not sure exactly when SEARCH_COUNT was added.

You can find that out by looking through the info at http://www.awareim.com/changelog/
Tom - V8.8 build 3137 - MySql / PostGres
vinsnash
Posts: 415
Joined: Sun Oct 07, 2007 4:58 pm

Post by vinsnash »

I'm using 4.9/1301. SEARCH_COUNT appears in the notice for 1187

Vins Nash
vinsnash
Posts: 415
Joined: Sun Oct 07, 2007 4:58 pm

Post by vinsnash »

There is definitely something odd about SEARCH_COUNT. Trying to use "IF SEARCH_COUNT = ...." after "FIND" in a process always causes a syntax error at the "IF".

Putting it in a query like

"FIND Object WHERE SEARCH_COUNT = 0" is accepted although I don't see the utility of a statement like that.

Vins Nash
technopak
Posts: 287
Joined: Thu Dec 04, 2008 2:16 pm

Post by technopak »

Hi Vins,

I don't have a comment about the SEARCH_COUNT - it usually works for me.

But you could always go back to your original structure and use

IF EXISTS THEN
FIND


This will test for the existence of what you're after and then the FIND will put it in context. It's a bit clumsy, but it does work :-)

Peter
vinsnash
Posts: 415
Joined: Sun Oct 07, 2007 4:58 pm

Post by vinsnash »

I think there's some other problem. Seems where ever I use "IF" it causes a syntax error.

I'm trying to create a process. The IF is always flagged as a syntax error in column 1.

CREATE ObjectA WITH
ObjectA.ID = LoggedInRegularUser.LogInName
ObjectA.Date = CURRENT_DATE
ObjectA.Amount = (Some calculated number)

IF ObjectB EXISTS WHERE ObjectB.ID = ObjectA.ID THEN
FIND ObjectB WHERE ObjectB.ID = ObjectA.ID
ObjectB.Date = CURRENT_DATE
ObjectB.Amount = ObjectA.Amount

ELSE

CREATE ObjectB WITH
ObjectB.ID = LoggedInRegularUser.LogInName
ObjectB.Date=CURRENT_DATE
ObjectB.Amount = ObjectA.Amount

There are other attributes involved but I need only one instance of ObjectB per RegularUser and there will be multiple instances of ObjectA.

It's actually meant to be a PayPal routine. I need ObjectA to accumulate an amount in a number field. The PayPal parameter for the amount is a text field. ObjectB (passed to PayPal) will be used repeatedly as needed.
BobK
Posts: 548
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Post by BobK »

If your are entering the Conditions and Actions on the Rules Standard form, you do not need to manually enter the 'If', The system will add it.
If you are using the Textual form, you do need to enter the 'If'.

Also, checking the SEARCH_COUNT after a Find definitely works, but it needs to be in a second rule within the process.
Bob
technopak
Posts: 287
Joined: Thu Dec 04, 2008 2:16 pm

Post by technopak »

Hi,

Not sure if this is just in your example, but the IF needs to be followed by the EXISTS - not by the object name

IF EXISTS Object WHERE(Object.Attribute=SomeValue) THEN

Could your problem just be the syntax ?


Peter
Post Reply