How to get a variable from JavaScript to use in Preparation? Example I want to get timezone offset of client by JavaScript and then use in Web Screen Preparation

Solution

Hello Long,

I don't think this is possible at all.

Scenario:

You are the user, you sit in front of your computer and you type the URL in the address bar of the browser.
No JavaScript will be executed, but the request will be sent to the server... 

So, there is no way of having this information when the Preparation of the screen being requested runs.

If you REALLY need the timezone in the preparation, you may try to get the UTC/GMT time that comes in the header (I think...) and try to guess the TImezone, or you can try a different approach.

You do a kind of "lazy load". So, instead of doing the things you need in the preparation, you execute the Javascript that will get the timezone when the answer is sent to the browser and also a "click" in a hidden link that will send back this information through Ajax Submit to a Screen Action where you actually do whatever you need and than refresh the screen.

I don't think there is any other way...

Cheers.

Solution

Eduardo Jauch wrote:

Hello Long,

I don't think this is possible at all.

Scenario:

You are the user, you sit in front of your computer and you type the URL in the address bar of the browser.
No JavaScript will be executed, but the request will be sent to the server... 

So, there is no way of having this information when the Preparation of the screen being requested runs.

If you REALLY need the timezone in the preparation, you may try to get the UTC/GMT time that comes in the header (I think...) and try to guess the TImezone, or you can try a different approach.

You do a kind of "lazy load". So, instead of doing the things you need in the preparation, you execute the Javascript that will get the timezone when the answer is sent to the browser and also a "click" in a hidden link that will send back this information through Ajax Submit to a Screen Action where you actually do whatever you need and than refresh the screen.

I don't think there is any other way...

Cheers.


Thanks for replying. But this approach affects so much on performance. I need time zone to set Min Date for DatePicker fields.

Long Du wrote:

Thanks for replying. But this approach affects so much on performance. I need time zone to set Min Date for DatePicker fields.

I agree that the Ajax strategy this will require two hits in the server, but I don't think there is any other good alternative, as the Header of the request does not have any information about Timezone.

Cheers.


Hi,

I was thinking...

There may be an alternative...
The approach we usually use is to use JavaScript in the page to show the dates in the user timezone... So this way we work always in the server UTC, the user just "see" things in their own timezone. 

You could try to adapt this to your use case.

But indeed, you would require JavaScript (maybe something like Memento.js)

Cheers.

Eduardo Jauch wrote:

Hello Long,

I don't think this is possible at all.

Scenario:

You are the user, you sit in front of your computer and you type the URL in the address bar of the browser.
No JavaScript will be executed, but the request will be sent to the server... 

So, there is no way of having this information when the Preparation of the screen being requested runs.

If you REALLY need the timezone in the preparation, you may try to get the UTC/GMT time that comes in the header (I think...) and try to guess the TImezone, or you can try a different approach.

You do a kind of "lazy load". So, instead of doing the things you need in the preparation, you execute the Javascript that will get the timezone when the answer is sent to the browser and also a "click" in a hidden link that will send back this information through Ajax Submit to a Screen Action where you actually do whatever you need and than refresh the screen.

I don't think there is any other way...

Cheers.

Maybe this one is the easiest way, I only need to update the Date time variable and reload Ajax for fields use it. Thanks for your answer.