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
LVL 5
jpolin1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.