Doc.save not working in Action button

Hi,

I have got a action button in a form, in which I am using doc.save. here when I click on that save button, the new document is getting created. After that when I am closing that notes window, it is again asking whether to save the document, can some one be able to tell me why it is happenning.

for better idea, this is the code, which I have got in the Action button.

Sub Click(Source As Button)

On Error Goto handler

’ Msgbox “testing”

Dim workspace As New NotesUIWorkspace

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView 

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument



Set db = session.CurrentDatabase

Set uidoc = workspace.CurrentDocument    



Dim CoreView As notesview

Dim CoreViewDocColl As notesdocumentcollection 

Dim CoreViewDoc As NotesDocument



Dim strExists As String

Dim j As Long



Set CoreView = db.getview("CoreView")

Set CoreViewDoc = CoreView.getfirstDocument 



While Not CoreViewDoc Is Nothing

	strProposalExists = CoreViewDoc.proposalNumber(0)

	strProposalNumber = uidoc.FieldGetText("ProposalNumber")

	

	Msgbox "inside while"

'	Msgbox "alreay there  " & strProposalExists

'	Msgbox "current documents proposal number " & strProposalNumber

	

	If Cstr(Trim(strProposalExists)) = Cstr(Trim(strProposalNumber)) Then 

		Msgbox "There is a match document"

		strExists = "True"

		Goto creating

	End If

	Set CoreViewDoc = CoreView.getnextDocument(CoreViewDoc)

Wend

creating:

