cancel
Showing results for 
Search instead for 
Did you mean: 

How to call an interceptor only during update of an object

Former Member
0 Kudos

strong text Hi,

Can you please let me know how to call an interceptor on updation of a custom object ? Or is there a way to find if the object is modified or created ?

I'm currently implementing PrepareInterceptor.

My requirement is to call an API on update of a particular attribute within a custom object. is there any way to achieve this ?

Former Member
0 Kudos

Use ctx.isNew(model) and ctx.isModified method for same

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

You can also use deltadetection, it was made for this cases.

former_member469962
Contributor
0 Kudos

Hello,
You can check the Interceptor context if the item is New or modified/updated. Check out this old Trail for an example. You can refer to the hasBecomeBig(...) method to see how it is done.

Hope this helps.

BR,
Shwetha

former_member537989
Contributor
0 Kudos

+1, check de.hybris.platform.servicelayer.interceptor.InterceptorContext#isNew & de.hybris.platform.servicelayer.interceptor.InterceptorContext#isModified

methods

Former Member
0 Kudos

Hi Divya,

If your requirement is to call an API only after update of an object you can implement AfterSaveListener interface. You need to create a custom class which implements AfterSaveListener and Override afterSave method.

 Code Sample:

@Override

 public void afterSave(Collection<AfterSaveEvent> events) { 

         for(final AfterSaveEvent event :events){  //get all the after save events

             final int type=event.getType();

             if(AfterSaveEvent.UPDATE==type){ //check if theAfterSaveEvent is UPDATE type

                 final PK pk=event.getPk();

                 if(TYPE_CODE==pk.getTypeCode()){ // check for your custom object typecode

                                    //write custom logic
                        }
                 }
       }

}