Rank: Advanced Member
Groups: Registered
Joined: 5/23/2016(UTC) Posts: 129 Location: Virginia Thanks: 20 times
|
I am new to mobile designer but have built my solution in a short time. However, I have been stuck for a few days now on completing my app because I cannot seem to calculate a datetime that is the critical value in building my app in the first place. All of the calculations in my app work except where I want to add and subtract time.
In the help file I have found that this works only if I personally put in the date and the number of hours manually:
add-hours-to-dateTime(xs:dateTime("2014-01-15T13:00:00"), 10) However,
I want the app to pull the time from the solution and to add or subtract the hours. For example want to pull a dateTime from one of my forms and subtract a number of hours that has already been determined by the solution.
How do I convert the node to the actual parameters as in the above function? For example: $PERSISTENT/Root/CurrentLoad/PastLoads/ShippersAppt - ($PERSISTENT/Root/CurrentLoad/PastLoads/HourstoPickup div 24)
Thanks
|
|
|
|
Rank: Administration
Groups: Registered, Administrators Joined: 7/21/2014(UTC) Posts: 498
Was thanked: 88 time(s) in 88 post(s)
|
Everything seems to work just fine if I do exactly what you have been trying to do. I've used this statement: Code:
add-hours-to-dateTime( $PERSISTENT/Root/CurrentLoad/PastLoads/ShippersApt, $PERSISTENT/Root/CurrentLoad/PastLoads/HourstoPickup )
with a tree which contains your values (see the screenshot) bbv attached the following image(s):
|
|
|
|
Rank: Advanced Member
Groups: Registered
Joined: 5/23/2016(UTC) Posts: 129 Location: Virginia Thanks: 20 times
|
Thanks for the help. However, what you have is not the same as I am trying to do. You have added the hours to the date but for some reason this isn't working for me either. When in simulation mode the StartbyDateTime is not being picked up in the persistent tree and the error message says that no target node was found. However, when I check for it under the persistent tree in design mode it is there. Not sure what's going on there.
What I'm trying to accomplish: I am building an app for truckers. What I am trying to do here is to subtract the hours required to get to the pickup + 1.5 hours (equipment prep time)from the pickup datetime. This will determine a startbydatetime the trucker must leave in order to reach the pickup on time. From there I will determine the ETA to delivery and his next available time. I am stuck because I can't get the startbydatetime.
Much help appreciated. Thanks.
|
|
|
|
Rank: Advanced Member
Groups: Registered
Joined: 5/23/2016(UTC) Posts: 129 Location: Virginia Thanks: 20 times
|
Also, I noticed that you have the date and the 10 hours in your tree already set to display when loaded.
I am using a calculation to determine what the hours to pickup are and this is working fine. The hours are appearing in the form. The calculation is (miles to pick up div average speed).
The pickup time is given in the dispatch so it would be a known value.
The 1.5 is a constant used to show time for inspections, fueling, etc.
If I do this on my database in MSaccess the formular StartbyDateTime = ShippersAppt - (HourstoPickup + 1.5)/24 works perfectly. However it does not work in mobile designer. If I pull it from the database to the form then an error occurs when I try to update the form.
Thanks,
|
|
|
|
Rank: Administration
Groups: Registered, Administrators Joined: 7/21/2014(UTC) Posts: 498
Was thanked: 88 time(s) in 88 post(s)
|
I could give you an exact formula you need, if you would simply show here the tree with your actual data as it comes from the database. So far I have to guess a lot. For your understanding, you can supply only integer numbers to the add-...-to-dateTime function for addition or subtraction. XPath is a strictly typed language which avoids a lot of accidential errors, but requires sometimes explicit type conversion. Because you need to add 1.5 hours, you will have to switch calculation to minutes. The new formula I'm using is Code:
add-minutes-to-dateTime(
$PERSISTENT/Root/CurrentLoad/PastLoads/ShippersApt,
- xs:integer( ( $PERSISTENT/Root/CurrentLoad/PastLoads/HourstoPickup + 1.5 ) * 60 )
)
I'm adding to HourstoPickup 1.5 hours, multiplying it by 60 and enclosing the result in xs:integer to calculate in exact minutes. With - before xs:integer I achieve subtraction.
|
|
|
|
Rank: Advanced Member
Groups: Registered
Joined: 5/23/2016(UTC) Posts: 129 Location: Virginia Thanks: 20 times
|
Thanks a million! This did the trick. Everything is working fine and I am nearing the completion of my app. I have been working on it for over a year and have tried several different solutions which could not do what you just did. Built it with Mobil Designer in about five days with your help. Can't say thank you enough.
|
|
|
|
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.