on 06-29-2016 9:56 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.