Currtime is 4 hours behind from my device time


The currtime does not match my local time, I use currtime() can I make this formula add a fixed 4 hours more?

Hello Faris.


The easy way: you can create your own action and use AddHours() to increase it manually by 4 hours.

Careful because the CurrDateTime value depends if it is called as Server Action or Local Action

The more advanced way: you work with TimeZones and this component. You can get the time of any place in the world and convert it to your.

Nuno Reis wrote:

Hello Faris.


The easy way: you can create your own action and use AddHours() to increase it manually by 4 hours.

Careful because the CurrDateTime value depends if it is called as Server Action or Local Action

The more advanced way: you work with TimeZones and this component. You can get the time of any place in the world and convert it to your.


Hi

Thanks for you repsonse I'm kinda biggner in outsystems, so I should make a new server action and make use addhours()?

Yes. The Client Action is out of your control (the device says the time it should use) but in the server, you can use your own instead of the default one and demand it to be 4 hours later.

Just remember that this is only valid if your difference is always 4 hours. Daylight Saving Time will probably change it twice a year.

The other solution is a lot trickier so I wouldn't advise it for a beginner. Add a Reminder in the code (use this link if you need https://success.outsystems.com/Support/Enterprise_Customers/Maintenance_and_Operations/OutSystems_Cloud_and_time_zones) and return to your functions before October to see if you can make it better.


Nuno Reis wrote:

Yes. The Client Action is out of your control (the device says the time it should use) but in the server, you can use your own instead of the default one and demand it to be 4 hours later.

Just remember that this is only valid if your difference is always 4 hours. Daylight Saving Time will probably change it twice a year.

The other solution is a lot trickier so I wouldn't advise it for a beginner. Add a Reminder in the code (use this link if you need https://success.outsystems.com/Support/Enterprise_Customers/Maintenance_and_Operations/OutSystems_Cloud_and_time_zones) and return to your functions before October to see if you can make it better.



Can you help me with the steps? I have add an aggragate to connect the data with the server action, should I add Assign or If? and what formula should use with Addhours, Addhours() + 4?



You should do a function so you can use always exactly the same formula to add time.

Create a function MyDateTime that outputs the datetime. Inside it adds x hours (x defined in site properties so you can change it when needed)

Then, instead of calling the server's CurrDateTime() and worrying about the 4 hours, you simply call your MyCurrDateTime. it is already doing the math for you.

I attached this example.

Nuno Reis wrote:

You should do a function so you can use always exactly the same formula to add time.

Create a function MyDateTime that outputs the datetime. Inside it adds x hours (x defined in site properties so you can change it when needed)

Then, instead of calling the server's CurrDateTime() and worrying about the 4 hours, you simply call your MyCurrDateTime. it is already doing the math for you.

I attached this example.

When I put the formula it gives me an error for the TimeDifference:

I tried to put "4" instead but it does not work either


Nuno Reis wrote:

You should do a function so you can use always exactly the same formula to add time.

Create a function MyDateTime that outputs the datetime. Inside it adds x hours (x defined in site properties so you can change it when needed)

Then, instead of calling the server's CurrDateTime() and worrying about the 4 hours, you simply call your MyCurrDateTime. it is already doing the math for you.

I attached this example.

Nevermind I found out how to do it right:

AddHours(CurrDateTime(), 4)

So thats it? or is there another step I have to do becaus I get this warning:

Unused User Action
'MyCurrTime' action is never used in this module. Consider deleting it.


You need to create the Site Property TimeDifference to use Site.TimeDifference.

That warning is because you are not using it yet.

The moment you use it somewhere, the warning will go away.

Nuno Reis wrote:

You need to create the Site Property TimeDifference to use Site.TimeDifference.


I did it but I had to change the datatype of the site to integer if thats okey becaus I had an error telling me I should change it


Nuno Reis wrote:

That warning is because you are not using it yet.

The moment you use it somewhere, the warning will go away.

How can I use it?


Like you were using CurrDateTime().

Faris Abdullah Almozini wrote:

I did it but I had to change the datatype of the site to integer if thats okey becaus I had an error telling me I should change it

Yes. The site property is the number of hours you'll add to the date.

Nuno Reis wrote:

Like you were using CurrDateTime().

I was using here, but how to reference the action server


Because this is a personal function, you can't use it as a default value. That only works for static values (numbers, strings) and standard functions from SQL.

