Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Choose DayOfWeek date script parameters

Featured Replies

Hi everyone. I have a portal working, global date joined to invoices on InvoiceDate. The global date field is presented above the portal (as edit box) with forward and backward buttons. Script for backward button is: Set Field [ gDate - 1]; forward is +1. I would like to always skip weekends when moving through the dates - we never ship on weekends and an empty portal looks weird.

I have a startup script which sets the global to the last working day, so those invoices display when first opened, then people can enter any date they wish - or use the buttons to move. It is:

Case(

DayOfWeek ( Get(CurrentDate) ) = 2; Get(CurrentDate) - 3;

DayOfWeek (Get(CurrentDate)) = 1; Get(CurrentDate) - 2; Get(CurrentDate)

)

But I think I can use script parameters and Choose (with DayOfWeek) to 'lean' this up a bit and combine it into one script. Needs to be presented in the morning and my mind is leaving me. It's ready - just want to fine-tune this piece if possible before the presentation. Ideas on pulling this into one script and maybe even using it in Startup, using parameters? smile.gif

Lin

How about

Let( D = Get(CurrentDate);

D - 2 * (DayOfWeek(D) < 3) - (DayOfWeek(D-1) = 1 or DayOfWeek(D) = 7)

)

and

Set Field [gDate; Let( D = gDate - 1; D - 2 * (DayOfWeek(D) = 1) )] and

Set Field [gDate; Let( D = gDate + 1; D + 2 * (DayOfWeek(D) = 7) )]

for Previous and Next Date?

  • Author

Hi Queue! The first works perfectly in my Startup and the next two are perfect for the arrows - thank you so much. smile.gif

I kept trying to use Choose() thinking I could +/- somehow to use Get(ScriptParameter) but couldn't wrap my head around it. I sure like Let () ... thank you for the lesson!!

LindaG

I tried Let( D = Evaluate(gDate & Get(ScriptParameter) & 1); ... ) and several other variations. It didn't seem to want to return a date, but a number. I don't think Evaluate likes date fields.

  • Author

Hi there Queue smile.gif

Uh, I need to modify your solution a bit. I didn't forsee a problem. Some staff (uh, the boss, smile) doesn't arrive until mid-day and the daily shipments had already been uploaded. But when he logged on, it still displayed Friday's shipments instead of today's. I would like to include a test that, if shipments exist for that day (in related table), it displays that day instead of the prior workday.

I thought it would be a simple matter of an If( ) statement but I can't track the parens, I guess. If I wrap the whole thing with If():

If(

IsEmpty(OrdersByDate::InvoiceDate);

Let( D = Get(CurrentDate);

D - 2 * (DayOfWeek(D) < 3) - (DayOfWeek(D-1) = 1 or DayOfWeek(D) = 7);

Get(CurrentDate)

)

It says too many parameters. confused.gif

If I pretend the Let is outside the If (I don't understand Let) as:

Let( D = Get(CurrentDate);

If(

IsEmpty(OrdersByDate::InvoiceDate);

D - 2 * (DayOfWeek(D) < 3) - (DayOfWeek(D-1) = 1 or DayOfWeek(D) = 7));

Get(CurrentDate)

)

... I get the same error. Well, I won't go through all the errors I received giggle.gif but I'd appreciate your clarity on restructuring this startup calc.

Lin

Let is simply a way of creating a temporary variable, either so you don't have to type a long calculation multiple times and can use the temp variable instead or so you can use it instead of creating a new field to hold temporary data that's only needed during the calculation.

It's saying there are too many parameters, because the Let doesn't have closing parens in the first calculation and the second one has no false value for the If statement (you're closing it after 'DayOfWeek(D) = 7)', so the Get(CurrentDate) becomes part of the Let statement and not the If.

Here's how I would suggest making it simpler.

Set Field [gDate; Get(CurrentDate)]

Loop

Commit Records/Requests

Exit Loop If [not IsEmpty(OrdersByDate::serial)]

Set Field [gDate; gDate - 1]

End Loop

It will loop until there are related orders for the date in gDate. There's no need to worry about weekends, since there will be no related orders. Um, there will be no orders on the weekend, correct?

  • Author

This is a very clever use of a loop! I tend to think in terms of looping through records (although I know better) but this is valuable for many things. I will have fun playing with this principle.

Nope, we don't ship on weekends but every time I make statements like that the rules change. If I understand this, it doesn't matter because, if there are shipments on the weekend, they would show and if not, that day won't display anyway! Right? Please tell me if I'm misunderstanding this part.

Oh. And (of course) it also worked perfectly. Thank you so much, JT. smile.gif

Correct, you have the right idea. This will also apply to holidays on which you may have no orders. You can just skip right over them without worrying about hard-coding it.

You can loop through records, but you can also loop through fields and the data within a field (say for multi-key fields or text to parse). It's one of those simple yet powerful language constructs.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.