[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Agent runs fine when triggered manually but not when the agent is ran through a schedule

OK...I have an agent that I created to recalculate values in a form based on certain condition.  I want it only to run on documents that are pulled from a certain view.  When I created the agent and ran it manually through the Agent List, it worked fine and everything recalculated like it should have.  However, when I try to schedule the agent to run on its own, it does nothing.  The agent log says it ran but when I look at the documents that it should have recalculated on, I see that the agent did not do what I needed it to do and the values were never recalculated....any ideas?

Here is my script:

Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      
      Dim ws As New NotesUIWorkspace    
      Dim uidoc As NotesUIdocument
      Dim CMws As New NotesUIworkspace
      
      Set db = Session.CurrentDatabase
      Set view = db.GetView("Recalculate")
      
      Set doc = view.GetFirstDocument
      
      While Not (doc Is Nothing)
            Set uidoc = ws.CurrentDocument
            Set uidoc = ws.EditDocument(True,doc)
            Status=uidoc.FieldGetText("Status")
            
            NewLevel=uidoc.FieldGetText("NewLevel")
            
            If Status = "Non-Accepted" And NewLevel <> "ERROR" Then
                  Call uidoc.Close
            End If
            
            Select Case NewLevel
            Case "ERROR"
                  HighLevel=uidoc.FieldGetText("HighLevel")
            Case "ETC"
                  HighLevel=uidoc.FieldGetText("HighLevel")
            Case Else
                  Call uidoc.Close
            End Select
            
            Select Case HighLevel
            Case "Level 3"
                  NewLevel="ICL3"
            Case "Level 2 Complex"
                  NewLevel="CCCML 2"
            Case "Level 2 Chronic"
                  NewLevel="CCL2"
            Case "Level 1 RN"
                  NewLevel="IFL1"
            Case "Level 1 LPN"
                  NewLevel="CMOL1"
            Case Else
                  NewLevel="ERROR"
            End Select
            
            Call uidoc.FieldSetText("NewLevel",NewLevel)
            
            Call uidoc.Save
            Call uidoc.Close
            Call view.Refresh
            
            Set doc = view.GetFirstDocument
      Wend      
      
      
End Sub
0
jpolin1
Asked:
jpolin1
  • 2
  • 2
  • 2
  • +1
1 Solution
 
mshogrenCommented:
Hi,

It is not possible to use NotesUIWorkspace or NotesUIDocument classes in a scheduled agent.  The solution is to use doc.GetItemValue and doc.ReplaceItemValue rather than uidoc.FieldGetText and uidoc.FieldSetText.

You will have to remove all mention of your uidoc and ws objects from the code above.
0
 
marilyngCommented:
Hi jpolin1,

Yup, mshogren is right.  Scheduled agent will not run with front end classes.

Regards!
0
 
jpolin1Author Commented:
I took out all the frontend stuff and replaced with the corresponding back-end equivalents.  However,  I keep getting a type mismatch error:  

When I tried to decode pieces of it together, it seem to not like my "highlevel".  When I get the value of highlevel (highlevel=doc.getitemvalue("highlevel")), and run the TypeName function, it returns the value as a "string" but then for some reason, when I add the Select Case section, it gives me a typemismatch.  Any ideas......

Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      
      Dim Status As Variant
      Dim NewLevel As Variant
      Dim HighLevel As Variant
      
      Set db = Session.CurrentDatabase
      Set view = db.GetView("Recalculate")
      
      Set doc = view.GetFirstDocument
      
      While Not (doc Is Nothing)
            Status=doc.GetItemValue("Status")
            
            NewLevel = doc.GetItemValue("NewLevel")
            
            HighLevel = doc.GetItemValue("HighLevel")      
            
              Select Case HighLevel
                   Case "Level 3"
                       NewLevel="ICL3"
                   Case "Level 2 Complex"
                      NewLevel="CCCML 2"
                   Case "Level 2 Chronic"
                      NewLevel="CCL2"
                   Case "Level 1 RN"
                      NewLevel="IFL1"
                   Case "Level 1 LPN"
                     NewLevel="CMOL1"
                  Case Else
                     NewLevel="ERROR"
               End Select
                        
            Call doc.ReplaceItemValue("NewLevel",NewLevel)
            Call doc.Save(True, True)
            
            Set doc = view.GetFirstDocument
      Wend            
End Sub
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.

 
mshogrenCommented:
GetItemValue returns an array of values.  You want the first one so try this

HighLevel = doc.GetItemValue("HighLevel")(0)
0
 
marilyngCommented:
Ah,

 Dim NewLevel As Variant
 Dim HighLevel As Variant

You  instantiated newLevel and highLevel as variants, but it would seem that the field "New Level" and "High Level" are not multivalue fields, hence the type mismatch, I think.

0
 
Sjef BosmanGroupware ConsultantCommented:
Even for single-value items, an array is returned.
0
 
jpolin1Author Commented:
Thank you everyone for all your help...I finally got the agent working.  

These are the changes I had to make:

Dim NewLevel As String      
Dim HighLevel As Variant
.
.
.
HighLevel = doc.GetItemValue("HighLevel")(0)


0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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