Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

How would I turn this formula into script

here is the formula

hs := History + @Name([CN]; @UserName) + "  " + @Text(@Today) + " - Status: " + Status + @NewLine + @NewLine;
@SetField("History"; hs)

I want to add it to this Lotus script

Sub Querysave(Source As Notesuidocument, Continue As Variant)
     Dim s As New NotesSession
     Dim db As NotesDatabase
     Dim doc As NotesDocument
     Dim collection As NotesDocumentCollection
     Dim dateTime As New NotesDateTime("01/01/2000")
     If Source.FieldGetText("IssueNumber") = "" Then
          Set db = s.CurrentDatabase
          Set collection = db.Search("Form = ""IssueNumber""", dateTime, 0)
          Set doc = collection.GetFirstDocument
          value = doc.GetItemValue("IssueNumberCounter")
          issueNum% = Cint(value(0))
          Call Source.FieldSetText("IssueNumber", Cstr(issueNum%))
          issueNum% = issueNum% + 1
          Call doc.ReplaceItemValue("IssueNumberCounter",  issueNum%)
          Call doc.Save(True, False)
     End If    
End Sub

My script skills are poor and I need the function of the formula added to the script.
0
Jaziar
Asked:
Jaziar
  • 5
  • 2
1 Solution
 
scottrmaCommented:
Add this line just before your call to Call doc.Save(True,False):

doc.History = doc.History(0) & s.CommonUserName & " " & Cstr(Today()) & " - Status: " & doc.Status(0) & Chr(13) & Chr(13)

Regards,

Scott
0
 
JaziarAuthor Commented:
Added the line

Sub Querysave(Source As Notesuidocument, Continue As Variant)
     Dim s As New NotesSession
     Dim db As NotesDatabase
     Dim doc As NotesDocument
     Dim collection As NotesDocumentCollection
     Dim dateTime As New NotesDateTime("01/01/2000")
     If Source.FieldGetText("IssueNumber") = "" Then
          Set db = s.CurrentDatabase
          Set collection = db.Search("Form = ""IssueNumber""", dateTime, 0)
          Set doc = collection.GetFirstDocument
          value = doc.GetItemValue("IssueNumberCounter")
          issueNum% = Cint(value(0))
          Call Source.FieldSetText("IssueNumber", Cstr(issueNum%))
          issueNum% = issueNum% + 1
          Call doc.ReplaceItemValue("IssueNumberCounter",  issueNum%)
          doc.History = doc.History(0) & s.CommonUserName & " " & Cstr(Today()) & " - Status: " & doc.Status(0) & Chr(13) & Chr(13)
          Call doc.Save(True, False)
     End If    
End Sub

Dont seem to be adding anything to the field
0
 
ArunkumarCommented:
wanna try something easier like this ?

macro$ = | History + @Name([CN]; @UserName) + "  " + @Text(@Today) + " - Status: " + Status + @NewLine + @NewLine |

doc.History = Evaluate( macro$ , doc )

Call doc.Save(True,False)

-Arun.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
scottrmaCommented:
Oh, sorry, you probably want to make the change in the currently open document, not the document(s) returned by your call to db.Search(), right? Do this then:

Dim thisDoc As NotesDocument
Set thisDoc = Source.Document
thisDoc.History = thisDoc.History(0) & s.CommonUserName & " " & Cstr(Today()) & " - Status: " & thisDoc.Status(0) & Chr(13) & Chr(13)
Call thisDoc.Save(True,False)

Or am I misunderstanding you? If so, please clarify want you want to do. Thanks.

Regards,

Scott
0
 
scottrmaCommented:
If you wanna do Arun's approach, you need to assign the result of Evaluate() call to a temprary variant first, then get the first element like such:

macro$ = | History + @Name([CN]; @UserName) + "  " + @Text(@Today) + " - Status: " + Status + @NewLine + @NewLine |

Dim tempVar As Variant
tempVar = Evaluate( macro$ , doc )
doc.History = tempVar(0)

Call doc.Save(True,False)

This is, again, assuming you want the change to be made to the variable you have called "doc", which is the document returned from searching your database with db.Search, followed by collection.GetFirstDocument. This may not be the same as the current document (the document from which this QuerySave is called).

Regards,

Scott
0
 
scottrmaCommented:
Either way it should work, it's just that we're not quite sure which document's History field you want to update: the current document containing the QuerySave code, or the document you got by doing db.Search()?

Regards,

Scott
0
 
JaziarAuthor Commented:
This was exactly what I was looking for - Thanks
0
 
scottrmaCommented:
You're welcome.

Regards,

Scott
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now