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

Sandeep Rajput
Tera Patron
Tera Patron

@Khalid9030 I don't see any issues with your code here. It is following the standard practice.

ShubhamGarg
Kilo Sage

Hello @Khalid9030 ,

Although the code looks good, but you can ADD COMMENTS to score more in terms of code readability matrix.

 

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

@ShubhamGarg 

Thanks for your reply. 

In OOB save button i just found curret.insert(); ,

May i know which one should i use current.update() or  curret.insert(); in my custom Save button 

@Khalid9030 If your UI Action updates the existing record then you should use current.update(). If your UI Action creates a new record then you should use current.insert();

 

Hope this helps.