HelloWorld - part 4 default values

From EPESI framework documentation
Jump to: navigation, search

In order to set default values for the fields you created you have to use the set_defaults method in your modules main file in the body function.


Where rb is an instance of your recordset. You may set as many default values as you like. Remember to write the <field_name> in lowercase.

Lets say you wanted to set the default value of longtext to "some text" and set the select to your id. This is how the code should look like for mulitple defaults.

$me = CRM_ContactsCommon::get_my_record();
$this->rb->set_defaults(array('longtext'=>"some text",'select'=>$me["id"]));

CRM_ContactsCommon::get_my_record() returns an array of the logged in users recordset. Select fields are arranged by their index. If you want to set a default date the syntax is shown below (Y - year,m - month,d - day, H - hour,i - minute,s - seconds).


The code above will output the current date. If besides the date you want to set the current time for timestamp the code should look like this.

$this->rb->set_defaults(array('timestamp'=>date('Y-m-d H:i:s')));

Below is an example of how it should look like.

 public function body() {


        $me = CRM_ContactsCommon::get_my_record();

        //default values
        $this->rb->set_defaults(array('longtext'=>"some text","select"=>$me['id']));
        $this->rb->set_defaults(array('timestamp'=>date('Y-m-d H:i:s')));




The end result should look lik this where Admin is the user you are currently logged in as.


Download: Get full tutorial here