Button to Agent

Posted on 2003-10-21
Last Modified: 2013-12-18
How can this code be changed to work in an agent as opposed to where I currently have it... in a button?  I'd rather have the button trigger the agent.

Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Dim curdoc As NotesDocument
      Dim db As NotesDatabase
      Dim view As NotesView          
      Dim PartNo As String
      Dim answer As Integer
      Dim codeType As String
      Set uidoc = workspace.CurrentDocument
      If uidoc.IsNewDoc Then
            Set curdoc = uidoc.Document
            Set db = curdoc.ParentDatabase
            Set view = db.GetView("VendorTable")'All Fields Values sorted
            PartNo = uidoc.FieldGetText("ven_num") 'The FieldName you want to check
            Set doc = view.GetDocumentByKey(PartNo)
            If Not (doc Is Nothing) Then
                  Forall i In doc.Items
                        If (i.Text = PartNo) Then codeType = "Vendor Number"
                  End Forall
                  answer = Messagebox( "Duplicate " & codeType & " found. Switch to existing Vendor document?", 1+32, "Duplicate Vendor Document")
                  If (answer = 1) Then
                        curDoc.SaveOptions = "0"
                        Call uidoc.Close          
                        Delete uidoc
                        Call workspace.EditDocument(True, doc)
                  End If
            End If  
      End If      
End Sub
Question by:schmad01
LVL 24

Accepted Solution

HemanthaKumar earned 125 total points
ID: 9594072
If this is an agent that is run in foreground via agent, then you can just copy and paste it in initialize event . And call it from button either using simple action "Run Agent" or ToosRunMacro command

This cannot be a scheduled/background agent.


Expert Comment

ID: 9594152
Put the code in the agent with properties as :

Shared agent

Manually from Agents List

Run Once @Commands May be used.


Paste the code in the initialize event.

Now, create a button and have the

@command([ToolsRunMacro];"AGENT NAME")

to run the agent.  Make sure you use (Agent Name) with in paranthesis since the agent will be hidden in this case.

Good Luck!


Author Comment

ID: 9594186
Thanks alot.  I was pasting it in Declarations, no wonder I was getting errors.
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.


Expert Comment

ID: 9594197
LVL 31

Expert Comment

ID: 9594217
You shoudl have been able to paste in (Decalartions), and Notes should have created a new subroutine automatically.  Well, water under the bridge, I guess.

Expert Comment

ID: 9594227
well if you dont have sub initialize and end sub copied into your clipboard then you will get these kinds of errors right ?
LVL 31

Expert Comment

ID: 9594272
Nope, you will just have an empty initialize, and a sub called click that is never executed

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now