Link to home
Start Free TrialLog in
Avatar of Jaziar
Jaziar

asked on

How would I do this in LotusScript

How would I change this to LotusScript

@If(@IsNewDoc; @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; tmpFrom; "Manager"); ManManager);
@If(@IsNewDoc; @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; ManManager; "Manager"); lineManager);
result := @If(lineManager = "John Smith";
                                     @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; "Mike Smith"; "Manager");
                                     @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; lineManager; "Manager"));
@If(@IsNewDoc; result; ManagerA)

Thanks


Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Smells like a rent-a-coder job, Jaziar...

Also, there seems some code missing. The resulting values of the first two lines are discarded!

Where is this code anyway? In an agent? A field? Is it just a small part of a larger module??

Conclusion: Bad code, cannot translate.
Avatar of Jaziar
Jaziar

ASKER

rent-a-coder - hmmm

The lines where cut and paste from 4 differnt fields.  Right now when the form opens those fields are computed and populated.  But I need a dialog form that when the click a action button the dialog form (Disc) opens with the fields in the Disc form populated, not the main form.  Each field on the Disc form with be a names field with lookup abilites.  If the names are ok when the user clicks ok on the disc form the fields on the main form fill in.

what this is doing is running through an address book and pulling a managament chain, the list of names then becomes a workflow approval list.  Buy populating it in a dialog form, it gives the user the ability to change a name in the workflow.  The reason I have to do it in a clicked button is that there are differnt managment chains it may have to pull, so I will hide the non-needed ones.

this is all I have

Sub Click(Source As Button)
      Dim session As New NotesSession
      Dim uiDoc As notesUiDocument
      
      Dim doc As NotesDocument, dialog As NotesDocument
      Dim ws As New NotesUIWorkspace
      Dim s As New NotesSession
      Dim db As NotesDatabase
      Set db = session.CUrrentDatabase
      Set dialog = db.CreateDocument
      Set uiDoc = ws.currentDocument    
      flag = ws.DialogBox( "Disc", 1,1, 0, 1, 1, 0, "title", dialog)
      If Not flag Then Exit Sub
Okay, now I understand, it's fourmulas :)

I'll give you some serious hints, but it's almost 22:00 out here so I'd like to call it a day...

    Set view= db.GetView("($Users)")
    Set doc= view.GetDocumentByKey(doc.tmpFrom(0), True)
    value= doc.Manager(0)

    Set view= db.GetView("($Users)")
    Set doc= view.GetDocumentByKey(doc.ManManager(0), True)
    value= doc.Manager(0)

    Set view= db.GetView("($Users)")
    If doc.LineManager(0) = "John Smith" Then
        Set doc= view.GetDocumentByKey("Mike Smith", True)
    Else
        Set doc= view.GetDocumentByKey(doc.LineManager(0), True)
    End If
    value= doc.Manager(0)

Assuming all fields are on the document itself, and you add or change "doc" to "dialog" wherever appropriate.

Bye for now, I hope the good fairy will take over... ;)
Avatar of Jaziar

ASKER

Bosman,

Set view= db.GetView("($Users)") <- I do not have all the users and thier relationships to managers listed in the database.  That is why the formulas are pulling information from a Address book.  I would be impossible to list all management chains.

Can I do something like this

Set Addressdb = session.Addressbook location
   
    Set view= Addressdb.GetView("($Users)")
    Set doc= view.GetDocumentByKey(doc.tmpFrom(0), True)
    ->value= doc.Manager(0)

Let me make sure I understand your hints

Set view= db.GetView("($Users)")
Set doc= view.GetDocumentByKey(doc.tmpFrom(0), True)
value= doc.Manager(0)

This is going to get the manager for tmpFrom
so the next one would be

Set doc= view.GetDocumentByKey(doc.Manager(0), True)
value= doc.ManagerA(0)

etc.....

Does this sound right







Since you didn't give me the names of the fields where those formulas above were in, I couldn't tell you whether I think you're right or not... But I assume the general direction is right. The session.Addressbooks will give you all addressbooks (as NotesDatabase objects) that can be found by the user. See the Designer Help for more info. To open an explicit address book, it might be better just to use the name of the current server and "names.nsf".
Avatar of Jaziar

ASKER

field -> Manager
@If(@IsNewDoc; @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; tmpFrom; "Manager"); ManManager)

field -> lineManager
@If(@IsNewDoc; @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; ManManager; "Manager"); lineManager)

field -> ManagerA
result := @If(lineManager = "John Smith";
                                     @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; "Mike Smith"; "Manager");
                                     @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; lineManager; "Manager"));
