You need to sign in to do that
Don't have an account?
Pre populate a date field with standard controller LEAD
Hi there,
working on a simple VF page using the standard controller "Lead" and the VF page will be opened through a button on the lead page.
What I want to do is to pre populate a field "Tourgivendate__C" with the current date time {!NOW()}. If this can be hidden, even better. SO when the user updated the info and hits the submit button , the Lead record will now have the "Tourgivendate__C" field populated with the time the person opened the form.
Also, on my Commandbutton, I have a onclick"navigatetoURL('/secur/logout.jsp');" that is not logging out after the button is clicked. It worls fine on the Sandbox, but in production is not logging me out whe I hit the button. It saves the record but no logou. Here is the code:
<apex:page standardController="Lead" showHeader="false" sidebar="false" > <img src="{!URLFOR($Resource.logo3w, 'logo3w.jpg')}"/> <apex:pageBlock title=""> <apex:form > <table width="60%" columns="2"> <td align="left"><p><b>First name: </b><br/><apex:inputField value="{!Lead.FirstName}" /></p></td> <td align="left"><p><b>Last name:</b><apex:inputField value="{!Lead.LastName}" /></p></td><tr/> <td align="left"><p><b>Email:</b> <br/><apex:inputField value="{!Lead.email}" /></p></td> <td align="left"><p><b>Phone:</b> <br/><apex:inputField value="{!Lead.phone}" /></p></td><tr/> <td align="left"><p><b>Zip Code:</b> <br/><apex:inputField value="{!Lead.Zip_Code__c}" /></p></td> </table> <p><b>Primary area of interest:</b> <br/><apex:inputField value=" <p><b>Who is giving you the tour? (Please ask the Front desk manager)</b><br/> <apex:inputField value="{!Lead.Tour_Given_by__c}" /></p><br/><br/> <apex:commandButton value="Save" action="{!Save}" onclick="navigateToUrl('/secur/logout.jsp');"/> </apex:form> </apex:pageBlock> </apex:page>
Thanks a lot!
B
Hi,
Try the below code snippet
<apex:page standardController="Lead" id="p1" >
<apex:pageBlock title="" id="pb1">
<apex:form id="f1" >
<table width="60%" columns="2">
<td align="left"><p><b>First name: </b><br/><apex:inputField value="{!Lead.FirstName}" /></p></td>
<td align="left"><p><b>Last name:</b><apex:inputField value="{!Lead.LastName}" /></p></td><tr/>
<td align="left"><p><b>Email:</b> <br/><apex:inputField value="{!Lead.email}" /></p></td>
<td align="left"><p><b>Phone:</b> <br/><apex:inputField value="{!Lead.phone}" /></p></td><tr/>
<td align="left"><p><b>Zip Code:</b> <br/><apex:inputField value="{!Lead.Zip_Code__c}" /></p></td>
<td align="left"><div id="a" style="display:none;"><p><b>Company</b> <br/><apex:inputField value="{!Lead.Company}" id="cmp" /></p></div></td>
<td align="left"><div id="a" style="display:none;"><p><b>Tourgivendate</b> <br/><apex:inputField value="{!Lead.Tourgivendate__c}" id="dt"/></p></div></td>
</table>
<p><b>Who is giving you the tour? (Please ask the Front desk manager)</b><br/> <apex:inputField value="{!Lead.Tour_Given_by__c}" /></p><br/><br/>
<apex:commandButton value="Save" action="{!save}" onclick="AssignnDatevalu();" />
</apex:form>
<script>
function AssignnDatevalu()
{
var currentTime =new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var currenrdte=month + "/" + day + "/" + year;
alert(currenrdte);
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
if (minutes < 10)
{
minutes = "0" + minutes;
}
var tme=hours + ":" + minutes + " ";
if(hours > 11)
{
var tmeextention="PM";
} else
{
var tmeextention="AM";
}
// alert(currenrdte+'_________'+tme+tmeextention);
var dtetime=currenrdte+" "+tme+tmeextention
// alert(dtetime);
document.getElementById('p1:pb1:f1:dt').value=dtetime;
document.getElementById('p1:pb1:f1:cmp').value='DummyComp';
// alert('_____Date_'+document.getElementById('p1:pb1:f1:dt').value);
navigateToUrl('http://www.google.co.in/');
}
</script>
</apex:pageBlock>
</apex:page>
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thanks S Jain!
The javascript actually capture the current date and time but it is not passing the value to the field Tourgivendate__C after saving it. I modified the javascript a little just to get updae the field and navigate to a logout page, but still no success. will post my java in a sec...
Hi Sjain,
I've modified the Jscript a bit to simplify. But I tried yours too and it didn't work Here is what I've done:
BUt still, only saves the data entered on the regular fields but not on the Tour_given_time__C which is what I want to pre populate or pupolate it when the submit button is hit with the current date and time.
Field should be Tour_given_time__C.
Thanks!!
B