So I have this app where I click a button and it begins a series of modals to take user input. I am having an issue when trying to update the current modal with a new view object.
I can update and push new views no problem when responding to other buttons within a modal but not when it's the submission button. Unfortunately when using input blocks you must include a submission button.
Here is the code I am using to handle the view_submission payload I receive when clicking submit.
app.view('callback_period', async ({ ack, body, view, client }) => { // Pass callback_id
// Acknowledge the view_submission event
await ack();
// Log out view ID to confirm it is indeed the same as the initial view
try {
console.log(body.view.id);
const result = await client.views.update({
response_action: "update",
view_id: body.view.id,
hash: body.view.hash,
view: views_payroll_prefill_shift
});
console.log(result);
console.log(body.view.id);
}
catch (error) {
console.error(error);
console.log(body.view.id);
}
});
So when I click the button my app receives the payload just fine but the client.views.update method just gives me a "not_found" error. I checked the documentation and it says the view_id must be invalid however I've logged the view ID from the original modal and it is consistent throughout. I don't understand why it's working for app.actions() but not app.view().
I've tried creating const for the original body.view.id and passing that but I will keep getting this not_found error from app.views().
I'm really at my wits end. Any help would be greatly appreciated.
So after some more digging I finally found my answer. You need to pass the updated view as arguments during your acknowledgement. When the submission button is pressed you pass along the response action and your view inside ack(). Here is the solution;
app.view('callback_period', async ({ ack, view}) => { // Pass callback_id
// Acknowledge the view_submission event
await ack({
"response_action": "update",
"view": views_payroll_prefill_shift,
});
});