Link to home
Start Free TrialLog in
Avatar of Jaziar
Jaziar

asked on

Populating a SendTo Fields

I have a view called (Users By Group) - the view is setup like this

Group             User                Email

Owner        Bob Roast          broast@email.com
Worker       Chuck Cheese    ccheese@email.com
ETC..           etc....               etc.....

I have a field in my form called GroupSelect (Checkbox)  Values= Owner
                                                                                               Worker
                                                                                               All
Then I have SendTo field

I would like for when GroupSelect = Owner - the SendTo field is set to dialogbox and shows all the users created in the database but only the ones in the owner group are checked - this would work for any selection and if all is selected all names are checked.

I was trying to use this as the default for SendTo

result := @Name([CN];@DbLookup("":"NoCache";""; "(Users By Group)"; GroupSelect; "Username"));
@If(@IsError(Result);"";result)

Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

And you set the correct properties for your fields? GroupSelect must have "Refresh document when value changes" (or whatever the name is) and SendTo must have "Refresh choices when document is refreshed". The default is okay, but what is the formula for the choices of SendTo?
Avatar of Jaziar
Jaziar

ASKER

The issue is I want to show all users from the view but only check the ones in the selected group.
Group Manager is selected the only user in the group is Joe - I also want to see Bob and Chuck just in case I need to select them

[] Bob
[] Chuck
[/] Joe

The way the code is now the only name in the SendTo is Joe
Did you set the properties as I said? What's the formula for the choices, and what's the formula for the default value? If necessary, or just for verification purposes, you could create a computed for display-field, multi-value, with the choices-formula in it, and use that field as the checkbox-choices formula.
Avatar of Jaziar

ASKER

Yes both fields refresh on the select change.

No formula on [GroupSelect] - just a check box field with the values of Owner, Worker, All

I may not be possible to do what I want.  Right now when I click owner - all the owners show up in the SendTo
                                                                           when I click Worker - all the workers show up in the SendTo

I want to see all the users from the view and the ones that are checked are from the specified group.


Group             user          

Bob              Owner                     Right Now when I select Owner in the GroupSelect FIeld
Chuck           Owner                     my sendTo dialog FIeld looks like this
Sam             Worker                                                               [ ] Bob
Linda            Worker                                                               [ ] Chuck
Stan             Worker                                                               [ ] Carla
Carla            Owner                    
                                                  I want to click the SendTo Field and see (if Owner is selected)
                                                                                             [x] Bob
                                                                                             [x] Chuck
                                                                                             [ ] Sam
                                                                                             [ ] Linda
                                                                                             [ ] Stan
                                                                                             [x] Carla
                                                  I want to click the SendTo Field and see (if Worker is selected)
                                                                                             [ ] Bob
                                                                                             [ ] Chuck
                                                                                             [x] Sam
                                                                                             [x] Linda
                                                                                             [x] Stan
                                                                                             [ ] Carla
                                                 I want to click the SendTo Field and see (if All is selected)
                                                                                             [x] Bob
                                                                                             [x] Chuck
                                                                                             [x] Sam
                                                                                             [x] Linda
                                                                                             [x] Stan
                                                                                             [x] Carla
No, ONE field should have "Refresh fields on keyword change" but the SendTo field should have "Refresh choices on document refresh"!

You might need an additional refresh to make this work, but first set the properties right.
Avatar of Jaziar

ASKER

The properties are as you stated.
So the default formula is the one you give above, and the choices formula should be something like
    result := @Name([CN];@DbLookup("":"NoCache";""; "(Users By Group)"; "All"; "Username"));
    @If(@IsError(Result);"";result)

If with "All" you get all usernames.
Avatar of Jaziar

ASKER

The names come in and out of the SendTo field correctly.  If I select Owners I get all the owners, if I select workers I get all the workers.  I want both with the correct ones checked.  I think I need to somehow change my default value formula
Avatar of Jaziar

ASKER

result := @Name([CN];@DbLookup("":"NoCache";""; "(Users By Group)"; "All"; "Username"));
    @If(@IsError(Result);"";result)

When I put this in for my GroupSelect - I dont get any choices to select from
Ah. I might have seen the light :) Is this what you want: when the field GroupSelect is changed, then you want to change the SendTo field as well? But that's not the default value. The default value is computed and used when the field doesn't have a value yet, so either when the document is created or when an existing document is opened and the form has a new field that's not in the document.

You don't want to change the default value, you want to change the real value of the field. Then you have to do a @SetField("SendTo"; ....) or so, in the PostRecalc event.

But what if the user already created the document, and he changes GroupSelect? SendTo has a value, do you want it to be overwritten?
Avatar of Jaziar

ASKER

After the document is created and sent off - the document is no longer editable.
So they can not go back and change it
Okay, if you use PostRecalc to set or reset the SendTo field, then every time the PostRecalc is called the content of the SendTo is reset to a default value, even if the user changed it, i.e. selected or deselected values. Can they save the document without it getting blocked for editing?
Avatar of Jaziar

ASKER

they create and send and then it saves - I am guessing they can save as a draft and then go in and send
Avatar of Jaziar

ASKER

I am thinking we would need something like

