Custom Business Logic : Persisting State in between before and After Updates for appending an Array

Hello , I am planning to implement data structure of ‘Array’ on my Backendless Data Through Use of a String Type(or maybe TEXT ). Suppose that hypothetical class is ‘data_array’ and I update it by :

CustomData array=new CustomData();
array.put("data_array",mJson) //Consdering mJson being string representation of a JSON object 
Backendless.Persistence.Save(array,new AsyncCallback..........) 

I can do this Array appending stuff by downloading the current state of ‘data_array’ from the server, updating it in the client side and saving the appended array from the client side itself. But, I think that this would cost me extra network operations and volume of data transmitted across the network (Though that wouldn’t be much).So,I decided to use Custom Business Logic to tackle this.
What I want is that in the ‘BeforeUpdate’ trigger of the Custom Server Code, I could get the current ‘data_array’ state of my column before updating (which I guess is Provided by argument T entitymapbefore ) and when the new object is added at the original implementation part , the new object to be updated would automatically be passed to 'AfterUpdate ’ as T entityMap. After Update operation where I have the data persisted from ‘Before_Update’ right intact and finally append the data from the middle state of API Call. How can I get the T entitymapbefore persisted for a particular instance of API Call.
Please suggest me How can I achieve this implementation :slight_smile:
-Regards

Hi Pujan,

You can modify the object in the before handler and any changes you introduce in the object at that stage will be persisted by the default persistence logic of Backendless.

Regards,
Mark

Okay Mark , I Think I am close to getting it done here. Suppose I have an un-appended array at beforeupdate given by T entitymapbefore argument of the Callback. Now , If Only I could Bypass the actual Upadate method(the second phase of 3 step model ) and move to the AfterUpdate method to do my appending and finally save it.
I want to avoid going through the actual saving because well , when object_array which contains
an array of objects before 2nd step of updating might loose its bunch of data when I do :
object.addArray(jObj1) ;
and update the object it might replace the previous list with an individual json object element.
So , how can this be tackled then ?

Pujan,

I am confused now what the “3 step model” is.

If by “bypassing the actual update method” you mean skipping the default behavior of the update operation handled by backendless itself, then there is no point in calling update at all. You’d be better of creating either a custom event or your own service and handle all of the logic in there.

Нужна Ваша помощь по бизнес-логике

Мне нужно создать обработчик который будет удалять неиспользованные данные после того как пользователь обновил информацию. Я создаю данный обработчик:
GenericUserEventHandler

И в методе  afterUpdate (RunnerContext context, HashMap userValue, ExecutionResult<HashMap> result)

мне необходимо обратиться к result и userValue
Мой объект users содержит такие элементы как String objectId и List<UserData> userData
как мне вытянуть данные элементы из result и userValue.
И еще правильно ли я вытягиваю и удаляю из хранилища:
вытягиваю -

IDataStore&lt;Users&gt; dataStore = Backendless.Data.of(Users.class);
Users currentUsers = dataStore.findById((String) userValue.get("objectId"));

удаляю -

Backendless.Data.of(UserData.class).remove(userData);

Буду очень признателен если поможете в кратчайшие сроки решить данную проблему