Refresh Document

I need help with freshing a document. I have a computed field called DUEDATE. The db admin needs rights to edit the field as needed but no one else should be able to do so. I have created an agent that will allow the admin to do so.

The agent will update the date but the document will not show the new date unless she opens the document, places it in EDIT mode and then resaves the document. When the date change is made, we need the document to automatically refresh. Here is the code we’re using. Any ideas on why the document is not refreshing?

Sub Click(Source As Button)

Dim w As New NotesUIWorkspace

Dim s As New NotesSession

Dim db As NotesDatabase

Dim uiDoc As NotesUIDocument

Dim parDoc As NotesDocument

Dim thisDoc As NotesDocument

Dim thisDate As NotesDateTime



Set db = s.CurrentDatabase

Set uiDoc = w.CurrentDocument

Set thisDoc = uiDoc.Document

Set parDoc = uiDoc.Document



Forall v In thisDoc.Items

	Select Case v.Name

	Case Is = "AdminDate"

		Set thisDate = New NotesDateTime(v.Values(0))

		If v.Values(0) <> "" Then

			Call changeProjData("AdminDate",thisDate,parDoc)

		End If

	End Select

End Forall



Call parDoc.ComputeWithForm(False,False)

Call parDoc.Save(True,False)

Call uiDoc.Close(True)

End Sub

…and this is the code for CHANGEPROJDATA

Sub changeProjData(fieldName As String,newValue As NotesDateTime,parDoc As NotesDocument)

Dim updateItem As NotesItem

Set updateItem = parDoc.GetFirstItem(fieldName)



If Not updateItem Is Nothing Then

	updateItem.Values = newValue.DateOnly

End If

End Sub

Subject: Refresh Document

How is your Admin specifying the new due date and how are you invoking the agent? What is the formula for the DUEDATE field?

Gary.

Subject: RE: Refresh Document

I stated the field incorrectly, its actually called AdminDate. The agent to update this date is in an action menu. The user selects a document, and chooses the UPDATEADMINDATE option. The agent opens the document, and displays a dialog form and the users selects a new date. The agent is supposed to refresh and save the document. The new date is supposed to be updated in the document but I have to use the refresh agent or manually edit and save the document before I can see the new date.

This is the formula that thats in the AdminDate field. It computes the date considering some other fields on the form. But if the date is amended by the above agent, the new date should be displayed.

@If(

     Type != "" ;

      @Do(

	CreateDateVar := @Text(CreateDate;"S0");

      @Adjust(@TextToTime(CreateDateVar);0;0;@ToNumber(tmpAdj);0;0;0)

 );

""

)

Subject: Refresh Document

I would not rely on computewithform to recalculate any computed fields as in my experience it does not behave consistently. The notes help only mentions default value, translation, and validation formulas although most of the time it does recalculate computed fields as well.

It is best to set any fields explicitly in your code.

As you pass AdminDate and the value of AdminDate into your subroutine, don’t you just end up setting AdminDate with the same value? Also DateOnly returns a string value so the field will end up as text until the next time it is edited and saved when it will revert to a date.

Subject: Refresh Document

Morning - for a one time fix put this in an agent - select the docs u want to refresh in a view and run the agent:

@Command([ToolsRefreshSelectedDocs])

Subject: RE: Refresh Document

Hi - I have that agent also. Im hoping for a way to do this programattically rather have the user do it. But that is a great workaround.

Subject: Refresh Document

The real problem here is one of permissions if I am understanding your problem correctly. The actual problem is that you want a field which is readonly for some users and editable by others right?

If that is the case, then why not just use the InputEnabled code to control access to it rather than running an agent on it? Seems kind of an overkill solution - or I am completely misunderstanding what the real problem is?