Embedded view button does not get hold of object

I have created buttons in the embedded view but when I click say “approve” button (which calls an agent to update a field in the embedded view), I receive an error saying that the document has not been saved.

The exact message is: “Document has not been saved”.

Even if I re-save the document, the agent ran without updating the field defined in the code.

JJ