Creating records in custom module

We want to create new custom module in the SuiteCRM and then create the records for this module using data from another database.

Means, we get the data at database(A) everyday and we automatically want to create records in the SuiteCRM database for this module using schedular.

Is it possible to do it? :thinking: Please guide! :pray:

Sounds like a great case for scheduled job in SuiteCRM, you can write your own code to fetch the info from the other DB and create new records in SuiteCRM.

OR

Is your other system capable of generating a webhook? You could build a custom entry point to accept the webhook everytime a add/edit or delete is done in the other database.

I think for our case, your first method will work well. We need to copy fields from the database(A) and then store them in the suitecrm database.

I hope this operation will create new records in the suitecrm :crossed_fingers: :face_with_peeking_eye:

Yep no problem you just have to write your logic which records to pick to create and/or update or delete on the SuiteCRM side.

You’ll have to code some logic to maybe get records since the last sync. and/or compare records that have changed since the last sync and then deal with either updating the bean, deleteing the bean or creating a new bean.

1 Like

Do you know how to set up scheduler to delete all records which are related to the sNumber = ‘S00798’?

There records should get delete from the DB too.

1 Like

Here is an example I tried on my local system to add a scheduler and a job to delete table entries. Please change the code and SQL if required to insert records from a db into suite db table.

  1. Create a new file at custom/Extension/modules/Schedulers/Ext/ScheduledTasks/scheduledtasks.ext.php
<?php
$job_strings[] = 'cleanDBRecordsScheduler';
	
function cleanDBRecordsScheduler(){
	global $sugar_config, $timedate;
    $GLOBALS['log']->debug('----->Scheduler fired job of type cleanDBRecordsScheduler()');
    $db = DBManagerFactory::getInstance();

    $query = "DELETE FROM sugarfeed";


    $GLOBALS['log']->debug("----->Cleaned up records as per query $query");
    $db->query($query);

    return true;
}
  1. Create a new language file and add a key at custom/Extension/modules/Schedulers/Ext/Language/en_us.cleandbrecords.php
<?php
$mod_strings['LBL_CLEANDBRECORDSSCHEDULER'] = 'Clean OLD DB Records – CUSTOM';
  1. From admin->repair->quick repair and rebuild

  2. Create a new Scheduler Record and select the newly added job. Please select the new JOB from the drop down list.

  3. Run your jobs by php.exe -f cron.php or If the cron job is already scheduled on your system, wait till it gets done.

  4. Check the logs

2 Likes

You have as well a few examples in our fork. If you have any specific question let us know.

1 Like