HELP with FOR EACH

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
rocketman
Posts: 1239
Joined: Fri Jan 02, 2009 11:22 pm
Location: Preston UK
Contact:

HELP with FOR EACH

Post by rocketman »

I am trying to do a CREATE FOR EACH process where the loop is WEEKEND_DAY between two dates input by the user but the thing I need to create must include the date itself. So something like

CREATE Duties FOR EACH WEEKEND_DAY between UserInput.Start_Date and UserInput.End_Date WITH Duties.StartDate=[The date we've got to in the loop]

UserInput is a non persistent BO and the gap between start and end could be up to 6 months - but I don't know how to grab the date we are at in the loop - Will that be in WEEKEND_DAY or is this a job for LOOP_ITERATION

My other problem is - I don't see any reference to WEEKEND_DAY in any of the manuals

Edit: Found an example in Programmers Reference so can now confirm that FOR EACH DAY BETWEEN..... With Duties.StartDate=DAY syntax works but whenever I swap it for EACH WEEKEND_DAY, I get a syntax error (like somebody forgot to do the code for WEEKEND DAY - which is a shame).

So how can I create a process that only creates records for weekend days
Rocketman

V8.7 Developer Edition. Server 2016 Standard edition. MySql 5.5
BLOMASKY
Posts: 1470
Joined: Wed Sep 30, 2015 10:08 pm
Location: Ocala FL

Re: HELP with FOR EACH

Post by BLOMASKY »

why not just create the records for all (including weekend) days then remove the weekends with:

FIND BO WHERE DATE Between firstdate and last date and (DAY_OF_WEEK(datefield) = 1 or DAY_OF_WEEK(datefield) = 7)
DELETE BO


Bruce
rocketman
Posts: 1239
Joined: Fri Jan 02, 2009 11:22 pm
Location: Preston UK
Contact:

Re: HELP with FOR EACH

Post by rocketman »

BLOMASKY wrote: Mon Mar 28, 2022 4:40 pm why not just create the records for all (including weekend) days then remove the weekends with:

FIND BO WHERE DATE Between firstdate and last date and (DAY_OF_WEEK(datefield) = 1 or DAY_OF_WEEK(datefield) = 7)
DELETE BO


Bruce
Just trying not to waste too many ID resources
Rocketman

V8.7 Developer Edition. Server 2016 Standard edition. MySql 5.5
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: HELP with FOR EACH

Post by Jaymer »

got to chime in here while Mark is still sleeping in Mongolia...

this is a job for...
while loop.jpeg
while loop.jpeg (63.54 KiB) Viewed 14891 times
knowing your date range, you init the NP BO and it loops until the final date.
in the process it creates records only when its Sat/Sun, then increments the test date.

easy
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
rocketman
Posts: 1239
Joined: Fri Jan 02, 2009 11:22 pm
Location: Preston UK
Contact:

Re: HELP with FOR EACH

Post by rocketman »

Yeah, Jaymer. I was heading that way. It's just so frustrating that the following example has been in every manual from 8.1 through 8.6 but WEEKEND_DAY just doesn't seem to exist. It would have been three lines of code.

"1. CREATE Transaction FOR EACH Account
2. CREATE Transaction FOR EACH
DAY/WEEK/MONTH/QUARTER/YEAR/WEEK_DAY/WEEKEND_DAY BETWEEN
Account.OpeningDate AND Account.ClosingDate
3. CREATE Transaction FOR EACH NUMBER BETWEEN 1 AND 3
4. CREATE Attachment FOR EACH FILE IN 'c:/mydirectory'
The action in the first example will create as many instances of the Transaction object as
there are instances of the Account object in the Context.
The action in the second example will create as many instances of the Transaction
object as there are days in the specified date interval. The date interval includes both
starting and ending dates."
Rocketman

V8.7 Developer Edition. Server 2016 Standard edition. MySql 5.5
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: HELP with FOR EACH

Post by Jaymer »

I know that would’ve been easy, but
There’s a great amount of satisfaction when you get a WHILE loop working correctly :-)
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
cishpix
Posts: 183
Joined: Fri Nov 06, 2015 5:07 am
Location: Indonesia

Re: HELP with FOR EACH

Post by cishpix »

rocketman wrote: Mon Mar 28, 2022 10:01 pm CREATE Transaction FOR EACH NUMBER BETWEEN 1 AND 3
Is it possible to include the NUMBER value into an attribute of every instance that created?

example: I want the Transaction.No = A-1, A-2, and A-3

I have try like rule in this below but got error

Code: Select all

CREATE Transaction FOR EACH NUMBER BETWEEN 1 AND 3 WITH Transaction.No='A-'+NUMBER
Regards,

Suwandy
-----------------
Kisaran - Indonesia
hpl123
Posts: 2579
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Re: HELP with FOR EACH

Post by hpl123 »

I am fairly sure the LOOP_ITERATION can be used for this. Search the forum and or docs.

I think the syntax would be something like:

Code: Select all

CREATE Transaction FOR EACH NUMBER BETWEEN 1 AND 3 WITH Transaction.No=LOOP_ITERATION
Then you can have business rule that adds the A or have another attribute where you combine letter with number.
Henrik (V8 Developer Ed. - Windows)
cishpix
Posts: 183
Joined: Fri Nov 06, 2015 5:07 am
Location: Indonesia

Re: HELP with FOR EACH

Post by cishpix »

hpl123 wrote: Thu Jun 16, 2022 10:07 am I am fairly sure the LOOP_ITERATION can be used for this. Search the forum and or docs.
OMG, I didn't read the text in the rectangle of AwareIM user guide.
hpl123 wrote: Thu Jun 16, 2022 10:07 am CREATE Transaction FOR EACH NUMBER BETWEEN 1 AND 3 WITH Transaction.No=LOOP_ITERATION
Many thanks, it works now..
Regards,

Suwandy
-----------------
Kisaran - Indonesia
Post Reply