How to write @Prompt with an @Replace

I am new to trying to write agents on my own and I stumped how to combine two simple formula functions for an agent.

All I want to do is prompt a user to have a gien field value replaced with the entered value.

For example, after selecting documents to be modified, run the agent and be prompted for “New Territory Name” and after keying the value, having it replace whatever the exisiting value is in the field called “IENRegion”

I know this should be extremely elementary and I’m not sure why I’m not able to figure it out myself. Thank you in advance for any help you may provide.

This is what I have so far:

ret :=@Prompt([OkCancelEdit];Territory;“Enter Territory Name”;Richmond);

@Replace($IENUserKey04Value;“”;ret);

SELECT @All

Where “IENUserKey04Value” is the data field I want to replace with a new value on all documents I’m running the agent against.

Subject: How to write @Prompt with an @Replace

@replace sin’t for thatIt replaces one element in a list with one from another list

You really want

ret :=@Prompt([OkCancelEdit];Territory;“Enter Territory Name”;Richmond);

@setfield(“$IENUserKey04Value”;ret);

SELECT @All

But as Ben has said you’d have to enter the value for every document you select

Are they all to have the same value?

If so, split it into two

Agent two sets the fields, and runs over all selected documents

@setfield(“$IENUserKey04Value”;@environment(“retvalue”);

Agent one primes the env variable, and is a ‘run once’ agent

ret :=@Prompt([OkCancelEdit];Territory;“Enter Territory Name”;Richmond);

@setenvironment(“retvalue”;ret);

@command({toolsrunmacro];“agent two”)

Subject: How to write @Prompt with an @Replace

The code looks OK bar the fact that you will get this prompt for every document you’ve selected. Is that what you mean by posting that the code isn’t working properly? Personally I would implement this in script. Ask the user for their input once up-front, then apply the change to NotesDatabase.UnprocessedDocuments (i.e. the selection). Doint his in @formula is tricker: you probably need two agents. One to take the user input and write it to the INI file, calling the second agent. The second agent then picks up the value from the INI file and writes it to the document selection.

Subject: RE: How to write @Prompt with an @Replace

Yes, that’s one of the problems-- but it also just failed to work, period. A buddy of mine suggested using two agents as well.

He suggested:

Agent 1: “Select Territory”

territory:=@Prompt([OKCANCELLIST]:[NoSort]; “Enter Territory Name”; “Select territory:”; “”;“Richmond”:“Wherever”);

@Environment(“Territory” ; territory);

@Command( [ToolsRunMacro] ; “(SetTerritory)” )

Agent 2: (SetTerritory)

FIELD $IENREGION:=@Environment(“territory”);

SELECT @All

Either I do not know how to implement this or it has a bug in it. It also requires input on every single record and then also fails to change anything.

Subject: This works (WAS: How to write @Prompt with an @Replace)

Agent1 (trigger = “None”):

@Environment(“YOUR_VAR_NAME”; @Prompt([OkCancelEdit]; “Prompt title”;

"Prompt text"; "Default text"));

@Command([ToolsRunMacro]; “Agent2”)

Agent2 (trigger = “Selected documents”)

FIELD YOUR_FIELD := @Environment(“YOUR_VAR_NAME”);

SELECT @All