If Not Cstr(Trim(strExists)) = "True" Then 

	Set doc = db.CreateDocument

	If doc.isNewNote Then

		doc.Form = "Core Proposal Form Tabbed"

		Msgbox "This is a new document"

		doc.ProposalManager = uidoc.FieldGetText("ProposalManager")

		doc.ServiceEstimator = uidoc.FieldGetText("ServiceEstimator")

		doc.LegalServices = uidoc.FieldGetText("LegalServices")

		doc.Date = uidoc.FieldGetText("Date")

		doc.ProposalNumber = uidoc.FieldGetText("ProposalNumber")

		doc.Client = uidoc.FieldGetText("Client")

		doc.ProjectTitle = uidoc.FieldGetText("ProjectTitle")

		doc.Scope = uidoc.FieldGetText("Scope")

		doc.PRMGcat = uidoc.FieldGetText("PRMGcat")

		doc.Client1 = uidoc.FieldGetText("Client1")

		doc.ProjectLocation = uidoc.FieldGetText("ProjectLocation")

		doc.BusinessLine = uidoc.FieldGetText("BusinessLine")

		doc.EstimatedContractValue = uidoc.FieldGetText("EstimatedContractValue")

		doc.Materials = uidoc.FieldGetText("Materials")

		doc.Construction = uidoc.FieldGetText("Construction")

		doc.Services = uidoc.FieldGetText("Services")

		doc.EstimatedCost = uidoc.FieldGetText("EstimatedCost")

		doc.ProjectDescription = uidoc.FieldGetText("ProjectDescription")

		doc.Licensor = uidoc.FieldGetText("Licensor")

		doc.Confidentiality = uidoc.FieldGetText("Confidentiality")

		doc.ScopeFW = uidoc.FieldGetText("ScopeFW")

		doc.ScopeClient = uidoc.FieldGetText("ScopeClient")

		doc.ITBSpecify = uidoc.FieldGetText("ITBSpecify")

		doc.ScopePartner = uidoc.FieldGetText("ScopePartner")

		doc.ITBSpecify1 = uidoc.FieldGetText("ITBSpecify1")

		doc.ScopeKeySC = uidoc.FieldGetText("ScopeKeySC")

		doc.ITBSpecify2 = uidoc.FieldGetText("ITBSpecify2")

		doc.ClientPS = uidoc.FieldGetText("ClientPS")

		doc.PartnerPS = uidoc.FieldGetText("PartnerPS")

		doc.KeyPS = uidoc.FieldGetText("KeyPS")

		doc.RequiredProjectSchedule = uidoc.FieldGetText("RequiredProjectSchedule")

		doc.BidType = uidoc.FieldGetText("BidType")

		doc.Competition = uidoc.FieldGetText("Competition")

		doc.A = uidoc.FieldGetText("A")

		doc.BIDTechnicalDateTimeLocation = uidoc.FieldGetText("BIDTechnicalDateTimeLocation")

		doc.BIDTechnicalTime = uidoc.FieldGetText("BIDTechnicalTime")

		doc.BidTechnicalLocation = uidoc.FieldGetText("BidTechnicalLocation")

		doc.B = uidoc.FieldGetText("B")

		doc.BIDCommercialDateTimeLocation = uidoc.FieldGetText("BIDCommercialDateTimeLocation")

		doc.BIDCommercialTime = uidoc.FieldGetText("BIDCommercialTime")

		doc.BidCommercialLocation = uidoc.FieldGetText("BidCommercialLocation")

		doc.Award = uidoc.FieldGetText("Award")

		doc.BidValidity = uidoc.FieldGetText("BidValidity")

		doc.BidRates = uidoc.FieldGetText("BidRates")

		doc.PaymentTermsRequested = uidoc.FieldGetText("PaymentTermsRequested")

		doc.PaymentCurrency = uidoc.FieldGetText("PaymentCurrency")

		doc.PaymentTax = uidoc.FieldGetText("PaymentTax")

		doc.LegalIssuesTerms = uidoc.FieldGetText("LegalIssuesTerms")

		doc.ContractingEntity = uidoc.FieldGetText("ContractingEntity")

		doc.LiabilityDelay = uidoc.FieldGetText("LiabilityDelay")

		doc.WarrantyIiabilityDefect = uidoc.FieldGetText("WarrantyIiabilityDefect")

		doc.ConsequentialLossExclusions = uidoc.FieldGetText("ConsequentialLossExclusions")

		doc.OverallLimitofLiability = uidoc.FieldGetText("OverallLimitofLiability")

		doc.OtherSignificantLiabilities = uidoc.FieldGetText("OtherSignificantLiabilities")

		doc.LiabilityOfPropertyDamage = uidoc.FieldGetText("LiabilityOfPropertyDamage")

		doc.InsurancesByClient = uidoc.FieldGetText("InsurancesByClient")

		doc.ContractLaw = uidoc.FieldGetText("ContractLaw")

		doc.Othercpl402Compliances = uidoc.FieldGetText("Othercpl402Compliances")

		doc.ParentCompanyGuarantee = uidoc.FieldGetText("ParentCompanyGuarantee")

		doc.BondRequired = uidoc.FieldGetText("BondRequired")

		doc.AcceptancePoint = uidoc.FieldGetText("AcceptancePoint")

		

		Call doc.Save(True, False)

		

	End If

