Agent Update manually but not in schedule

Hi all

I am hoping someone could help me out.

I am trying to create an agent that run's on a certain view, which will check values on a document and if the values are different it need's to update my history and update the field to the new price.

All is working great on the agent if i run it manually, but as soon as i switch it over to run on schedule nothing happens. And yes i did check on the server to see if there is any errors and there is nothing and can also see it did run with a certain amount of ticks.

This is my current code. And if someone could please assist it would be great.

Sub Initialize
Dim view As NotesView
Dim doc As NotesDocument
Dim s As New NotesSession
Set db = s.CurrentDatabase
Dim Retail1LHis As Variant
Dim TotalRetailP As Variant
Dim Product As Variant
Dim item As NotesItem
Dim statement As String

Set view = db.GetView( "Price list" )

'// loop thru all docs in Price list view.

Set doc = view.GetFirstDocument
If doc.HasItem("Retail1LHis") Then
While Not(doc Is Nothing)

new_value = doc.GetItemValue( "Retail1LHis" )
new_value1 = doc.GetItemValue( "TotalRetailP" )
Product1 = doc.GetItemValue( "Product" )

If new_value(0) = new_value1(0) Then
Else



statement = +"On"++" "+Cstr(Now) + " - " + +"The Retail Price of" +" "++Product1(0)+" "+"1L changed from"+" "+Cstr(new_value(0))+" "++"to"+" "+ Cstr(new_value1(0)) +" "+" - " + "Document changed by" +" "+ s.CommonUserName


Set item = doc.GetFirstItem("History")
Call item.AppendToTextList(statement)

Call doc.ReplaceItemValue( "Retail1LHis", new_value1(0))
Call doc.Save( False, True )
End If
Set doc = view.GetNextDocument(doc)
Wend
End If
End Sub

Kind Regards

Hi,

As basic troubleshooting, please first check if this agent is listed in AMGR task or not.

Issue below command on server console.

"tell amgr sched"

Confirm if this agent is listed or not in scheduled agent list.

If not, then restart AMGR task and confirm the situation.

Refer to below URL for more information.

1. Troubleshooting Script for Notes Scheduled Agents (and Agent Manager)

2. What is the purpose of the TELL AMGR SCHED Server Console command?

Can you please refer to below steps and confirm the outcome of same.

1. Please check if below property is checked or not in your impacted database.

2. Please add few PRINT statement in your code. See what happens when the scheduled agent runs.

Check the logs.

3. You have mentioned that -->

And yes i did check on the server to see if there is any errors and there is nothing and can also see it did run with a certain amount of ticks

Can you elaborate more on bold part?

Share the logs when this agent runs and stops. What is outputted in log?

4. Can you try to create another schedule agent(with lets say having just one PRINT statement) in same database and check if it runs.

5. Are there any other scheduled agents present on same database that are running fine?

6. If issue is related to only one database, please perform maintenance task on this database.

Try to reproduce the issue again.

Also refer to agent properties and check what values are present in below highlighted two tabs.

Regards,

Amit Sharma

Hi

Amit Sharma
Thank you for the kind reply
I have checked the following:
There is no tick.
I do have other agents that is also running on the server and all of them are working correctly, but i did disable them just to make sure it does not interfere with this one so only this agent is running currently.
This is the return that i get from the server regarding the ticks
I think it could be my code that is perhaps wrong, i am still very new to Lotusscript coding.
If i may ask how do i go about entering a PRINT statement in my code? And would that show on screen or how does it work?
Kind Regards
500 points - Enthusiast

I think it could be that my coding is wrong but i don't know where. I am still very new to the lotusscript coding.

If you where talking about putting PRINT statement in the code, what does it do? and does it show on screen?

Kind Regards

Can you share other information requested.

You have other agents on server but do you have any other scheduled agent on this impacted database.

Create a new scheduled agent such as -->

Sub Initilaise

Print "This is test agent"

End Sub

Check if this agent runs. If yes, then it will Print "This is test agent" on log.

In your code, you can add PRINT statement as below. It will show on screen.

Sample example -->

Set view = db.GetView( "Price list" )

Print "This is view"

'// loop thru all docs in Price list view.

Set doc = view.GetFirstDocument

Print "This is doc"


If doc.HasItem("Retail1LHis") Then
While Not(doc Is Nothing)

new_value = doc.GetItemValue( "Retail1LHis" )
new_value1 = doc.GetItemValue( "TotalRetailP" )
Product1 = doc.GetItemValue( "Product" )

If new_value(0) = new_value1(0) Then
Else



