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.
IF EXISTS and Context
-
- Posts: 7559
- Joined: Sun Apr 24, 2005 12:36 am
- Contact:
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/
You can find that out by looking through the info at http://www.awareim.com/changelog/
Tom - V8.8 build 3137 - MySql / PostGres
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
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
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
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
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.
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.
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.
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