How to create saved search programatically?

I am using SuiteCRM.
Version 7.11.3
Sugar Version 6.5.25 (Build 344)

Every list view have “My Filters”, you can save the search parameters id database table named “saved_search”.

I want to create this filter programatically from logic hook on certain condition.

saved_search” table have a field named ‘contents’, which contains some encrypted text. I want that algorithm of encryption and decryption.


$saved_search_bean = BeanFactory::newBean("SavedSearch");
$saved_search_bean->contents = "some search text";
$saved_search_bean->name = "custom duplicate search";
$saved_search_bean->search_module = "Leads";
$saved_search_bean->save();

I tried this, but this will store plain text in ‘contents’ field. I need to encrypt the search parameters properly.

Anyone having idea about this?

it’s not encryption, it’s just Base64 encoding of a serialized array.

This, or something similar, should work to read it from the database:


$settings_array = unserialize(base64_decode($stringFromDatabase));

This, or something similar, should work to write it to the database:

$StringForDatabase = base64_encode(serialize($settings_array));