Im new to SuiteCRM and I need to know is theres a way to change a field value when I do an import.
Let me give an example.
Im importing a list of contacts and the countries are estabished by code (US, AU, CL, BR, etc). I need to change this value to the country name after I do the import.
I can only think about doing a workflow but this is not very productive since I would have to make about 200 to cover al the countries.
Any help would be appreciated.
I’m sure there are ways to do it via code. But the simplest way to accomplish it is by modifying the file with the records before importing. Open it with excel, or your favorite software, and add an extra column, then manually add the proper name on that column.
That might take some time but will ensure all data is properly imported.
The other option is to import it the way it is and later do a direct substitution on the DB via SQL.
The thing is that I need to be able to do this without modifying the importing file.
In fact, let me rephrase my question.
Can I import this country codes and have a different field to “autofill” with the corresponding contry name? Or this could only be achived via code?
Then create a logic hook. It will give you more leverage on how to create your logic.
A before save logic hook can allow you to do direct substitution and you can use the same field.
Here the logic hook documentation:
Intro Logic hooks allow you to hook into various events in SuiteCRM to fire custom code. This can allow you to, for example, make a call to an external API, or to create a new record if certain events occur.
Types Logic hooks can occur in three...
Here a discussion regarding validations on logic hooks:
Unfortunately I have uncovered a fatal flaw in my approach. The problem is that the “before_save” hook is called after any relation records have been inserted. This means that after the exception has been thrown, although the actual record is not saved, there are still orphan relation records left behind.
As such I have had to take a different approach. The first set of steps apply to the application as a whole, so need to be put somewhere under custom/Extension/application
I will try that!
You can write
function beforeImportSave for object Contact. For example:
$countries=array('US'=>'United States','AU'=>'Australia',...); // write full array!!!