Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Not Answered
Replies
16 replies
Subscribers
8 subscribers
Views
11263 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
User Interface
Set value to a date time variable on saving a date field
arjunv
over 8 years ago
Hi All,
I have a scenario where there is a date field and once a date is entered, a date and time field should replace a date field with a defaulted time and the date.
If I remove either date or time in the date time field, it should again go back to a empty date field. Following is the code
load(
local!dt1,
local!dtTm1,
if(isnull(local!dt1),
a!dateField(
label:"date",
value:todate(local!dt1),
saveInto:{local!dt1,a!save(local!dtTm1,gmt(todatetime(save!value & " " & "16:00")))}
),
a!dateTimeField(
label:"dateTime",
value:todatetime(local!dtTm1),
saveInto:{local!dtTm1,local!dt1}
)
)
)
But when I again enter a date in the date field, the date and time field populates with a previously entered date and time instead of current chosen one. Is there any other way to implement this?
Thanks in advance.
OriginalPostID-251525
Discussion posts and replies are publicly visible
0
Sally Mason
Appian Employee
over 8 years ago
It is caused by adding the hours - in the first instance, you are selecting a date from a date field which has no time component. In the second part where you are saving this value, it cannot be cast and throws the error:
"Could not cast from Time to Date and Time with Timezone."
For this to work, the first date should also be datetime, not just time, but with the hours set to 00:00 and include the timezone too.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Sally Mason
Appian Employee
over 8 years ago
Also, when using GMT, you should specify the zone if you are not GMT 0. Also note the format Appian expects for the time: am/pm, not 24:00hr time.
Eg for the 7th of December at 1pm Eastern Standard Time (GMT-05:00) would be:
gmt(todatetime("12/07/2016 1:00 pm"), "EST")
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
arjunv
over 8 years ago
Thanks Sally, the issue with "Could not cast from Time to Date and Time with Timezone." is fixed in the date field by setting hours with timezone. However once the date time field appears with a default value and If I remove either date or time, the date field has to appear with empty date. When I choose another date, the date and time field appears with date entered the previous time.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Sally Mason
Appian Employee
over 8 years ago
Please attach a copy of the current SAIL code for review?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
arjunv
over 8 years ago
PFA
DateTime.txt
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Sally Mason
Appian Employee
over 8 years ago
Hmm.. using the code supplied, I cannot reproduce the as described: I select a date, the date in text changes to the selected, I choose a new date, the new date is saved, the hours stay the same.. as expected?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Ravi
over 8 years ago
I guess it's the default behavior of datetime field
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
rodgraham
Certified Lead Developer
over 8 years ago
@Sally what version are you using I can reproduce @arjunv's issue - the variables are set correctly but the value displayed in the date time field is the previous value. Pick a date say today, then remove the time, enter a new date say tomorrow. The variables show tomorrow but the value displayed is today
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Sally Mason
Appian Employee
over 8 years ago
I have tested on 16.2, 16.3 - which version, including build.info are you able to reproduce this so we can investigate further?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
arjunv
over 8 years ago
Yes I'm able to reproduce this on a 7.11 as well as on cloud. I will share the build.info
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
>