statement = +"On"++" "+Cstr(Now) + " - " + +"The Retail Price of" +" "++Product1(0)+" "+"1L changed from"+" "+Cstr(new_value(0))+" "++"to"+" "+ Cstr(new_value1(0)) +" "+" - " + "Document changed by" +" "+ s.CommonUserName


Set item = doc.GetFirstItem("History")
Call item.AppendToTextList(statement)

Call doc.ReplaceItemValue( "Retail1LHis", new_value1(0))
Call doc.Save( False, True )

I guess you have enable Debug parameter in notes.ini.

That's why you are getting these messages like "1" ticks performed etc.

There must be notes.ini parameter like "Debug_AMgr = <some value> present.and hence such output appearing.

Refer to below URL -->

1. How can you monitor an agent's execution time

2. https://xpagesandmore.blogspot.com/2020/10/troubleshooting-hcl-notes-debugging.html

I will check the code to see if it has some issue.

Allow me some time for same.

Regards,

Amit Sharma

Hi Amit,

Yes i did enter Tell Amgr debug * in the console, because i wanted to see if there was any errors displaying and to see if the agent is actually running.

I did put some "PRINT" statements through the code and i got all the "This is view","This is doc" and "This is end" displayed.

Great it means that your agent is running.

It is just that its not working or updating the document like it does manually.

Can you share agent settings as requested earlier from "Basics" and "Security" tab.

Also share the agent schedule like at what frequency it is set to run.

Regards,

Amit Sharma

Hi @Heinrich Lubbe

I created an agent using your code and found some errors in it. I have rectified those errors and pasting the updated code below. I have not tested this code. You can test this code in your test server and ensure if it is working as per your expectation. I hope this helps.

Sub Initialize
	Dim view As NotesView
	Dim doc As NotesDocument
	Dim s As New NotesSession
	Dim db As NotesDatabase
	Set db = s.CurrentDatabase
	Dim Retail1LHis As Variant
	Dim TotalRetailP As Variant
	Dim Product As Variant
	Dim item As NotesItem
	Dim statement As String
	Dim new_value As String
	Dim new_value1 As string
	Dim Product1 As String
Set view = db.GetView( "Price list" )

'// loop thru all docs in Price list view.

Set doc = view.GetFirstDocument
If doc.HasItem("Retail1LHis") Then
	While Not(doc Is Nothing)

		new_value = doc.GetItemValue( "Retail1LHis" )
		new_value1 = doc.GetItemValue( "TotalRetailP" )
		Product1 = doc.GetItemValue( "Product" )

		If new_value &lt;&gt; new_value1 Then

			statement = + "On" + " " + Cstr(Now) + " - " + "The Retail Price of" + " " + Product1 + " " + "1L changed from" + " " + Cstr(new_value) + " " + "to" + " " + CStr(new_value1) + " " + " - " + "Document changed by" + " " + s.CommonUserName

			Set item = doc.GetFirstItem("History")
			Call item.AppendToTextList(statement)

			Call doc.ReplaceItemValue( "Retail1LHis", new_value1)
			Call doc.Save( False, True )
		End If
		Set doc = view.GetNextDocument(doc)
	Wend
End If

End Sub

Hi Abhay Shirke

Thank you for the code update. Unfortunately still not success, if i try to run it now manually i get on this line a "Type mismatch"

@Heinrich Lubbe

Try this...

new_value = doc.Retail1LHis(0)
new_value1 = doc.TotalRetailP(0)
Product1 = doc.Product(0)

Instead of this...

new_value = doc.GetItemValue( "Retail1LHis" )
new_value1 = doc.GetItemValue( "TotalRetailP" )
Product1 = doc.GetItemValue( "Product" )

Hi Everyone,

Got it sorted.

I created a new Agent with the name "Test" and copied all the code from the other agent exactly.

But what i have noticed, the new Agent("Test") had this:

And the old agent had this:

And the Test agent did run successfully, so i assume it has to do with "Run on behalf of"

I asked for these details in very first update.

Thanks for sharing. Looks to me it has something to with Security level. Will test the same.

Anyways glad that issue has been resolved.

Happy Friday.

Regards,

Amit Sharma

Thanks, lol yes you did Amit

Yet again thanks everyone

@Heinrich Lubbe

Good to know that it is working.

Are you using same user id (shown in "Run on behalf of") to create this agent or is it different id ?

If it is same then I would expect 1st case to run as expected.

If it is different then probably you might have to check the execution access rights of user id (shown in "Run on behalf of") in the server document.

So basically, when you add any user id in "Run on behalf of", the agent will run on server under this id. And, this id should have the edit rights, so that it can update the documents.

Yes it is actually very strange, because i am the one creating the document and the one changing it and i do have full access rights, so there should not actually be any problems