Jump to content

Updating a global date field......


This topic is 6988 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I just ran into an interesting problem, and I have a work-around, but I think it is clumsy and wonder if one of you pros out there can help me.

I have a DB that uses Get(CurrentDate) to populate a field that is then used in a script that updates a production schedule.

Basically when the production schedule is called for a given day the DB goes to the global date field, copies the date in the field, enters find mode, goes to the appropriate layout, pastes the date in the "order due field" performs the find and then sorts the records.

This worked great. However, today when I went to test the Script again it didn't work because it was posting "yesterdays date". What I discovered was that until I created a new record, the global field did not change to the current date.

Now I know I can write an opening script that will create a blank record which would update the global field, and then script a deletion of the record. The problem that would cause though is then the sequence would be off in the autmatically generated "serial number"

I also know that I can have a sub database that creates serial numbers and thereby I could have it pulling serail numbers from that DB and paste them into the active DB. But this seems awfully cumbersome. (even though I use a similar solution in a DB I use all of the time)

So.....To make a long question short....is there a better way to get the global date fields to update without having to create a new record?

Sorry for the long explanation. Can anyone HBO. (Help a Brother Out!)

Thanks in advance,

Steve

Link to comment
Share on other sites

This is certainly a smiple soultion and points to my full lack of understanding on SET FIELD (topic of a recent post of mine!)

Can I use/change the same operator:

Set Field [order due field, Get(CurrentDate)]

to

Set Field [order due field, Get(CurrentDate)+ 1]

to find orders due tomorrow?

Thanks, This forum is worth it's weight in gold.

Steve

Link to comment
Share on other sites

Yes. And, if tomorrow means next business day, you can

Set Field [order due field; Get(CurrentDate) + 1 + Choose( DayOfWeek(Get(CurrentDate)) - 6; 2; 1 )]

It appears that you are using version 6, in which case you should use Status(CurrentDate) instead of Get(CurrentDate) and commas instead of semicolons.

Link to comment
Share on other sites

OK.....I'm doing something wrong!

My fields are:

Current_Date (global)

Order Due (Date)

Layout in question is called "production schedule" database is named "produciton order"

Script looks like this now:

Go to Layout ["Production Schedule" (production order)]

Enter Find Mode []

Go to field [Production_order::order due]

Set Field [production order::current date]

Perform Find[]

Sort Records [Restore; No Dialog]

This doesn't work as you all are probably chuckling to yourselves and understanding.

By putting pauses in the script I can see what happens, and the first thing I don't understand is that when it enters find mode it does not go to the proper field, and when it does get there by continuing the script, it does not paste (set) the current date.

Any help or ideas.....Thanks folks.

Steve

Link to comment
Share on other sites

First, you don't need to go to any layout or field in order to use Set Field. Set Field works "blind", IOW you can set any field from anywhere.

Now, Set Field has 2 parameters: which field to set, and what value to set it to. You didn't enter the second parameter.

In ScriptMaker, highlight the Set Field step, click on the "Specify.." button next to "Calculated result", and in the resulting calc window select the Get(CurrentDate) function.

---

Also, make sure you are setting the field that is to be searched.

This is what you should end up with:

Set Field [Production_order::order due ; Get(CurrentDate)]

Link to comment
Share on other sites

Try this:

Go to Layout ["Production Schedule" (production order)]

Enter Find Mode []

Set Field [Production_order::order due; production order::current date]

Perform Find[]

Sort Records [Restore; No Dialog]

The Set Field step is created by first Specify target field to order date, then specify Calculated result and use the dialog box to get the production order::current date.

Link to comment
Share on other sites

One last thing.....The way I read this:

Set Field [order due field; Get(CurrentDate) + 1 + Choose( DayOfWeek(Get(CurrentDate)) - 6; 2; 1 )]

This appears that if I am looking for orders due Monday, and today is Friday, that it would "ignore" the weekend and return the Monday date. Is that true?

If so...just to throw a wrench into, is there anyway to do that with a "3" day weekend thrown into the mix?

What blows me away is how you guys figure this stuff out. I mean, where does the "core" knowledge come from. It can't all be trial and error.

Steve

Link to comment
Share on other sites

Well.....So far this works great....But unfortunately this calculation did not perform as I expected:

Set Field [order due field; Get(CurrentDate) + 1 + Choose( DayOfWeek(Get(CurrentDate)) - 6; 2; 1 )]

What should I expect from this calculation? Can anyone explain what the modidiers should be doing.

Thanks,

SF

Link to comment
Share on other sites

Yes, you could do a three-day weekend, but you would need to know when to use it, possibly using a list of holidays or a holiday table of some sort. To implement it once you have the critiera, you would use Choose( DayOfWeek(Get(CurrentDate)) - 1; 1; 0; 0; 0; 0; 3; 2 ).

The Set Field step should return either the following day's date (for Sunday through Thursday) or the following Monday's date (for Friday and Saturday).

The way the calculation works is as follows:

Get(CurrentDate) + 1 + Choose( DayOfWeek(Get(CurrentDate)) - 6; 2; 1 ) =

Tomorrow + Choose( DayOfWeek(Get(CurrentDate)) - 6; 2; 1 ) =

Tomorrow + Choose( Case( DayName(Get(CurrentDate)) = "Friday"; 0; DayName(Get(CurrentDate)) = "Saturday"; 1 ); 2; 1 ) =

Tomorrow + Case( DayName(Get(CurrentDate)) = "Friday"; 2; DayName(Get(CurrentDate)) = "Saturday"; 1 )

So, essentially, it merely adds 2 to tomorrow's date, if today is Friday, or 1 to tomorrow's date, if today is Saturday. If today is Sunday through Thursday, the Choose test returns a number less than zero, and nothing happens after the 1 is added to today's date.

Can you elaborate on the incorrect result you're receiving?

Link to comment
Share on other sites

Well, I tried applying this formula to find for "day after tomorrow so I changed the + 1 to + 2. When a start day was like thursday, it would return sunday, when I was expecting monday. When I left it as is (no change to the +1) and the start day was thursday, it would return saturday. So not quite what I expected.

Set Field [order due field; Get(CurrentDate) + 1 + Choose( DayOfWeek(Get(CurrentDate)) - 6; 2; 1 )]

Thanks for your help. I know I am probably missing something basic and this is really one step further than my original question. I mean, if today is tuesday and I want to find orders due on monday, but ignore the weekend, would this work? It seems easiest to just set a button to find orders due in 6 days, but I was trying to get fancy. What I would love to do is have the script buttons that find orders due on Monday Tuesday wed, etc....but to do that I would need the type of functionality that you have been kind enough to already get me started on.

Steve

Link to comment
Share on other sites

Thursday should not return Saturday, but just to be safe, you could include all options

Get(CurrentDate) + 1 + Choose( DayOfWeek(Get(CurrentDate)) - 1; 0; 0; 0; 0; 0; 2; 1 )

in case the Choose portion isn't working the way it should. Have you upgraded to v3? That could possibly be the issue.

If you want to find the day after tomorrow, you need to do more than just change the + 1 to + 2.

Get(CurrentDate) + 2 + Choose( DayOfWeek(Get(CurrentDate)) - 5; 2; 1 )

or

Get(CurrentDate) + 2 + Choose( DayOfWeek(Get(CurrentDate)) - 1; 0; 0; 0; 0; 2; 1; 0 )

should do it.

If you want to find next Monday, regardless of today's date, use

Get(CurrentDate) + Choose( DayOfWeek(Get(CurrentDate)) - 1; 1; 7; 6; 5; 4; 3; 2 )

Link to comment
Share on other sites

This topic is 6988 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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