state changed first then posting the comments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 02:13 AM
Hi, we have configuration where comments are mandatory while rejecting the approval record, so need to provide comments while clicking on button. Here the problem is, it is making the state changed first then posting the comments. this behavior is preventing the notification to miss the comments posted.
Please help on how to make comments posted first then make the state changed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 02:21 AM
Hi klavan32,
The issue is that your system processes the state change before saving the comments, causing notifications to miss the comment details. The solution is to change the execution order:
Save the comment first – Ensure the comment is posted and committed to the database or backend.
Then update the state – Change the state only after the comment is successfully recorded.
Possible Solutions:
1. Modify Backend API Sequence
If the backend handles both actions, update the workflow:
First, store the comment.
Then, only after confirmation, proceed with the state update.
2. Frontend Sequential API Calls
Ensure the frontend makes API calls in sequence:
async function rejectApproval(recordId, comment) {
try {
// First, post the comment
await postComment(recordId, comment);
// Then, change the state
await changeState(recordId, 'Rejected');
alert('Approval rejected with comments.');
} catch (error) {
console.error('Error:', error);
alert('Failed to reject approval.');
}
}
3. Backend Transaction Handling
If both actions are handled in a single request, consider using database transactions:
Ensure that if the state update fails, the comment isn’t saved (or vice versa).
Kindly mark it as "Accepted Solution"/"helpful", as it resolves your query. Please press like button for the resolution provided.
With Regards,
Krishna Kumar M - Talk with AIT3ch
LinkedIn: https://www.linkedin.com/in/mkrishnak4/
YouTube: https://www.youtube.com/@KrishAIT3CH
Topmate: https://topmate.io/mkrishnak4 [ Connect for 1-1 Session]