Solved

Triggering an agent from JavaScript

Posted on 2003-11-16
26
582 Views
Last Modified: 2013-12-18

How do I start an agent running from JavaScript.  My web form has a hotspot button which launches a pop up window.  Within the pop up window the user can select a value from a drop down list.  When they click on OK button on the pop up window the value selected is written to a field on the original form (using Javascript), and I also want to manipulate half a dozen other fields in the main window.  This is complicated by the fact the the other fields are all multiple value fields and the value selected on the pop up box determines which values to manipulate in the multiple value fields.  I figure I could do this when the OK button is pressed on the pop up window using JavaScript, but as my Javascript is not too hot I am looking to trigger an agent to do the manipulation instead.

I'd appreciate ideas on whether triggering the agent is the best approach or whether I should concentrate on doing it all in OK hotspot button on the pop up Window.

Thanks.
0
Comment
Question by:StuartCalam
  • 12
  • 10
  • 4
26 Comments
 
LVL 19

Expert Comment

by:madheeswar
ID: 9761123
Java Script will be triggered in the client side. This method is faster than any method.

If ur running Agent, it will take sometime.

to run an agent:
http://servername/dbname/agentname?openagent

What are the calculations ur doing?
0
 

Author Comment

by:StuartCalam
ID: 9761141

I have six multiple value fields each with the same number of entries. What I want to do is get the value selected by the user in the pop up box, and delete the corresponding values in the other fields.

So...

Field 1 = Red : White : Blue :Green
Field 2 = Monday : Tuesday : Wednesday :Thursday
Field 3 = Dog : Cat : Fish : Bird.

On the pop up box the user can select the colour.  If they select Blue for example, then I need code which will delete Wednesday and Fish from the other fields on the main document.
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9761147
I know only Lotus Script and I am not much aware of JScript.

Lets wait whether other experts can give answer for it or not.

If u r looking for a LScript, let me know. I will write it for you.

-madheeswar
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9761167
This is much more easilyhandled by js.  However, we need to know what the field type is of the three fields -- checkboxes, plain text, list boxes... what?

The reason this is important is that each field type has a different way of accessing the multiple values.  Text fields will have a separator -- usually comma, but we need to know what specifically.  Manipulating it involves splitting it into an array, finding the appropriate element, and removing it.  SELECT field (list box) and checkboxes are already arrays, and it is a matter fo finding the right array elements, and urning off a flag that indicates it is selected.

Of course, with selects/checkboxes, I'm not sure  whether you want to manipulate what is turned on, or what is avaialble as a choice. You need to let us know that, too!
0
 

Author Comment

by:StuartCalam
ID: 9761170
Thanks for your help.

Not sure how well I can use Lotusscript as I need to do validation etc in the button before passing the values through?
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9761176
Qwaletee is here.
And don't bother from now. he can handle it easily. Just give the info he is asking for.
Implement Java Script.
Best of luck.
0
 

Author Comment

by:StuartCalam
ID: 9761188

whoops - cross comments!

The fields I want to manipulate are (computed) text and numeric fields.  All are multiple value fields, using the New Line option to separate values.

I don't want to manipulate any options available to users or anything like that.  Just delete the corresponding values from the other fields depending on the value selected in the pop up window

0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9761293
Ah, computed field!  SO, effectively, there is no matching field on the main form, because computed fields are turned to HTML text, not HTML fields.

Is the form in edit mode, read more, or are both possible?
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9761303
Why can't we have an editable field(Hidden) and have all the values in computed field and delete values from editable fields and append new values to computed values?

Need to know how computed fields are going to have values. May be using @DbLookup/@DbColumn.

If it is the case, then assign the same to editable fields and append.

I think this logic may work.
0
 

Author Comment

by:StuartCalam
ID: 9761337

Form is always in edit mode when this is being done.  The computed fields are computed to themselves so no lookups or anything are being done to get there values.  They are being set somewhere else on the form but that is tomorrows headache!
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9761384
What you will need to do then is a bit tricky.  Here's why.

Let's say, in addition to the computed list fields you mention, you have a COMMENTS field (or other editable field), and the button that launches the po-up.

User changes comments, then clicks the pop-up.

Problem #1 if we just run an agent directly: What of the main document window was a new document and never saved before?  There is nothing for the agent to run agianst!

Problme #2: Let's say the document was previously saved.  We can't have the pop-up ignore the main window and run an agent -- what would update the main window with new values?  It would not "know" an agent ran, and would stay where it is!

Problem #3: Let's say you have the pop-up pass control back to the main window, and somehow have  the pop-up cause the main window t run the agent.  if all it does is change the URL, then any changes to the COMMENTS field would be lost.

Here's what I suggest to get around all of this.  When the user clicks the "pop-up button," instead of loading the pop-up directly, what the form should do is submit itself, save the changes, and come back with the pop-up screen.  When the user makes a selection in te pop-up screen, it submits itself, which makes teh changes on the original document, and teh window loads again with the original document once more, now modified of course.

Does this course of action make sense to you?
0
 

Author Comment

by:StuartCalam
ID: 9761427


Tricky indeed!!
We can certainly save the document both before and after the pop up box opens if that helps.  Or are you saying we would not have a second window opening for the pop up box?  If possible I would rather keep the pop up box as the users are keen on it.

I can get the value from the pop up box to the main document quite easily so is it possible to have another flag field on the main document?  This could be hidden editable field and when the pop up box value is entered the flag is set.  I could then have the script in the onChange event of the flag field?  

0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9761477
Well, yes you could do that... I will restate this just to make sure we both mean the same thing.

You will place a flag field, type text, NOT HIDDEN on the form, but with HTML attributes set to TYPE=HIDDEN.  The pop-up window, when it closes, will set a value for this HTML hidden flag input field, so that when the document is submitted, the server cde knows what to do.  The pop-up window will also force the main window to submit itself when closes.

So, the pop-up close sequence is:
1) set hidden field value of main
2) submit main
3) close self (pop-up)

Server shoudl then, if it sees the hidden field filled in, do the "reove" processing from teh three hidden fields, clear the value of teh hidden editable field, and redisplay the document again in edit mode.

Is that all correct?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:StuartCalam
ID: 9761492

Yes - Sounds good to me; although why can we not hide the flag field that we want to set?
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9761530
If you hide it in Notes, it doesn't go over to teh web browser at all, and there is therefore no way for your browser-side script to pass a value through it.

Here's thenext problem: Open database properties. Look for the setting, "Use Javascript when generating pages"  Is it on or off?

If it is off, we have an easier time of it.  If it is on, there might be a few bumps on the orad.  Do not turn it on or off unles you understand the full consequences of it.

Here's why it makes a difference.

When yuo have this value OFF, any submission of a form is treated the same, no matter how it occurs.  When you have it on, Notes adds some Javascript so it can determine which button or link or image you clicked to do the submit... and we won't be clicking any of them in our pop-up-driven submit.
0
 

Author Comment

by:StuartCalam
ID: 9761559

Great news. Option is turned ON.
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9769288
Would have been easier if it wasually.  t is late, I'm tired, please post tomorrow so I'll get a reminder e-Mail to work on this.
0
 

Author Comment

by:StuartCalam
ID: 9775107
ok - thanks for all your help with this...
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9776834
OK, this is what we will do.

Let's say that your three fields are named F_COLOR, F_DAY, and F_ANIMAL.  Move them to the top of the form.  Make them EDITABLE, visible, and allow multiple values.  HTML attributes should be "TYPE=HIDDEN" for all three.

F_COLOR should have a translation formula of @Trim(F_COLOR) -- that will remove empty values when we turn selected item from pop-up to blank.  Similar for other two fields.

Wheer you used to have the three fields, create three computed text blocks.  The formula for the first should be F_COLOR, the second and third should be F_DAY and F_ANIMAL. In other words, these will be non-editable displays of the current field values.

Let the user press the button to start the popup, same as you have it now, with the same exxact code.  So, no trip to the server to make a popup.

But, at close, it needs to run code something like the following:

var userChoice = .... 'set to value of user's choice on the popup
var form = opener.document.forms[0];
var colors = form.F_COLOR.value.split(","); //turns the editable field into an array
var days = form.F_DAY.value.split(",");
var animals = form.F_ANIMAL.value.split(",");
for(i=0;i<colors.length;i++) {
   if (colors(i)==userChoice) {
      //null out the deleted entry and equivalent position in other arrays is also nulled out
      colors(i) = "";
      days(i) = "";
      animals(i) = "";
      form.F_COLOR.value = colors.join(","); //if it was red,green,blue and green is removed, it becomes red,,blue, which the @Trim turns to red,blue
      form.F_DAY.value = days.join(",");
      form.F_ANIMAL.value = animals.join(",");
      form.submit();
      window.close()
   }
}


The form.submit() will send it to the server.  Since there is no "click value" for the Domino Javascript processing to work with, it will use the default form action of just saving the document; you should put in a $$Return that redisplays the document.  The @Trim removes the "nulled" field value.  The computed text picks up the changed value and displays it as read only.

