Values changed by agent are not saved

I have an agent that if a field value on a form is left blank, it replaces the value.

The agent works correctly when listed as an action menu selection and is run on a selected document in a view. When changed to an agent list selection and run during the save event the field values do not change on the document. I am able to view the code via the debugger while running and the field value does change while walking through the code, but when the debugger finishes and the document is closed, the original value is on the form again . The code below is part of the agent. The owner field is a field on the initial form that if left blank when saved, it does get changed to Lynne when viewing the doc - items values, but is blank after being saved. The ownernotified field does not exist in the form and is only populated when the agent is run, it has the correct value - Lynne when closed.

I’m signed in and using a design id that has manager access to the database. The designer also has full access to run agents on the server and all development work is done with this id…

If (doc.owner(0)="") Or doc.owner(0)="Unassigned" Then 

	Call doc.ReplaceItemValue("Owner", "Lynne")

	Call doc.Save(True, False)

End If



If doc.OwnerNotified(0) <> doc.Owner(0) Then

	Call doc.ReplaceItemValue("OwnerNotified", doc.Owner(0))

	Call doc.Save(True, False)		

End If

Appreciate any light that can be shed - thanks so much, Penny

Subject: values changed by agent are not saved

@PostedCommand([FileSave]) ; @Command([ToolsRunMacro]; “(Notes Process CTF)”);

@PostedCommand([FileCloseWindow])

this is the code in the save & exit button now. I moved the agent out of the querysave and initially had it as the first item - still did not work. I just moved it to the second line and the code works - but… very strange. When the agent is finished and you are brought back to the main view, the item appears in the unassigned area with the refresh button on the view. When the refresh button is selected the actual doc moves into the correct category and now has the right value in the field.

The code is working - but not sure why the code change made the difference and the view refresh is very confusing.

Subject: values changed by agent are not saved

When you went through the debugger, you verified that it actually hit your doc.Save() statements as well, right?

You might want to test for the return code when the save is done. E.g.

if doc.Save(True, False) = false then

print “Document was not saved”

end if

There might be another reason the document’s not being saved.

Subject: RE: values changed by agent are not saved

Don’t save the document twice – that’s wasteful. Furthermore, the agent works with the document in the back end, and the document that’s open in edit mode is not going to automatically update its display just because the back-end document changed, any more than it would if another user edited and saved the document while you were working on it.

Furthermore, there’s apparently nothing to prevent a user from saving without using your action button, bypassing this code.

Do your thing in the Querysave event, but don’t use an agent. Just put the code on the form (or in a script library and call it from the form).

For that matter, if all you want to do is detect a blank field and fill a value in, why not just use an input translation formula?

@If(@IsDocBeingSaved & @ThisValue = “”; “default value”; @ThisValue)