Else

	

	If Not CoreViewDoc Is Nothing Then 

		CoreViewDoc.Form = "Core Proposal Form Tabbed"

		Msgbox "This is a modified document"	

		CoreViewDoc.ProposalManager = uidoc.FieldGetText("ProposalManager")

		CoreViewDoc.ServiceEstimator = uidoc.FieldGetText("ServiceEstimator")

		CoreViewDoc.LegalServices = uidoc.FieldGetText("LegalServices")

		CoreViewDoc.Date = uidoc.FieldGetText("Date")

		CoreViewDoc.ProposalNumber = uidoc.FieldGetText("ProposalNumber")

		CoreViewDoc.Client = uidoc.FieldGetText("Client")

		CoreViewDoc.ProjectTitle = uidoc.FieldGetText("ProjectTitle")

		CoreViewDoc.Scope = uidoc.FieldGetText("Scope")

		CoreViewDoc.PRMGcat = uidoc.FieldGetText("PRMGcat")

		CoreViewDoc.Client1 = uidoc.FieldGetText("Client1")

		CoreViewDoc.ProjectLocation = uidoc.FieldGetText("ProjectLocation")

		CoreViewDoc.BusinessLine = uidoc.FieldGetText("BusinessLine")

		CoreViewDoc.EstimatedContractValue = uidoc.FieldGetText("EstimatedContractValue")

		CoreViewDoc.Materials = uidoc.FieldGetText("Materials")

		CoreViewDoc.Construction = uidoc.FieldGetText("Construction")

		CoreViewDoc.Services = uidoc.FieldGetText("Services")

		CoreViewDoc.EstimatedCost = uidoc.FieldGetText("EstimatedCost")

		CoreViewDoc.ProjectDescription = uidoc.FieldGetText("ProjectDescription")

		CoreViewDoc.Licensor = uidoc.FieldGetText("Licensor")

		CoreViewDoc.Confidentiality = uidoc.FieldGetText("Confidentiality")

		CoreViewDoc.ScopeFW = uidoc.FieldGetText("ScopeFW")

		CoreViewDoc.ScopeClient = uidoc.FieldGetText("ScopeClient")

		CoreViewDoc.ITBSpecify = uidoc.FieldGetText("ITBSpecify")

		CoreViewDoc.ScopePartner = uidoc.FieldGetText("ScopePartner")

		CoreViewDoc.ITBSpecify1 = uidoc.FieldGetText("ITBSpecify1")

		CoreViewDoc.ScopeKeySC = uidoc.FieldGetText("ScopeKeySC")

		CoreViewDoc.ITBSpecify2 = uidoc.FieldGetText("ITBSpecify2")

		CoreViewDoc.ClientPS = uidoc.FieldGetText("ClientPS")

		CoreViewDoc.PartnerPS = uidoc.FieldGetText("PartnerPS")

		CoreViewDoc.KeyPS = uidoc.FieldGetText("KeyPS")

		CoreViewDoc.RequiredProjectSchedule = uidoc.FieldGetText("RequiredProjectSchedule")

		CoreViewDoc.BidType = uidoc.FieldGetText("BidType")

		CoreViewDoc.Competition = uidoc.FieldGetText("Competition")

		CoreViewDoc.A = uidoc.FieldGetText("A")

		CoreViewDoc.BIDTechnicalDateTimeLocation = uidoc.FieldGetText("BIDTechnicalDateTimeLocation")

		CoreViewDoc.BIDTechnicalTime = uidoc.FieldGetText("BIDTechnicalTime")

		CoreViewDoc.BidTechnicalLocation = uidoc.FieldGetText("BidTechnicalLocation")

		CoreViewDoc.B = uidoc.FieldGetText("B")

		CoreViewDoc.BIDCommercialDateTimeLocation = uidoc.FieldGetText("BIDCommercialDateTimeLocation")

		CoreViewDoc.BIDCommercialTime = uidoc.FieldGetText("BIDCommercialTime")

		CoreViewDoc.BidCommercialLocation = uidoc.FieldGetText("BidCommercialLocation")

		CoreViewDoc.Award = uidoc.FieldGetText("Award")

		CoreViewDoc.BidValidity = uidoc.FieldGetText("BidValidity")

		CoreViewDoc.BidRates = uidoc.FieldGetText("BidRates")

		CoreViewDoc.PaymentTermsRequested = uidoc.FieldGetText("PaymentTermsRequested")

		CoreViewDoc.PaymentCurrency = uidoc.FieldGetText("PaymentCurrency")

		CoreViewDoc.PaymentTax = uidoc.FieldGetText("PaymentTax")

		CoreViewDoc.LegalIssuesTerms = uidoc.FieldGetText("LegalIssuesTerms")

		CoreViewDoc.ContractingEntity = uidoc.FieldGetText("ContractingEntity")

		CoreViewDoc.LiabilityDelay = uidoc.FieldGetText("LiabilityDelay")

		CoreViewDoc.WarrantyIiabilityDefect = uidoc.FieldGetText("WarrantyIiabilityDefect")

		CoreViewDoc.ConsequentialLossExclusions = uidoc.FieldGetText("ConsequentialLossExclusions")

		CoreViewDoc.OverallLimitofLiability = uidoc.FieldGetText("OverallLimitofLiability")

		CoreViewDoc.OtherSignificantLiabilities = uidoc.FieldGetText("OtherSignificantLiabilities")

		CoreViewDoc.LiabilityOfPropertyDamage = uidoc.FieldGetText("LiabilityOfPropertyDamage")

		CoreViewDoc.InsurancesByClient = uidoc.FieldGetText("InsurancesByClient")

		CoreViewDoc.ContractLaw = uidoc.FieldGetText("ContractLaw")

		CoreViewDoc.Othercpl402Compliances = uidoc.FieldGetText("Othercpl402Compliances")

		CoreViewDoc.ParentCompanyGuarantee = uidoc.FieldGetText("ParentCompanyGuarantee")

		CoreViewDoc.BondRequired = uidoc.FieldGetText("BondRequired")

		CoreViewDoc.AcceptancePoint = uidoc.FieldGetText("AcceptancePoint")

		

		

		Call CoreViewDoc.Save(True, False)

		

	End If

