PostSave not saving field value

Hi,

I am an undergraduate student doing my co-op (Internship) and am kinda new to Lotus Notes / Designer.

My problem is that I am trying to change a value of a field on PostSave, although the value is changed on saving but when I open the same database again, it shows me the value that field had before the PostSave command. I have no code in PostOpen…

Here is the code I am using in PostSave, please helpme as I have a deadline to meet.

Thanks in advance

@If(@Contains(wAssignment; “0”);@Command([RunAgent]; “Test”); @Failure(“”));

FIELD wAssignment := “1”;

@All;

@Prompt([Ok]; “On Save”; wAssignment)

Walie

Subject: PostSave not saving field value

The PostSave event is fine but you should use Lotusscript and write the change into the back end. Notesuidocument - called Source in the PostSave event - is the front end object. Each notesuidocument has a back end object that represents the data independent of the interface. (Interestingly the back end is available even before the document has been saved.) You cannot call notesuidocument.save here - because that would be a loop - but you can write the back end.

Sub Postsave(Source As Notesuidocument)

dim s as notessession

dim db as notesdatabase

dim doc as notesdocument

dim item as notesitem

dim agent as notesagent

set doc = Source.document

set item = doc.getfirstitem(“wAssignment”)

if item.contains(“0”) then

set s = new notessession

set db = s.currentdatabase

set agent = db.getagent(“Test”)

call agent.run

end if

’ ****************************************************************************************

’ This will cause Source to reload data from the back end. It’s a good

’ practice to call .refresh after doing this, such as if you have hide-when

’ formulas that depend on the value of wAssignment.

’ ****************************************************************************************

with doc

call .replaceitemvalue(“wAssignment”,“1”)

call .save(false,false)

end with

call Source.refresh

msgbox “On Save”, doc.getfirstitem(“wAssignment”).text

End sub

@If(@Contains(wAssignment; “0”);@Command([RunAgent]; “Test”); @Failure(“”));

FIELD wAssignment := “1”;

@All;

@Prompt([Ok]; “On Save”; wAssignment)

Subject: PostSave not saving field value

walid,

I’m running your code and I made one change…

@If(@Contains(wAssignment; “0”);@Command([RunAgent]; “Test”); @Error);

FIELD wAssignment := “1”;

@All;

@Prompt([Ok]; “On Save”; wAssignment);

It set the field value to “1” on the post save and when I opened it again, it had the value it set on the post save. You may want to put this code in the QuerySave event. What’s happening is that when you call code from the postsave, it “rolls” back to the QuerySave event and then saves the document for a second time. Just some thoughts.

HTH

SPJ

Subject: RE: PostSave not saving field value

Thanks alot SPJ, it worked, now I understand what was happening.

As my code was in Postsave, so the document was already saved before the changing the calue of the field.

Thanks again

Subject: RE: PostSave not saving field value

no problem walid and welcome to the community :slight_smile: