Agent done error on web application

Hey people. I’m very new by using lotusscript. And I need a little help of you. Sorry for my poor english too.

I’m making an agent to calculate average from two fields dates on web. The agent run and show the alert but when it finished I got the error “Agent done”.

I’ve already signed the database. In the server console theres no errors too.

Could you help me to resolve this pluzze?

Thanks in advance.

Heres the code.

MsgBox “Entrou no agente!”

On Error GoTo TrataError

Dim ses As New NotesSession

Dim db As NotesDatabase

Dim vis As NotesView

Dim col As NotesDocumentCollection

Dim contotal As Integer

Dim numeracao As Double

Dim docMig As NotesDocument

Dim doc As NotesDocument

Dim autor As Variant

Dim data() As String

Dim contpont As Long

Dim data1 As Variant

Dim data2 As Variant

Dim criacao As Variant

Dim cria As Variant

Set Webdoc = ses.DocumentContext

Set db = ses.CurrentDatabase

Set vis = db.GetView(“Autores”)

Set docMig = vis.Getfirstdocument()

Set col = db.Alldocuments

Set doc = col.Getfirstdocument()

criacao = docMig.dat1

MsgBox criacao

QueryString = Webdoc.Query_String_Decoded(0)

data1 = RetornaCampo(UCase(QueryString),UCase(“rel_data1=”))

data2 = RetornaCampo(UCase(QueryString),UCase(“rel_data2=”))

'cria = retornacampo(UCase(querystring),UCase(“dat1=”))

contpont = col.Count

contpont = 0

'criacao = RetornaCampo(UCase(QueryString),UCase(“dat1”))

If doc Is Nothing Or (criacao > data2) And (criacao < data1) Then

MessageBox “Entrou na validação incorreta!”

Print “<script language=”“JavaScript”" type=““text/javascript””>"

Print |var path = window.location.pathname.substring (0, window.location.pathname.toLowerCase().indexOf(“.nsf”) + 4);|

Print “alert('Data Fora do período inserido para análise!” “.')”;

MessageBox “Data Fora do período inserido para análise!”

Print |var path = window.location.pathname.substring(0, window.location.pathname.toLowerCase().indexOf(“.nsf”) + 4);|

Print “”

Exit Sub

ElseIf criacao < data2 and criacao > data1 Then

MessageBox “entrou no if certo, pra a analise das medias”

Print “Verificando média…”

Set doc = col.Getnextdocument(doc)

contpont = contpont + 1

End If

MsgBox contpont

contotal = contpont

numeracao = CInt(contotal/5)

Print “<script language=”“JavaScript”" type=““text/javascript””>"

Print |var path = window.location.pathname.substring(0, window.location.pathname.toLowerCase().indexOf(“.nsf”) + 4);|

Print “alert('Média de Migrações realizada durante a semana:” + CStr(numeracao) + “.')”;

MessageBox “Média de Migrações realizada durante a semana:” & CStr(numeracao), 64, “Resultado”

Print |var path = window.location.pathname.substring(0, window.location.pathname.toLowerCase().indexOf(“.nsf”) + 4);|

Print “”

TrataError:

MessageBox “Data de criação:” & criacao & Chr(13) & "Primeira data inserida: " & data1 & Chr(13) & “Segunda data inserida:” & data2

MsgBox “Erro:” + Error + Chr(10)+ " na Linha" + CStr(Erl) + Chr(10)+ “numero” + CStr(Err)

Exit sub

End Sub

Subject: Where is the main HTML?

You don’t print any HTML as output, try to add that, even if it is just one line of text.That is what I would test first.

I would also remove the MsgBox statements, you won’t have them pop up on the server anyway. They won’t hurt, but I believe in keeping the code as clean as possible…

Subject: I used the messagebox so many times cause I wasn’t able to see the errors.

OK. I’ll try this.I used the messagebox so many times cause I wasn’t able to see the errors.

The main HTML is in the form. I put the agent at the Initialize and I’ts is called from a javascript script.

Here’s the code:

function mediasemana() {

if (enviardados()) {

alert(“Verificando a média entre as datas inseridas…”)

	var url = path + "/mediasemana?OpenAgent&rel_data1=" + form.rel_data1.value + "&rel_data2=" + form.rel_data2.value  + "&1";

	form.Return.value = "["+ url + "]";

	form.submit();

Subject: OK…

Can you try to explain the whole thing from the beginning, what design elements you have and what you are trying to do?

Where is the code that you post called from?

When you call an agent, you need to have it return a complete HTML-page, you can’t just put it on a button or something and execute it.

Subject: Explanation

SO… let’s go! I’ll try this.

The application has a menu and in one option there’s a link to a form. In this form the user put the two dates to know the average of docs created in this period.

The problem is that I created two forms. One for the average and other for created date in the docs. When the user clicks in the button to see the average this button calls the javascript and runs it.

The javascript calls the agent at the code area, the agent runs (I could see it from the server console by the messagebox), and after all this I get the Error.

In the code that I showed to you, theres a querystring, which gets the values of the fields in the two forms. I think that I’ve made it in a wrong way and I don’t know how I can do it right. In the server console I see that the code can’t get the value of the docs’s form but I can’t find a way to get this without use UI doc. And I know that the UI docs doesn’t work at Web.

The HTML is on the two forms and calls a lot of scripty Libraries. The javascript I put on the JS Header, not on th body of the form.

Heres is the part of the codes…

HTML:

<!-- Declaração do CSS da visão - INÍCIO --><BR>
	<li class="wSubMenu"><a href="#">Estatísticas</a>

			<ul>

			<li><a href="javascript:mediadia();"> Média Diária por Técnico</a></li>

			<li><a href="<Computed Value>/Relatorio Tecnico semanal?OpenForm"> Média Semanal por Técnico</a></li>

			<!--<li><a href="javascript:mediasemana();"> Média Semanal por Técnico</a></li>-->

			<li><a href="javascript:mediatec();"> Média Mensal por Técnico</a></li>

			<li><a href="javascript:mediadia();"> Média Diária das Migrações</a></li>

			<li><a href="<Computed Value>/Relatorio Tecnico semanal?OpenForm"> Média Semanal das Migrações </a></li>

			<!--<li><a href="javascript:mediasemana();"> Média Semanal das Migrações </a></li>-->

			<li><a href="javascript:mediamensal();"> Média Mensal de Migrações</a></li>

				<!--<li><a href="<Computed Value>/Estatisticas?OpenAgente"> Estatísticas</a></li>-->

			</ul>

		</li>
<ul id="mnOptions">

	<li class="salvar" style="display:<Computed Value>"><a href="javascript:Salvar();">Salvar</a></li>

	<li class="editar" style="display:<Computed Value>"><a href="javascript:Editar();">Editar</a></li>

		<li><a href="<Computed Value>/Cadastro de migracao?OpenForm"><img src="<Computed Value>b_novo.gif" alt="Novo"/> Inserir Nova Migração </a></li>

	<!--<li class="sair"><a href="javascript:Sair();">Sair</a></li>-->

	<li class="sair"><a href="javascript:window.history.go(-1);">Sair</a></li>

</ul>

JAVASCRIPT:

function mediasemana() {

if (enviardados()) {

alert(“Verificando a média entre as datas inseridas…”)

	var url = path + "/mediasemana?OpenAgent&rel_data1=" + form.rel_data1.value + "&rel_data2=" + form.rel_data2.value  + "&1";

	form.Return.value = "["+ url + "]";

	form.submit();

	//alert("Cadastro salvo com sucesso!");

}

}

Subject: Explanation

OK, when you call the javascript function mediasemana(), you read the values on the current form and pass them as name-value pairs in the URL you are redirecting the browser to.

Since you are redirecting the browser to another page, the current page will go away. Your agent does not have any HTML to display, so you will get “Agent Done”.

You can’t call another webpage/URL and expoect the current page to stay visible.

Why not simply compute the resulting value in mediasemana() using just javascript?

Or you could use Ajax to call the agent, have it return the information you need/want and then update the current page.

I wrote about this on my blog just a little over a week ago: http://planetlotus.org/9df918

There is even sample code, using the YUI3 framework that makes that call in just one call.

Perhaps you need to sit down and rethink your design a little bit. In the long run, it may help you to design it in a way that makes it easier for you to do what you need.

Subject: Thanks. I’ll see your blog!

Thanks!

I’ll see your blog and make a register And think about your Idea.