I'm not quite sure I have all the pieces worked out, but it is a start.  And, the JS may be a little off.
0
 

Author Comment

by:StuartCalam
ID: 9784866

Hi,
I'm not having much joy I'm afraid.  Heres what I have...

var form = opener.document.forms[0];
                
      var srNumbers = form.srSpareNo.value.split(",");  //turns the editable field into an array
      var srDescriptions = form.srSpareDesc.value.split(",");
      var srQuantitys = form.srQty.value.split(",");
      var srPrices = form.srPrice.value.split(",");
      var srLocations = form.srLocation.value.split(",");
      var srRemarks = form.srRe.value.split(",");
      //need to get just number part of selected value;
     for(var k=0;k<spNumber.length;k++) {         // For each option inNames field
      if (spNumber.options[k].selected == true) {        // ifselected
            var srKey = window.opener.document.createElement("Option");
            srKey.text = spNumber.options[k].text;
            var srKeySplit = srKey.text.split("-");
            var srKeySelection = window.opener.document.createElement("Option");
            srKeySelection.text = srKeySplit[0];
            alert(srKeySelection.text);          
            }
      }                  

       for(var i=0;i<srNumbers.length;i++) {    
                 if (srNumbers(i)==srKeySelection) {
                 //null out the deleted entry and equivalent position in other arrays is also nulled out
                 srNumbers(i).value = "";
                 srDescriptions(i).value = "";
                 srQuantitys(i).value = "";
                 srPrices(i).value = "";
                 srLocations(i).value = "";
                 srRemarks(i).value = "";
                  form.srSpareNo.value = srNumbers.join(",");
                  form.srSpareDesc.value = srDescriptions.join(",");
                  form.srQty.value = srQuantitys.join(",");
                  form.srPrice.value = srPrices.join(",");
                  form.srLocation.value = srLocations.join(",");
                  form.srRe.value = srRemarks.join(",");
                 form.submit();
            }
      }                  
self.close();


This is in the hotspot button on the pop up window.  The alert shows that I have getting the value (I think) but immediately after the alert I am getting a 'Function Expected' error message.  

Any ideas what I am doing wrong?

Thanks
0
 

Author Comment

by:StuartCalam
ID: 9784869
sorry - should mention that spNumber is the name of the field on the pop up window.  That 'split' code is there as I only want what is to the left of the '-' in the value selected.
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9805140
Put in a few lines like:
alert("Got here #1/#2...");

So we can pinpoint where the failure is.  You don;t have to put one at every line... once you figure out a smaller range, you can sprinkle them into the right place to find the exact line (i.e., the line immediately after a working alert and before a non-working one)
0
 

Author Comment

by:StuartCalam
ID: 9808271
Hello again.

Getting there.  The reason the previous error ocured was because the following...
   if (srNumbers(i)==srKeySelection) {
      srNumbers(i).value = "";
               
Should of been...  
   if (srNumbers(i)==srKeySelection) {
      srNumbers(i) = "";


So now values is getting removed from the liston the main document.  However, the @Trim translation forumla is not working (not removing the spare comma's).  I am also uinsure about the form.submit.  I already have a $$Return field on my main document and when the pop up box does the submit the value in this field is followied and an error is generated (due to the spare comma's)
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9815745
The field containing the comma-separated values should be set to be:
1) Text
2) Allow multiple values
3) Use comma as both input separator and output separator
4) Be computed, with @Trim is formula, or editable, with @Trim as input translation
0
 

Author Comment

by:StuartCalam
ID: 9829797
Think I am getting there...

I didn't think we could use computed fields as the Javascript would not be able to retrieve the values.  I of course would much prefer the fields to be computed.  The TYPE=Hidden does not work on editable fields as the HTML code generates a textarea tag for the field.  Type is not an attribute of this tag.  
0
 
LVL 31

Accepted Solution

by:
qwaletee earned 350 total points
ID: 9834900
You are correct, computed fields are not sent as fields, so Javascript can't access them.  However, we have created a pair of Domino representations of each value: A field (F_xxxx) and a computed for display value.

HTML allows two types of text fields: regular inputs, and textareas.  Domino normally generates INPUTs, not TEXTAREAs.  Two exceptions:

1) Rich text fields -- you should be using plain text
2) Plain text fields that allow multiple values and use new line as separator.  Designate comma as input and outpit separator, and do not use new line or blank line.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

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

19 Experts available now in Live!

Get 1:1 Help Now