You need to specifically assign it when you set the values before sending it to Create.

Nuno Reis wrote:

Because this is a personal function, you can't use it as a default value. That only works for static values (numbers, strings) and standard functions from SQL.

You need to specifically assign it when you set the values before sending it to Create.

This caused me a headache :(

I'm sorry I'm taking so much of your time, how to specifically assign it?


Don't worry with time if you are learning something.


Ok, so first part is:
You can use CurrDateTime() as default value, but not your functions.


You can use it in Assign before you save it.


Just be sure the MyCurrDateTime action is marked as a function so you can use it there.


Nuno Reis wrote:

Don't worry with time if you are learning something.


Ok, so first part is:
You can use CurrDateTime() as default value, but not your functions.


You can use it in Assign before you save it.


Just be sure the MyCurrDateTime action is marked as a function so you can use it there.


About the CreatInformation server action,it is a new action that I need to create?

No. It is only an example.

What I did was pick a Create action from the Entity and assign the value to it.

My entitiy is called Information. Yours is something else. 

Nuno Reis wrote:

No. It is only an example.

What I did was pick a Create action from the Entity and assign the value to it.

My entitiy is called Information. Yours is something else. 

I keep getting an error when I try to add the assginemnt


And what should I put in the source of  CreaArrFlightDom

The error says everything. "Can't identify ArrFlightDome" is because your Action1 needs a variable named ArrFlightDome of type ArrFlightDom before you can assign it.

"A valid expression must be set for parameter Source" is because the field ArrFlightDome.Time doesn't exist. Because, once again, ArrFlightDome doesn't exist in the action.

Nuno Reis wrote:

The error says everything. "Can't identify ArrFlightDome" is because your Action1 needs a variable named ArrFlightDome of type ArrFlightDom before you can assign it.

"A valid expression must be set for parameter Source" is because the field ArrFlightDome.Time doesn't exist. Because, once again, ArrFlightDome doesn't exist in the action.

Thanks that just fixed the errors, now should I publish the app and test it?


If you think it is ready.

The same way you checked that the time was 4 hours early than what you wanted, you can now see if it is ok.

Nuno Reis wrote:

If you think it is ready.

The same way you checked that the time was 4 hours early than what you wanted, you can now see if it is ok.

Still no luck, I just have warning that says:

Unused User Action
'ArrFlightDomTime' action is never used in this module. Consider deleting it.

Which is regarding the action I just created, also I haven't added the 4h time differnce where should I tell it to add 4 hours more on Currtime?


The 4h difference is in MyCurrDateTime, in AddHours, remember?


My suggestion was for you to use this wherever you were using the CurrDateTime(). If ArrFlightDomTime is not in use, you aren't fixing the original problem.



Nuno Reis wrote:

The 4h difference is in MyCurrDateTime, in AddHours, remember?


My suggestion was for you to use this wherever you were using the CurrDateTime(). If ArrFlightDomTime is not in use, you aren't fixing the original problem.




I was using here


but I get this error

Invalid Property Value
'Default Value' must be set to a 'Time' literal value.



That's why I said this:

Ok, so first part is:
You can use CurrDateTime() as default value, but not your functions.


You can use it in Assign before you save it.

You can't use it as default value, but you can assign it before each Create action. And ideally, there is only one Create action.


Nuno Reis wrote:

That's why I said this:

Ok, so first part is:
You can use CurrDateTime() as default value, but not your functions.


You can use it in Assign before you save it.

You can't use it as default value, but you can assign it before each Create action. And ideally, there is only one Create action.


I did all this and assigned it to my data but still says is never used.

I have attached the OML it might give you a better look at the problem

You created an action that you never use. I simply deleted it

.

What I said was to do the assign before calling Create.

This is how you see where Create is called.

On bootstrap you are setting a value from Excel so I guess here things are controlle and you are reading the time right.


On SaveOnClick you need to set the value just like you did on your action:


See the error? That is because you can't call a server action in a client action. But also, you can't expose database operations on client side...


So, I created a server action to call the default create. I can use it here and there is one less warning.


There are two ways of calling the action. The lazy one send the full structure. The elegant one send one the parameters that can be changed. I made this example here Time is not sent because it is recalculated on server.

Now you have one less warning of exposing database, but two new.

One for the unused action Create (you only need one, choose the format you prefer).

The other because the screen is anonymous and messes with data, but I guess you will fix permissions aftrer testing.