?
Solved

How would I turn this formula into script

Posted on 2003-03-13
8
Medium Priority
?
215 Views
Last Modified: 2013-12-18
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
Comment
Question by:Jaziar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 7

Expert Comment

by:scottrma
ID: 8131021
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
 

Author Comment

by:Jaziar
ID: 8131107
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
 
LVL 9

Expert Comment

by:Arunkumar
ID: 8131199
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Accepted Solution

by:
scottrma earned 2000 total points
ID: 8131210
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
 
LVL 7

Expert Comment

by:scottrma
ID: 8131242
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
 
LVL 7

Expert Comment

by:scottrma
ID: 8131279
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
 

Author Comment

by:Jaziar
ID: 8131281
This was exactly what I was looking for - Thanks
0
 
LVL 7

Expert Comment

by:scottrma
ID: 8131306
You're welcome.

Regards,

Scott
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question