Change Form from Action Button

Is there a way to decide which form to use based upon which action button a user clicks? I've set up Roles that allow editing of different fields for a document & a corresponding Form for each scenario. I've linked those roles to a view Form Formula, as follows:

@If(@IsMember("[EditEquip]";@UserRoles);"Equipment";"Log Usage"));

This works fine, but I'd like to present these users with an option to use either form, so I modified the formula, as follows:

        @If(@Prompt([OKCANCELLIST];"Select Function";"What do you wish to do?";"Edit Equipment";"Edit Equipment":"Log Usage") = "Edit Equipment";"Equipment";"Log Usage");"Log Usage")

This works also, but I'd like to present authorized users with 2 different action Buttons, Edit Equipment & Log Usage, & bring up the document with the appropriate form based upon which they clicked. Any ideas?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If your button is in a view, you basically just have to reset the Form field

FIELD form="Name";
<open doc here>

That should do it... sorry for the short answer, have to go :)
RayboneAuthor Commented:
This was the first (& Most obvious) thing I tried, but it presents a problem of timing: The Form Field isn't updated until AFTER the document is opened & saved. Therefore, the document opens with the wrong form.


1) Form = "FormA"
   Click Button which says:
     FIELD Form := "FormB";
   Document opens with FormA. After the document is saved, it opens with FormB next time.

2) Form = "FormB"
   Click Button which says:
     FIELD Form := "FormA";
   Document opens with FormB. After the document is saved, it opens with FormA next time.

I've tried saving it first, but I got save conflicts.
If your button is in a view, rather than a form, then you can avoid this problem. Otherwise, have your button save then close the document, then reopen it, using:


This should work (I hope) but if you are getting save conflicts then there is some other piece of code somewhere else that is causing problems. The easiest way to accomplish what you want to accomplish is to have a button on a view or navigator.

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Try something like this from a View Action Button.

Choice := @Prompt([OKCANCELLIST]:[NoSort]; "Initiate"; "Please select one of the following:"; "Form";"Form A": "Form B");
@Command([ViewSwitchForm]; Choice)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I doubt that shabala's solution will work from View Action Button as the ViewSwitchForm cannot work against the yet unopened document.  Perhaps placing it in a Form Action Button instead (to be clicked after the user opens the form?)

Is the order of the sequence unmovable?  Have you considered having them open a "generic" document layout and then allowing them pick different ways to view the currently open document using computed subforms?

If you are flexible in the order of events ("open then pick" vs "pick then open") .. I'd suggest:
1) Create a keyword field at the top of a nearly blank form.  The keyword style can be anything you like -- but limited to single value.  The field's properties should be set to refresh the form on change.
2) Create subforms to contain each of the "customized form layouts" appropriate for each role.  Also create a generic/default subform that will be displayed immediately on the initial open of the form (before the user selects a new look from your keyword field).
3) Use the computed subform feature on your main form to select (load and display) the appropriate custom subform when the user changes the keyword field.

One of the beauties of this approach is that you can combine different keyword fields based on their roles (think "hide/when") with some very sophisticated tailoring in the computed subform formula.

The drawback, however, is the order of events.  If the users can handle the order "open then pick" then this approach may work for you.
How about using script such as the following:

Dim s As New Notessession
Dim db As Notesdatabase
Set db = s.Currentdatabase
Dim docol As Notesdocumentcollection
Set docol = db.Unprocesseddocuments
Dim doc As Notesdocument
Set doc = docol.Getfirstdocument()
doc.Form = "<The new form>"
Dim w As New NotesUIWorkspace
Call w.Editdocument("1", doc)
RayboneAuthor Commented:
I found a simple answer myself using environment variables, as follows:

Button1 - Log Usage:
 @Environment("UseForm";"Log Usage");

Button2 - Edit Equipment:

View Form-Selection Formula:
        @Environment ("UseForm");"Log Usage")
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.