Link to home
Start Free TrialLog in
Avatar of Raybone
Raybone

asked on

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(@IsMember("[EditEquip]";@UserRoles);
        @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?


Avatar of Paebdb
Paebdb

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 :)
Avatar of Raybone

ASKER

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.

Example:

1) Form = "FormA"
   Click Button which says:
     FIELD Form := "FormB";
     @Command([EditDocument];1)
   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";
     @Command([EditDocument];1)
   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:

@Command([FileSave]);
@Command([FileCloseWindow]);
@Command([OpenDocument])

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.

Zaphod.
ASKER CERTIFIED SOLUTION
Avatar of shabala
shabala

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start 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)
Avatar of Raybone

ASKER

I found a simple answer myself using environment variables, as follows:

Button1 - Log Usage:
 @Environment("UseForm";"Log Usage");
 @Command([EditDocument];1)

Button2 - Edit Equipment:
 @Environment("UseForm";"Equipment");
 @Command([EditDocument];1)

View Form-Selection Formula:
@If(@IsMember("[EditEquip]";@UserRoles);
        @Environment ("UseForm");"Log Usage")