Page 1 of 1

Get Date and Time

Posted: 27 Nov 2017
by TonyDuke
Good Morning,

We have an edit form with a number of fields that do not need to be edited by a user and that we want to display in a more user friendly way.

Two of these fields are as follows
Call Taken by - Single Client People Picker
Time Logged - Date & Time field

I have placed a HTML field on the form with the following code:

Code: Select all

<div id="callTakerDetails"  style="white-space:nowrap;"></div>
And then in JavaScript added the following function and called the function to run on Form Load: -

Code: Select all

// Sets the Call Taker Display Field
function setCallTakerDisplay () {
	var callTaker = fd.field('Call_x0020_Taken_x0020_By').value().dictionaryEntries[0].AccountName;
	var dateLogged = fd.field('Time_x0020_Logged').value()[0];
	var hourLogged = fd.field('Time_x0020_Logged').value()[1];
	var minLogged = fd.field('Time_x0020_Logged').value()[2];
	$("#callTakerDetails").html('<p style="font-size:14px; color:#4F81BD;"><b>Call Taken by - </b>' + callTaker + ' on ' + dateLogged + ' at ' + hourLogged + ':' + minLogged +'</p>');
}
None of the above seems to work, I already have a forum post for the "Call Taken by" field, but equally I cannot get the values of the "Time Logged" field either.
This is on an edit form, but I will also need to use this on a display form to display the same information to the user.

Any help much appreciated.

Re: Get Date and Time

Posted: 27 Nov 2017
by Nikita Kurguzov
Hello, Tony!
Your code worked just fine for me, at least the time setting part that I've tested.
Make sure that the field name is indeed correct and don't forget to call this function after declaring it:

Code: Select all

function setCallTakerDisplay () {
	//your function
}

setCallTakerDisplay();
As for Display form, you will need custom form for it, because this:

Code: Select all

fd.field('Time_x0020_Logged').value();
will return you a string of Date and Time, like this - "11/23/2017 1:35 PM"