Link to home
Start Free TrialLog in
Avatar of Faraj1969
Faraj1969Flag for Liberia

asked on

Adding Subform based on Script instruction

Hi everyone

I know how to add a subform based on a formula, but how we can do it through Lotus Script ?

Regards
Avatar of CRAK
CRAK
Flag of Netherlands image

Never tried it, but you could write a field to the document and compute the subform based on its value or use an environment variable instead of a field.
You probaply need to do so in queryopen.
I don't think this is possible. Even the subforms are loaded before the QueryOpen is fired.

My two cents...
Avatar of qwaletee
qwaletee

Sjef, I don't think that's right, QueryOpen executes before any rendering, and subforms are part of rendering.  You should be able to use QueryOpen to modify Source.Document.SomeFieldWhereYouPutTheNameOfTheSubform and then have the subform compute to SomeFieldWhereYouPutTheNameOfTheSubform

Note sure if you need to have a field on the form named SomeFieldWhereYouPutTheNameOfTheSubform
I'll test this tomorrow, if I haven't already been proven wrong... ;-)
If you do, you might want to consider a shorter fieldname: a typo in "SomeFieldWhereYouPutTheNameOfTheSubform" might get you stuck with scientifically unreliable results!
(A freebie!)
;-))
You have issues with 39-character identifiers?  Puny human.
Not really.... some of my friends have "identifiers" that long. But we often refer to to each other by shorter aliases. E.g. in the hockey rink those short identifiers provide a lot of ease when addressing team mates after a failure to score or unneccessarily losing the ball to an opponent. Pitty the membership agreement doesn't allow me to give an example. I'm sure you'd understand!
Some people have a troublesome "keybaord" though.... the longer the identifier gets, the higher the change on error.

A long as there are electronic devices involved, human error is never the issue!
How are you doing Faraj1969? Is there a light at the end of the tunnel yet or are you still groping in the dark?
Avatar of Faraj1969

ASKER

lol... I'm still groping in the dark... I usualy wait for someone to hand me the trunk, and I'll pull the rest of the elephant. I'm working on it now, just trying to manage the coding.

To put more light on the elephant, before initiating the form, I have a DialogBox that have some questions like "YES, NO" or "SINGLE, MARRIED, DIVORCED, WIDOW" and so on, based on those questions, I just compose a form, and start adding subforms, then present the form to the user to fill in. This way, I avoid the user filling unnecessary information or printing empty forms.

Cheers
Ok, here's a trunk....

I have created 3 subforms: SubA, SubB and SubC.
Each containing nothing but the letter A, B or C resp.

I created a form "LsComputedSub", containing a computed supform only. Formula: UseSub (this field doesn't really exist).

Then I added this agent (menu, run once):
Sub Initialize
      Dim WS As New NotesUIWorkspace
      Dim Session As New NotesSession
      Dim Db As NotesDatabase
      Dim Doc As NotesDocument
      Dim Choise As String
      
      Set Db = Session.CurrentDatabase
      Do
            Choise = Ucase$(Inputbox$("Enter subform (A, B or C)", "Choose subform"))
      Loop Until Choise Like "[ABC]"
      
      Set Doc = Db.CreateDocument
      Doc.Form = "LsComputedSub"
      Doc.UseSub = "Sub" & Choise
      
      Call WS.EditDocument(True, Doc)
End Sub
Public Sub TestingPhase( CRAK_Code )

          MsgBox "Initiating testing procedure for CRAK_Code, Please wait..", MB_OK + MB_ICONINFORMATION, "Information"
          Call StandBy.Testing( CRAK_Code )

End Sub
Sneaky! But can you do it from a QueryOpen, in the form itself?
Thanks CRAK, it worked nicely, I just need to manipulate it a little and try to see if it works from QueryOpen.

Grateful everyone.
Faraj,

Please be back to confirm to me that it doesn't work from QueryOpen? ;)

Sjef
I change the subform computation to:
@Environment("UseSub")

Then I dropped the agent and put this code in LsComputedSub's QueryOpen:
Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
      Dim Session As New NotesSession
      Dim Choise As String
      
      Do
            Choise = Ucase$(Inputbox$("Enter subform (A, B or C)", "Choose subform"))
      Loop Until Choise Like "[ABC]"
      
      Call Session.SetEnvironmentVar("UseSub", "Sub" & Choise)
End Sub

Like a charm, Sjef!


Faraj1969, what's with the B? Service doesn't often get as good as this!
With an environment variable? Yacky-bah!! One of those Notes 3 remnants... Should be banned.

Grade A for the pragmatic solution, but I'd given an E for the use of the neveroment var...

Sjef ;)
Well, when I thought it over again..... if I'd write a field to an existing document, what would happen if 2 people decide to open the same document at the same time?
It has also served me well in the past when I had to fire a multi-step agent. I thing in the days when a dialogbox wasn't available in script.
I had to launch an agent to provide me the dialogbox, have it launch a 2nd agent running on a set of documents in a view or so and then launch a 3rd agent to perform another single task. The three had to exchange some variables. The only was appeared to be the use of an environment var.