@If(@IsNewDoc; result; ManagerA)

field -> ManagerB
result := @If(ManagerB = "John Smith";
                                     @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; "Mike Smith"; "Manager");
                                     @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; ManagerA; "Manager"));
@If(@IsNewDoc; result; ManagerB)

Sorry about giving not very detailed information - These four computed fields work with I create a document.  I am trying to do the same thing but after a button click that will load the values to 4 fields in the Disc Form (Dialog)  Those fields are named as follows

discManager
disclineManager
discManagerA
discManagerB

These 4 fields are name fields that are editable, when the form opens the names should be populated and the user should be able to change a name if needed.  The user then clicks ok and the 4 above fields populate with the correct - computed information.

Avatar of Jaziar

ASKER

Sub Click(Source As Button)
      Dim session As New NotesSession
      Dim uiDoc As notesUiDocument
      
      Dim doc As NotesDocument, dialog As NotesDocument
      Dim ws As New NotesUIWorkspace
      Dim s As New NotesSession
      Dim db As NotesDatabase
      Set db = session.CUrrentDatabase
      
                Dim Addressdb As New NotesDatabase( "", "" )
      Call Addressdb.Open( "domino1/Lexmark", "names.nsf" )      
      
                Set dialog = db.CreateDocument
      Set uiDoc = ws.currentDocument    
      flag = ws.DialogBox( "Disc", 1,1, 0, 1, 1, 0, "title", dialog)
      If Not flag Then Exit Sub
      
      Dim manager As String
      manA = dialog.discManager(0)      
      
      Set view= Addressdb.GetView("($Users)")
      Set doc= view.GetDocumentByKey(doc.tmpFrom(0), True)
      manA = doc.Manager(0)

      Call uidoc.document.save(True,True)
      Call uidoc.reload()
      
End Sub

I am trying to just get the first manager - the dialog opens but there is no value in discManager - What am I missing?

There are several ways to go, there are the following parameters:
-   how do you want to use the DialogBox
-   where do you want to do the calculations
-   what language is best

I'm not convinced that your approach is the best one for this sall problem. The fields you described, is that there is on the DialogBox?? If that's so, then you should know that the DialogBox can be used as a different layer over the same (current) document: all fields on the current document are available to the DialogBox. So, try the following:
- initialize tmpFrom correctly on your form
- use the discManager field only on the DialogBox-form!
- call the DialogBox using
    return:= @DialogBox( form ; [AUTOHORZFIT] : [AUTOVERTFIT] ; title )
    @If(return; @Do(
        @Setfield("Manager"; discManager);
        ...
    ); "")
- set the default value of discManager to
    x:= @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; tmpFrom; "Manager");
    @If(@IsError(x); ""; x)
- for the other fields, do something similar

You could say that the form and the DialogBox-form share the same data.

In your LS-code you explicitly set no-new-fields and no-field-update. Can you explain why?
Avatar of Jaziar

ASKER

My LS skills are poor, that is the reason I am trying to learn how to do these types of things.  I did not know I was setting those variables.  This is a seperate issue, but let me explain what I am trying to do with this.

Each document must have a approve workflow.  But the workflow is not the same for everyone.  Meaning, I can not have a static workflow.
when the document is created the user is asked if this is for Sales or Engineering.  If Sales is selected that means that Jeff Fortune has to be the last Approver always.

Lets say Joe Smith creates one and he works for sales his management chain is like this.

Joe Smith      <- tmpFrom
Chuck Roast  <- Manager
Sally Hunter  <- ManagerA
Jeff Fortune  <- ManagerB

So I have a button on the form that says Create Approval Workflow.  When Joe clicks the button the system goes to the address books and gets the managers and populates 4 fields in the dialog form ( the fields are hidden unless they have a value ).  At this point with the dialog open, if Joe knows that Chuck is out of town and Sam is filling in, Joe can change Chuck to Sam and hit ok.  Now the names are on the main form and they are computed so no one can change them once the document is submitted.  Now has they approve the document emails are sent to the next manager.  

But if Chuck Roast creates the document the workflow is

Chuck Roast  <- tmpFrom
Sally Hunter  <- Manager
Jeff Fortune  <- ManagerA

The system has to always stop at Jeff Fortune for Sales and Bill Doe for Engineering.  That is what I am thinking of trying to do.  My LS skills are not that strong.  If you think I am going about this the wrong way, I am open for suggestions.

Thanks for help thus far

I think I understand. A DialogBox seems the right thing to use, but you can use the "overlapping" type, i.e. the DialogBox uses the same document as the form on the screen. Try with a small example, and then build the full one. Construct the DialogBox-form with the fields, use the formulas in their simple for (without @IsNewDoc) and try it at first.

