Cycle through a list of agents gives an error

2019-03-06 13:20发布

问题:

I have this code on an action button that should just run through the Agents and disable all of the scheduled agents:

   var agentList:Array = database.getAgents();
   3: for (var n=0 ; n < agentList.length; ++n ){
   4:   var name:string = agentList[n];
   5:   dBar.info(name,"Agent Name ");
   6:   var ag:NotesAgent = database.getAgent(name);
   7:   dBar.info(ag.getName());
   8:   if (ag.isEnabled()){
   9:       dBar.info(ag.getName(),"Is Enabled ");
  10:       ag.isEnabled() = false;
  11:   }
  12: }

The problem is that when I run it I get this error:

Error while executing JavaScript action expression Script interpreter error, line=6, col=38: [TypeError] Method NotesDatabase.getAgent(lotus.domino.local.Agent) not found, or illegal parameters

I know from the dBar that name is in fact the name of the first agent in the list and is a string. But it would appear that it is treating the name string as a lotus.domino.local.agent.

Am I missing something really obvious? I have Manager Access to the Database even set the max Internet access to Manager as well.

回答1:

@BillF: referring to your comments to @TimTripcony's answer:

a) LotusScript's language structure cannot be compared to what we have with SSJS: LS is a close relative to VisualBasic allowing read/write properties, whereas SSJS has a closer relationship to Java, where we usually have separate methods for reading and changing properties.

b) I think you are correct in doubting your approach of allowing the manipulation of a design element through http. A possible approach could be to write a server-side LS agent to perform your task which then could be triggered from your SSJS code. It might be necessary to use sessionAsSigner to be able to properly trigger the agent, and of course you need to make sure that only an Administrator may be able to do so.



回答2:

database.getAgents() returns a list of agents, not a list of agent names. By coercing name to string you might be able to convince the debug toolbar to tell you it is a string, but it shouldn't be.

Try this:

var agentList = database.getAgents();
for (var n = 0; n < agentList.length; n++) {
    var eachAgent = agentList[n];
    if (eachAgent.isEnabled() {
        dBar.info(eachAgent.getName(), "Is Enabled");
        eachAgent.setEnabled(false);
    }
}

Note in particular the substitution of setEnabled() in the last line of the if...



回答3:

In LotusScript language Notesdatabase.Agents returns an array of NotesAgent objects.

I never tried in SSJS to day, but SSJS Domino Designer Help has this to say for the database.getAgents() method (see IBM Domino Designer XPages Reference > Domino > NotesDatabase (JavaScript)):

Syntax
getAgents() : java.util.Vector

Usage The elements of the return vector are of type NotesAgent

and in the example that follows a java iterator is used to loop through the list of agent objects returned (looks exactly like your task, really):

var agents = database.getAgents().iterator();
var list = "";
while (agents.hasNext()) {
    list = list + agents.next().getName() + "\n";
}
return list

Designer Help isn't all that bad, really ;)



回答4:

AS Tim wrote you need to setup that the ACL Maximum Internet name and password is set to at least Designer otherwise this will fail.