I don't prefer the use of environment vars, but why condemn it in advance?

What are the other two remnants?
Do you think the features added later are perfect? I dislike pages (in web apps), I can't like outlines and frames don't offer me all I need (e.g. a JS library). It's about time they offered some documentation on the NotesCrash class too! It must be either top-level or embedded in both NotesSession and NotesUIWorkspace. It probably has optional arguments like NotesDateTime and a User- or ServerName. I know it's there somewhere, but I can't get hold of it....
My objection towards environment vars is that they are just one building block too many. In Notes you can glue almost anything together, up to a point that the poor maintenance guy loses his marbles. In LS you can call Formula, I managed to "call" LS from Formula, with one agent you can start another, throw in some Java and JavaScript, some nice embedded HTML, and fix the holes with neveroment vars, not to forget C, C++ and external Java programs or Applets and VB or other COM stuff to complete the list.. To me, neveroment vars are some sort of last resort: if all else fails... Needs to be well-documented, but that must be done for almost everything in Notes.

Features of Notes? What about a better interface to UI e.g. to be able to do active frame control, and a bug-free NotesTimer?

I hope for you Faraj will reconsider his grading...
> ...last resort.... if all else fails...

I fully agree! I also make exceptions when a workaround for its use makes it a lot harder to grasp or maintain the code. An environment var is abailable to any freshman. API's aren't.....
I had to! ;-)

Never mind the grading. Bing a PE I should have put that comment differently. I should have explained or pointed to https://www.experts-exchange.com/help.jsp#hi73.
For either of us this competition isn't about points, is it? Its the challenge.... the thought of helping someone struggling with a piece of code in a different part of the world.
Hi everyone, I was just openning my email and found several comments were added here, specialy after I accepted CRAK answer.

Anyway, CRAK, I know ( A ) is a suitable grade for your solution, but I almost changed the whole solution to fit me, still working on it tho, but the idea was fantastic, at least I know its possible, and I'm very thankful for it. The only mistake I did was, that I wanted to increase the points to 100 at least, cause I can realize the code took alot of effort, but I forgot, and if EE gives a chance, I would do so.

And yes sjef, I'll be back to confirm wether it did work or it didn't...

Many thanks everyone.
Being a Page Editor, I could unaccept the question if you insist. But there's no real need to.
It wasn't that much effort....

But since to intend to become THE expert in LS computed subforms, perhaps you've figured out a solution for Sjef at https://www.experts-exchange.com/questions/21401754/Field-computed-by-WebQueryOpen-cannot-be-used-for-Computed-Subform.html
;-))
You'd make my day!  :-D
Ok, with Environment variable, as CRAK suggested, it worked also, but would it work for 3 or 4 subforms ? thats one.

Second, is there anything in LS like NotesUIDocument.InsertSubForm( "SubformName" ) ?

