Need help on custom Save button

Khalid9030
Tera Contributor

Hello,

 

We have created a custom Save button on a scoped application for a table. The code for the button is given below. The Save button is conditionally visible, which is why we created it instead of using the out-of-box (OOB) Save button (which saves a new record and redirects back to itself). Could you please review the code to ensure it follows best practices? If not, please provide recommendations for improvement.

 

 

current.update();

action.setRedirectURL(current);

1 ACCEPTED SOLUTION

Hello @Khalid9030 ,

 

current.insert() should be inserted only inside if loop where you will check if given record isNewRecord() else current.update() should run.

 

For Example

if(current.isNewRecord()){ //New Record which is not saved/created/inserted into the table yet.
current.insert();
}else{
current.update();
}

Let me know if it helps.

 

Thanks,

Shubham

View solution in original post

7 REPLIES 7

Hello @Khalid9030 


insert() - To create new record.
update() - To update existing record.

You can use action.setRedirectURL(current); in both the scenario.

 

Mark this as Accepted Solution/Helpful if above info. helps in any way and help in closing this thread.

Regards,
Shubham

@ShubhamGarg  @Sandeep Rajput 

When I use current.insert(); in the save button, each click creates a new record. This shouldn't happen—it should work like the default save button, as shown in the attached OOB Save button. The save button in my form should create a new record correctly.

Hello @Khalid9030 ,

 

current.insert() should be inserted only inside if loop where you will check if given record isNewRecord() else current.update() should run.

 

For Example

if(current.isNewRecord()){ //New Record which is not saved/created/inserted into the table yet.
current.insert();
}else{
current.update();
}

Let me know if it helps.

 

Thanks,

Shubham