- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 03:16 AM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 11:30 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 05:38 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 09:18 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 11:30 AM
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