I find this my only wall to break so far, and to be honest, I'm almost giving up and looking for better idea to do it.

Cheers
I just tried to add 2 Computed Subforms, and I noticed registering the vars in Notes.INI, so basicaly I have to clear those vars in the INI file for the other user who checks-in so he can gets his own forms, since every new employee will check-in on the same computer, which lead me to have a conclusion that such solution, is not very practical, and therefor I have to find a better way to do it.

Thanks all for the great effort. Regards.
>...would it work for 3 or 4 subforms ?
I'd probably use multiple environment var's (UseSub1, UseSub2...) or concatenate the 4 results in one. Using @Word in the subform formula would allow you to pick the right value from the concatenated list.

>...NotesUIDocument.InsertSubForm( "SubformName" )
Nope... otherwise we probably would have mentioned it. I'm sure Sjef would have loved to slam it in my face for using an environment variable instead!  ;-))

>...I have to clear those vars in the INI file for the other user who checks-in...
Does that other user use the same INI? Doesn't that raise issues on the default user id and/or location? Or other stored settings? I have no true experience in multiple users on a PC (FYI: there are other questions in EE's knowledge base about that), but on my assignment the launch Notes through a script, that provides each user with its own INI in his personal directory.
However, you could clear the vars in the PostOpen event:
In LotusScript:
   Call Session.SetEnvironmentVar("UseSub", "")
In @functions:
   Environment UseSub:=@Unavailable
But are you sure that's neccessary? Doesn't the next user automatically get his own set of subforms asigned in QueryOpen?

May I ask a question?
What is the subform asignment based on? Isn't it just based on e.g. group membership (or better: userroles) and/or read/edit mode? I'd proces those in @functions in the subform computation.
That's the problem with my assignment, you just touched a sensitive string. lol.

The idea is, when a new employee joins the company, will have to check-in ( filling few forms using a generic ID ), after that, filled in forms will be printed, then some will go to personnel, for his file, some goes to IT, to create his ID and mail file, some goes to communications for telephone and handheld radio, some goes to HQ to start processing his payroll, and so on, and not all forms applys to all employees, thats why I need to ask few questions thru DialogBox, and based on the answers I add SubForms to Main Form. As you can see, all new employees use same ID and same INI file, I tried your solution, the one with Vars A & B, the first time it worked, but next time, they had the values, and so far I found the same subforms added, so I believe clearing the vars is necessary. But, with what you just said, it gave me an idea, that I will try now, and if it works, I'll paste it here right away.

Sjef, keep your hands in your pockets... ;-))

Cheers mate.
I can slam with other things too... ;)

Why don't you just ask everything, I mean EVERYTHING, using DialogBoxes? Then you store it all in a document, including the right values in some fields to open the right subforms. And then next time when a user opens the document, all the required subforms will be automatically opened. Add some buttons that will open a DialogBox, e.g. Payroll, Radio, Phone, etc. For the information to be displayed on the Input-form, add one multi-value text-field, separator set to newline, with value
    ra:= @Implode(@Trim(RadioNr:RadioType:...));
    pr:= @Implode(@Trim(PayRollID:....));
    ph:= @Implode(@Trim(PhoneNr:PhoneType:...));
    ra:pr:ph
so the user has at least some overview in between DialogBoxes.
My earlier example did not suffer with that: when opening a form QueryOpen gets triggered, asking you to enter a subform.
Only when you skip the question, an earlier value gets users.
What you expirience now is probably caused by the altered approach. E.g. if you only perform the subform computation for the general id, the final id won't redefine them.
Perhaps you could share your code so we can look at it?
I've changed the whole design already, decided to build 5 forms which meets most types of employees, and based on the questions, one or another form will be composed, and also used Controlled Access Sections to hide some subforms if they don't apply.

But the subject is interesting if someone would like to share us with a new idea or so.

Many thanks.
ASKER CERTIFIED SOLUTION
Avatar of CRAK
CRAK
Flag of Netherlands 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