OK override button in editor

Hi ,

When I save any record in from editor field, an auto generated ID will create along with saved record in table. Now I want to use that ID (auto generated) to map it with subID in some other table.
For this I need to override OK button in the editor. so how can I override OK button so that I can perform some action after it will save the record.

Thanks,
Saurabh

You can use middlewar listeners to override onbeforinsert and onbeforeupdate. If you are using Studio, just click Middlewar -> new -> entity listener

Also you can always use Button component for your own ‘window actions’. Just invoke methods for it

public void onMyOkBtnClick(){
    if(this.commit()) /*doSmth*/
}
public void onMyCommitAndCloseBtnClick(){
    if(this.commit()) {
       /*doSmth*/
      this.close(COMMIT_ACTION_ID,true);
    }
}

Hi,

Can I get any sample where this code has been implemented? Because I tried but it did not worked.

Thanks,
Saurabh

Take a look here

There lots of online samples, trhe first is about buttons.

1 Like

But using entity listener as @apunzi suggested is better if your after-commit logic goes beyond one editor screen.

Summary

2018-04-20_13-56-502018-04-20_13-56-252018-04-20_13-59-40

so you mean, in my below editor screen I need to add an extra ‘save button’ for after-commit logic?

image

Yes. Just remove standart window-actions frame and add your own ok and cancel buttons.

ok, and where will my before commit logic will go?
Because I want something to do before commit and something to do after commit.

Create an EntityListener. There you can implement Before and After CRUD actions.
image

1 Like
  1. If you implemented your own buttons:
public void myOkBtn(){
    if(isValid()){ //We need it since now we have pre-commit logic
        /* pre-commit  logic goes here */
		if(this.commit()){
		    /* post-commit logic */		
		}
    }
}
  1. Also i just realize that since you’re using Editor window there is some pretty useful hooks (sorry didnt mensiond it’s earlier): postCommit() and preCommit()
    It is even better since standart window-actions is ok for you.