Come to think of it, how much freedom do the users have to change the approvers? Isn't the approver cycle fixed somewhere? With stand-ins when someone isn't available for some reason? These could be mentioned in the Person form.

Maybe I sound too general, but I always try to develop something for the general situation. I think it's not up to Joe to decide who's going to approve a document. Or is it? Furthermore, if any of these approvers is on holiday or otherwise unavailable, your application has to cope with that.
Avatar of Jaziar

ASKER

This is basically saying

Joe wants to hire someone.
Joe's manager has to approve it
then thier manager has to approve it
the the VP of sales has to approve it.

The approval is just a chain of command - Joe may know that his manager is out of the country and all request has to route through a differnt manager - that is why we need the ability to change.  The reason I thought it would be better to do in a action button is for the reason to know where to stop.

When the document is created there is field called Direct that is populated with Jeff Fortune or Sam White - one is VP of Sales and one VP of Engineering.  So I would have 2 create workflow buttons one for each - only the one selected shows.  

the code would check to see if the requester is the VP
if the requester is VP then the manager field in the dialog box would be populated and the script would exit
if the requester is not the vp - we get the manager for the requester from a address book
the dialog.manager field is populated with the manager name
is the manager the VP, if so we exit the code
if the manager != vp, we get the managerA from the manager
set dialog.managerA with value
is managerA = VP, if so we exit
if managerA != VP, we get managerB from managerA
set dialog.managerB with value
is managerB = VP <- Most of the time this will be yes, but we still need to check
exit code

I hope this makes more sense
I am working on something similar, and HR Is going to supply me with a set of CSV files that I can import into Notes to do Lookups for all levels of approvals. It will be automatic, with the option to override for certain levels of management ( to handle vacations etc ).
I will have 3 or 4 CSV files to handle the 3 or 4 levels needed for approvals.
You should try something similar.

I hope this helps !

Did you already try to create the DialogBox-form using the guidelines I gave earlier?
Avatar of Jaziar

ASKER

SysExpert = I am doing this because HR is not enough involved.  They are not happy about what I am doing, so I will not get any help from them.

Bosman = I did get the dialog working. Using this

 return:= @DialogBox( form ; [AUTOHORZFIT] : [AUTOVERTFIT] ; title )
    @If(return; @Do(
        @Setfield("Manager"; discManager);
        ...
    ); "")

Dialog Field value was

x:= @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; tmpFrom; "Manager");
    @If(@IsError(x); ""; x)

That worked, but I do have to check for VP, there may one to four fields that need populated.  You still don't think I should do it in a LS?

I still think LS is not necessary :)

The other fields in the DialogBox-form, did you set their default value in a similar fashion?

So for disclineManager:
    x:= @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; discManager; "Manager");
    @If(@IsError(x); ""; x)    

discManagerA:
    x:= @If(disclineManager = "John Smith";
                                     @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; "Mike Smith"; "Manager");
                                     @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; disclineManager; "Manager"));
    @If(@IsError(x); ""; x)

discManagerB:
    x:= @If(discManagerA = "John Smith";
                                     @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; "Mike Smith"; "Manager");
                                     @DbLookup("":"NoCache";"domino1/Lexmark":"names.nsf"; "($Users)"; discManagerA; "Manager"));
    @If(@IsError(x); ""; x)

Should work...
You could use "NoCache" in the first field only, you can use the cached results for the other fields.
Avatar of Jaziar

ASKER

That will work for the standard user logging in.  But not checking for the VP will cause problems.

example Joe Creates A document

Joe Bill - user
Sally Ray - Joe's manager
Bill Bob - Sally's Manager
Chuck VP - Bill's Manager (the last person to approve)


Example Sally Creates a document

Sally Ray - Joe's manager
Bill Bob - Sally's Manager
Chuck VP - Bill's Manager (the last person to approve)
Darren Direct - Chuck's Manager (Darren does not care about this and does not need to be on the list to approve

Example Chuck Creates a document

Chuck VP - Only person that needs to approve
Darren - should not be here
Jeff - president of the company
no one

I have to make sure that it stops with Chuck

Avatar of Jaziar

ASKER

I am increasing the points because I do appreicate you staying with me on this one.  I really need to get this working and your time is valuable.

Thanks
Jaz
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
Indeed, with this many @DbLookups, some conversion into LotusScript might be easier. Try this first, though.
Avatar of Jaziar

ASKER

I do think this will work, once I have thought more about the logic.

Thanks