Set Default Value for Date Field through Script

By | October 22, 2014

In Sage CRM customizations, scripting has been proved essential for developers to justify trivial requirements with an ease. It provides the flexibility to set validations or values in field at screen level. Though this can be achieved through few configurations in CRM, but it does not allows you to limit the setting up to certain level. Today I will share one idea of setting default value for Date field.
New Stuff:Using Primary Key Column of an Entity to Search
While working on Sage CRM, I came across a requirement where I had to set current date and time as default value for one of the date field. I was able to achieve this through field level settings but it reflected the current date value on every screen whenever I progressed with the workflow. However the prerequisite was to set the current date value for one particular screen.
CRM did not provide any such setting at field level but writing one line of code on “Create Script” of date field worked like a treat. Please find below code snippet for the same.
DefaultType=6;
Just paste above code in ‘Create Script’ section of Date field and it will set current date time value by default for the same field. Refer below given steps to do the same.
1) Go to Administration || Customization || Leads. (Here I am working with Lead entity, you can use this for any other entity as per your requirement.)
2) Click and open the screen i.e. LeadCustomScreen.
3) Select the date field.
4) Write “DefaultType=6;” in Create Script section of the same.Img1
5) Update and Save the changes. Now go to new lead screen and will look as shown in below screen shot.
Img2
Also Read:
1) Default quote expiration/Delivery date setting in Sage CRM
2) Setting Default Date Time while progressing through Sage CRM Workflow
3) Disable Date Time Picker in Sage CRM v7.2
4) Print Current Date on Mail Merge Document in Sage CRM
5) Date fields in task and appointment