cancel
Showing results for 
Search instead for 
Did you mean: 

Identify create first time or update in BeforeSave

omkar_uthale2
Participant
0 Kudos

Hello,

I have a solution where I have to call External Web Services from my BeforeSave event at root node. What I need to do is, there are two different web services which I need to call, one involves data from Common node and other from AddressInformation node, both from Customer object.

Now there are two scenarios, first is for create, other is for update. My problem is, when I am creating new customer, my BeforeSave event gets called multiple times.

My both calls, for creation and update are in BeforeSave method. Is there anyway by which I can understand, if it's object creation or update? I need that info inside BeforeSave event.

Regards,

Omkar

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

var queryCustomer = Customer.QueryByIdentification;

var params = queryCustomer.CreateSelectionParams();

params.Add(queryCustomer.UUID.content, "I", "EQ", this.UUID.content);

var isCustomerPersisted = queryCustomer.ExecuteFromDB(params).Count() > 0;

// update

if(isCustomerPersisted){

}

// create

else{

}

This is not the best approach in terms of performance though... you could explore defining an Internal Communication with an additional "Processor" Business Object, or creating a new boolean field to identify whether the instance is already created.

Answers (2)

Answers (2)

omkar_uthale2
Participant
0 Kudos

Thank you Meghna and Fernando.

This solved my issue.

I combined the logic of query from DB as suggested by Fernando and one additional Boolean field so that it won't cause performance issues.

Also made some custom ID mapping of my own to track cross system IDs for future operations.

Regards,

Omkar

Former Member
0 Kudos

Hi Omkar,

You could use only the boolean field approach. For instance, a field named "IsPersisted" with default value "false". And in before save you set it to true, no matter what. Then you don't need this logic. I never tried but it should work.

Former Member
0 Kudos

Hello Omkar,

First of all the before save should be called only once for a save for any object. Please check if any custom code is causing the multiple call. And to check if the Customer is being created you can use Query and check if any Customer with same ID already exists. Generally Query will check the data committed in Database and not the one which is in buffer. You can try it.

Hope it helps.

Thanks & Regards,

Meghna