insert/update custom field value after logic_hook ?

I am creating new product using product module in sugarcrm, and also posting to the shopify api using “after_save_” logic hook. The product is created successfully on shopify side and also returning product id when product is created.
i want to save the shopify return product id in sugarcrm against created product, so that i can use that id later. how i can do this ?

What exactly is your difficulty? You just get the id and write it to the Bean.

Is it the same Bean that the after_save hook is being called for, or is it a related Bean? I ask because, if it is the same Bean, you have to be careful to avoid infinite loops (when an after_save hook saves, the after_save hook will be called…)

=> When i update a product on crm side, my after_save hook run, that post data to the shopify, problem is this that instead of updating the product on sholipy it create new product,because i have not product_id.
i want to save the return product_id on crm side so that when a user update the product on crm side then i can easly update product content on shopify using saved product_id.

=> i am using the same bean.

Should i alter the product table to save the shopify product_id ?

So you basically have a Products module. There is a custom field there, called shopify_id_c

When this module is saving, you call the Shopify API and get a new ID. You put it in $product_bean->shopify_id_c

Now you need to call $product_bean->save, but you need some extra work to avoid the save infinite loop:

https://web.archive.org/web/20171122135305/http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Module_Framework/Logic_Hooks/Examples/Preventing_Infinite_Loops_with_Logic_Hooks/

https://community.sugarcrm.com/thread/21375

Thanks for sending me helpful link.
But i have not the shopify_id_c named field in my product module. please see the screenshot.

i actually new to crm, that’s why i am confused.

image link

Press the “add field” button and add it :slight_smile:

i have some questions.
=> How i can avoid this field to show in product edit/create form ?
=> How i can access this field in “after_save” hook?

And also how i can save values in this field ?

If you don’t add it to the Detail View and to the Edit view, it won’t show.

In other words, you have to deliberately make it show - if you don’t do anything, it won’t show anywhere.

You can work with it normally through the Bean. Change it’s value, save the bean, …

Normally custom fields are created with a “_c” appended. So if you name the field “shopify_id”, it will be in the Bean as $bean->shopify_id_c

However, since yours is a custom module, maybe its fields aren’t considered custom fields, so try shopify_id if the aobve doesn’t work.

1 Like