End If



Exit Sub

handler:

Msgbox Cstr(Error$()) & "is in Save Action Button Click at line number " & Cstr(Erl())

Print Cstr(Error$()) & "is in Save Action Button Click at line number " & Cstr(Erl())

End Sub

Subject: doc.save not working in Action button

That was a bit too much code for me to have a proper look at, but even so your problem is a classic one.

You are saving the back-end document using the doc.Save method but when you are closing the UI-document, you have other values there that Notes considers to be different from what is in the back-end and therefore prompts you for saving.

You could try to use reload/refresh of the UI-doc before you close it, that may well be enough.

But really, if you have code that should execute whenever the document is saved, it should be in the Querysave-event.

Your ‘Save’-button could then have @Command([FileSave]); @Command([FileCloseWindow]) only.

Subject: RE: doc.save not working in Action button

Dear Kenneth,

Thank you so much it is working fine, once i moved the same to querysave event of that form and now my action button is having only…

@COMMAND([FILESAVE]);

@COMMAND([FILECLOSEWINDOW])

Thanks once again…

Subject: doc.save not working in Action button

For what it’s worth… I know your original question was answered… and I don’t want to butt in… but this just doesn’t look right to me…

I took a REALLY QUICK look at your code… and it apears to me like you could really improve the performance of it…

It seems like you’re actually looping though all the documents in the view “Coreview” until you get a match with the proposal number of the current document. Then when you find a match you use a goto to jump out of the loop and and do something based on wether you get a match or not…

There’s a lot of code and I might be off base but here are some quick observations…

  1. You shouldn’t loop through all the documents in the view looking for a match… use the getdocumentbykey method and if necesary have a hidden view that has all the documents sorted by proposal number.

  2. It’s a matter of personal opinon… but Goto’s are bad… with the exception of “On Error Goto”… I would try and stay away from them… Because of the way you did this… the “Creating” block is always going to run regardless… this requires you to use the strExists flag…

  3. when you hit your first creating section… you create a new document and then immediately test the document that you created to see if it is a new document… Seems redundant…

  4. I’m actually surprised your not getting an error if a match is NOT found…

                                             If Not CoreViewDoc Is Nothing Then 
    
     	CoreViewDoc.Form = "Core Proposal Form Tabbed"
    
     	Msgbox "This is a modified document"	
    
     	CoreViewDoc.ProposalManager = uidoc.FieldGetText("ProposalManager")
    
     	CoreViewDoc.ServiceEstimator = uidoc.FieldGetText("ServiceEstimator")
    

    If CoreViewDoc is Nothing then you shouldn’t be able to assign fields to it…

Here’s the structure that I would consider using for what I THINK you’re trying to do…

Set CoreViewDoc = CoreView.getdocumentbykey(uidoc.FieldGetText(“ProposalNumber”))

if CoreViewDoc is nothing then

’ No Match Found - Add Appropriate Code

else

’ Match Found - Add Appropriate Code

End If

Hope this helps…