?
Solved

How would I do this in LotusScript

Posted on 2006-03-28
21
Medium Priority
?
478 Views
Last Modified: 2013-12-18
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


0
Comment
Question by:Jaziar
  • 10
  • 10
21 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16313820
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.
0
 

Author Comment

by:Jaziar
ID: 16313913
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
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16314268
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... ;)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Jaziar
ID: 16322654
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







0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16323504
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".
0
 

Author Comment

by:Jaziar
ID: 16324468
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.

0
 

Author Comment

by:Jaziar
ID: 16324944
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?

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16330501
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?
0
 

Author Comment

by:Jaziar
ID: 16332541
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

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16334143
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.
0
 

Author Comment

by:Jaziar
ID: 16334762
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
0
 
LVL 63

Expert Comment

by:SysExpert
ID: 16339053
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 !

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16340830
Did you already try to create the DialogBox-form using the guidelines I gave earlier?
0
 

Author Comment

by:Jaziar
ID: 16342295
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?

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16342450
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...
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16342462
You could use "NoCache" in the first field only, you can use the cached results for the other fields.
0
 

Author Comment

by:Jaziar
ID: 16342550
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

0
 

Author Comment

by:Jaziar
ID: 16342564
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
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 2000 total points
ID: 16343007
Is there some property in the person's document to indicate things have to stop there? E.g. according to his function?

Then, for disclineManager:
    x:= @DbLookup("";"domino1/Lexmark":"names.nsf"; "($Users)"; discManager; "Function");
    @If(x="Director"; @Return(""); "");
    x:= @DbLookup("";"domino1/Lexmark":"names.nsf"; "($Users)"; discManager; "Manager");
    @If(@IsError(x); ""; x)    

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

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

Is that it?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16343017
Indeed, with this many @DbLookups, some conversion into LotusScript might be easier. Try this first, though.
0
 

Author Comment

by:Jaziar
ID: 16364548
I do think this will work, once I have thought more about the logic.

Thanks

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question