If NagView(view) != "" {

             IF GroupSelect = "Owner" then
                 check values from @DBLookup "Owner"
            endIF
            If  GroupSelct = "Worker" then
                 check values from @DBLookup "Worker"
            endif
}
else{
     check all values from @dblookup
}
Right... but when do you want to execute that formula? When the form is opened? How to decide the user never changed the SendTo field? Or you intend to bluntly overwrite the SendTo values? The "check values" is nothing more than a @SetField("SendTo"; ...), because all checked values are the value of that field.
Avatar of Jaziar

ASKER

should blunty overwrite the SendTo Values

If I select Owners, then change it to Workers I want the values to change.  So I say yes lets over write the values

does the formula belong in the select Group Field?
Avatar of Jaziar

ASKER

Also bosman - I want to thank you for staying with me on these issues.  I am in a tight spot on this database and your help has been and continues to be great!!!!
Avatar of Jaziar

ASKER

Are you saying that have the default value for the sendto set to show all users, then some action will assign the values with a @SetField.  If that is the case where should I run the action?
Avatar of Jaziar

ASKER

What if I did a SendTO Button and the button poped a dialog form with a field for group selection and even maybe A check box field that showed a each users name and when the user finished with the dialog and hit ok the checked values populated the actual SendTO Field on the request form?

Is this too much?
I think you'll always have problems with the single field approach.

The DialogBox or button you can always do, and it's a much better idea. I think you need 2 buttons actually: one to change the value, and one called Reset, to set it so the initial value you want. Make SendTo computed, keywords, with the choices-formula as it already has. The buttons can change the value of SendTo, but it cannot be changed directly on the form. I'd leave the group-selection field on the main form, otherwise you'd end up in the same trouble as now. What you could do, in the PostRecalc of the form, is use this formula:
    result := @Name([CN];@DbLookup("":"NoCache";""; "(Users By Group)"; "All"; "Username"));
    @SetField("SendTo"; @If(@IsError(result); ""; SendTo=""; result; SendTo))
When the fields on the form are recomputed, it would change SendTo only if it is empty. The result would be that SendTo would be populated on the first selection of GroupSelect.
Avatar of Jaziar

ASKER

can you show me a little code of what a button would look like - is it calling a form?  does the form only have one field on it?
ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

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
Avatar of Jaziar

ASKER

I have R6 but the rest of the company  has R5
Check in the R5 help db if it exists...
Avatar of Jaziar

ASKER

Ok I now see where you are going with this - I got this much working.  But it still only shows the people in the group and not everyone in the list - it may not be doable.  
But it must be doable. What are both your formulas, i.e. the default and the choices formula?
Avatar of Jaziar

ASKER

defaults:= @Name([CN];@DbLookup("":"NoCache";""; "(Users By Group)"; "All"; "Username"));
choices:= @Name([CN];@DbLookup("":"NoCache";""; "(Users By Group)"; EmailAss; "Username"));
@If(@IsError(Result);"";result);
st:= @Prompt([OkCancelListMult]; "title"; "prompt"; defaults; choices);
    @If(st=""; ""; @SetField("SendTo"; st))

When I click the button I get the correct values for each group selected.

so if Owners is picked

I get all the owners - but I need the option to add people from the workers as well.  

I wish there was a way to click the button - a dialog opens with a checkbox field.  The checkbox field displays all the users from the groups and only the users in the owner field is checked?
Swap the formulas for choices and defaults...
You can create a checkbox-field on a form to be shown in a DialogBox indeed. A lot more work... *yawn* ... not today, because I'm off in a few minutes (22:23 here). I'll read your comment in the morning.
Avatar of Jaziar

ASKER

ha ha ha - that does work - tacking on 50 extra points.  I am now in the process of cleaning this up then I will close it.
Good. Have a pleasant evening!
Avatar of Jaziar

ASKER

Good Morning Bosman,
   I would truly love to some how reflex the values that we are showing with the @Prompt with a checkbox maybe on a differnt form.  That way the user will see all the names with a checkbox.  

choices:= @Name([CN];@DbLookup("":"NoCache";""; "(Users By Group)"; "All"; "Username"));
defaults:= @Name([CN];@DbLookup("":"NoCache";""; "(Users By Group)"; EmailAss; "Username"));
@If(@IsError(Result);"";result);
st:= @Prompt([OkCancelListMult]; "title"; "prompt"; defaults; choices);
    @If(st=""; ""; @SetField("SendTo"; st))
Good morning to you too! Sorry to react this late...

I can imagine that that's what you want, a DialogBox. Bear in mind that the size of a DialogBox is always fixed, so that there is room on it for only x names. So if you only have groups at th emoment with a maximum of 6 users, don't make the DialogBox too tight, for there will be a group with 7 users some day.

The logic is pretty much the same. Instead of the @Prompt, you call a DialogBox. Sadly, the call only returns True (okay) or False (cancelled), so the DialogBox can set the new value of SendTo all by itself.

Make a new form, enclose the name in parentheses and give it a normal alias in such a way that you (and your successors) know that it's only used in a DialogBox. The DialogBox runs in the SAME document as the underlying form, so you have all its fields at your disposal.

Well, that's about the basics, but there is much more to tell about it. May I suggest to open a new question for that purpose? But first, study the DialogBox call and other information about it in the Designer Help database.