[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Trouble with Code

Posted on 2006-05-05
19
Medium Priority
?
242 Views
Last Modified: 2013-12-18
Ok maybe a second set of eyes will catch something that I have missed. I have a DB that routes out training modules. I have had 5 modules which have been working fine for a while, I added a sixth module today and cannot get that to send out poroperly. If I pasted a piece of the code and eliminated the redundant items. When I test the request by selecting module 5 & 6, which are the items below, I run it through debugger and module 5 works perfectly, but when it gets to the If statement for Module 6 it skips right over it. I have looked at the properties for that field it has both "5" and "6" for the values. Also, the module6_met_flag is blank so that should not be the issue, I have even taken that out. I have been looking at every detail and cannot find any issue.  


Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace          
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Dim linkdoc As NotesDocument
      Dim rtitem As NotesRichTextItem
      Dim Item As NotesItem
      
      Set db = session.CurrentDatabase
      Set uidoc = workspace.CurrentDocument
      Set doc = uidoc.Document
      Call uidoc.Save
      Call doc.Save(True, True)
      Set emaildoc = db.CreateDocument
      Set emaildocb = db.CreateDocument
      
      Set Item = New NotesItem(emaildoc,"SendTo", notesnh , NAMES)
      Item.IsSummary = True  
      
      If uidoc.FieldContains( "module_met", "5" ) And module5_met_flag <> "done" Then
            Set emaildocb = db.CreateDocument
            emaildocb.form = "module5_met"    '  the document you want to email
            emaildocb.Subject = "FIELD TOOLS:  Managing Your Practice, Module 5"
            emaildocb.SendTo = doc.user            
            doc.module5_met_flag = "done"
            Call emaildocb.Send (True)
      End If
      
      If uidoc.FieldContains( "module_met", "6" ) And module6_met_flag <> "done" Then
            Set emaildocb = db.CreateDocument
            emaildocb.form = "module6_met"    '  the document you want to email
            emaildocb.Subject = "FIELD TOOLS:  Table of Contents"
            emaildocb.SendTo = doc.user            
            doc.module6_met_flag = "done"
            Call emaildocb.Send (True)
      End If
      
      Msgbox "Thank you for submitting your request.  It has been received and is being processed."
      Call uidoc.Save
      Call uidoc.close
End Sub
0
Comment
Question by:jforget1
  • 8
  • 6
  • 4
  • +1
19 Comments
 
LVL 14

Assisted Solution

by:p_partha
p_partha earned 400 total points
ID: 16617994
is module_met as multi field value, then you can probably check like this:

if you know that thre are going to be 2 values then
if doc.module_met(0) = "5" and module5_met_flat <>"done"

for 6

if doc.module_met(1) = "6" and module6_met_flat <>"done"
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 800 total points
ID: 16620925
Here's another set of eyes... I think you need to add Option Declare in your Options section. There seems to be a problem with the following lines

     If uidoc.FieldContains( "module_met", "6" ) And module6_met_flag <> "done" Then
          ...
          doc.module6_met_flag = "done"
 
Is module6_met_flag part of the document or not? The first line might better be
     If uidoc.FieldContains( "module_met", "6" ) And doc.module6_met_flag(0) <> "done" Then

Why do you use FieldContains?? Is module_met a string with a content like "1256" or so, so you want to test whether there is a "6" in that string? The doc-equivalent would be (I don't like uidoc operations):
     If InStr(doc.module_met(0), "6" ) And doc.module6_met_flag(0) <> "done" Then

   
0
 
LVL 18

Assisted Solution

by:marilyng
marilyng earned 800 total points
ID: 16621648
Dim workspace As New NotesUIWorkspace        
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Dim linkdoc As NotesDocument
      Dim rtitem As NotesRichTextItem
      Dim Item As NotesItem
      
      Set db = session.CurrentDatabase
      Set uidoc = workspace.CurrentDocument
      Set doc = uidoc.Document
      'Call uidoc.Save                                       'remarked out mgl
      'either save the uidoc before instantiated the doc, or save the doc, but not both
      'you'll get a replication confict.
      
      'Be sure the form that you're mailing doesn't have computed fields or subforms that are hidden and
      'specific to the database, else the user opening the form will get errors.  You might want to
      'set those hidden values to unhide when copied to clipboard.
      
      Dim emaildoc, emaildocb As NotesDocument  'mgl added
      'Now you should use doc, or back end stuff.
      Dim docisChanged As Boolean
      docisChanged = False
      
      'Module 5
            If doc.HasItem("module5_met_flag") Then
                  If Len(doc.GetItemValue("module5_met_flag")(0))>0 Then
                        Set emaildoc = db.CreateDocument
                        'Item is contained by DOC not UIDOC
                        Set Item = New NotesItem(emaildoc,"SendTo", notesnh , NAMES)
                        Item.IsSummary = True  
                        emaildocb.form = "module5_met"    '  the document you want to email
                        emaildocb.Subject = "FIELD TOOLS:  Managing Your Practice, Module 5"
                        emaildocb.SendTo = doc.user          
                        doc.module5_met_flag = "done"                        
                        Call emaildoc.Send (True)
                        docisChanged = True
                  End If
            End If
            
      'Module 6
            If doc.HasItem("module6_met_flag") Then
                  If Len(doc.GetItemValue("module6_met_flag")(0))>0 Then
                        Set emaildoc = db.CreateDocument
                        'Item is contained by DOC not UIDOC
                        Set Item = New NotesItem(emaildoc,"SendTo", notesnh , NAMES)
                        Item.IsSummary = True  
                        emaildocb.form = "module6_met"    '  the document you want to email
                        emaildocb.Subject = "FIELD TOOLS:  Table of Contents"      
                        emaildocb.SendTo = doc.user          
                        doc.module6_met_flag = "done"
                        Call emaildocb.Send (True)                        
                  End If
            End If
            
            If docisChanged Then
                  Call doc.Save(True, True)
            End If
            
            If uidoc.editmode Then
                  Call uidoc.refresh
                  'Call uidoc.Save
            End If
            
      Msgbox "Thank you for submitting your request.  It has been received and is being processed."
      Call uidoc.close
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16622622
Just a remark:
>     Dim emaildoc, emaildocb As NotesDocument  'mgl added
emaildoc is declared as a Variant here...

0
 
LVL 18

Expert Comment

by:marilyng
ID: 16622718
oops.. thanks.
0
 

Author Comment

by:jforget1
ID: 16629926
The weird part here is that this code is working perfectly for 5 modules prior to this and for some reason it does not like the 6th item I had to add last week. I will try the suggections above.
0
 

Author Comment

by:jforget1
ID: 16630111
OK I have figured out what the issue is related to here, the selection for these items is below. THe problem appears to be that it is picking up the reference number from the digit after the word Module and not the alias after the "|" symbol. If I add 6 to the last item it sends out porperly. I also tried changing the number to a textual representation. When I do that it does not send any of the items. What is the best way to set these up so it sends properly, I would prefer to have the number in the description for 1-5 and no number except for the alias on number 6.

Example 1
Module 1 The Basics | 1
Module 2 Prospecting | 2
Module 3 Marketing Yourself | 3
Module 4 The Sales Process | 4
Module 5 Managing Your Practice | 5
Field Tools Table of Contents | 6

Example 2
Module One The Basics | 1
Module Two Prospecting | 2
Module Three Marketing Yourself | 3
Module Four The Sales Process | 4
Module Five Managing Your Practice | 5
Module Six  Table of Contents | 6
0
 

Author Comment

by:jforget1
ID: 16631280
I have looked throught the help files and I should be able to use the method as in example 2 above, but for some reason the script does not seem to pickup the alias at the end of the choice in the dialog box. Do I need to tweak the code so it will pickup the alias?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16631437
Where are those texts from?? In a DIalog List field? I cannot find the "|" anywhere in your code...
0
 

Author Comment

by:jforget1
ID: 16631499
It is an editable checkbox field which is the module_met field referenced in the code.
0
 

Author Comment

by:jforget1
ID: 16631541
I also tried changing the script to look for "| 1" and that did not work.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16631673
Ah, I understand. That's in my first post already! Why do you use FieldContains?? If all your options have an alias like "xxx | 6", then you just have to test like I have in the last paragraph there:
     If InStr(doc.module_met(0), "6" ) And doc.module6_met_flag(0) <> "done" Then

What's your current code?

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16631680
Free tip:
    Try as much as possible to avoid the use of uidoc (NotesUIDocument)
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16631999
jForget1-

if the selection is multivalue, then you would have an array of values: "1":"2":"6"
If the selection single, then the value in the field is "1" or "2"

So, if I was doing this on a form, then @if(Module_met = "5";...) would test for only that.  If it has more than one value and the value can be either 5 or 6 then:
     @if(@Contains("5":"6";Module_Met);"do this";"else do this")


back end example:  
  Dim tmpVar as variant
  tmpVar= Evaluate({(@if(@Contains("5":"6";Module_Met);"True";"False")},doc)

Or check for "5"
   Dim tmpVar as variant
  tmpVar= Evaluate({(@if(@Contains(Module_Met;"5");"True";"False")},doc)

Agree with sjef, avoid front end.

 
0
 

Author Comment

by:jforget1
ID: 16632180
Sjef, the code above "    If InStr(doc.module_met(0), "6" ) And doc.module6_met_flag(0) <> "done" Then" works but only seems to for one selection. Can I tweak this to account for more than one value?
0
 

Author Comment

by:jforget1
ID: 16632264
I ended up using another method which worked, I left it as is, but changed what it was looking for in the field to be the word for each option One, Two, Three etc.

If uidoc.FieldContains( "module_met", "One" ) And module1_met_flag <> "done" Then
            Set emaildocb = db.CreateDocument
            emaildocb.form = "module1_met"    '  the document you want to email
            emaildocb.Subject = "FIELD TOOLS:  The Basics, Module 1 "
            emaildocb.SendTo = doc.user            
            doc.module1_met_flag = "done"
            Call emaildocb.Send (True)
      End If
      
      If uidoc.FieldContains( "module_met", "Two" ) And module2_met_flag <> "done" Then
            Set emaildocb = db.CreateDocument
            emaildocb.form = "module2_met"    '  the document you want to email
            emaildocb.Subject = "FIELD TOOLS:  Prospecting, Module 2"
            emaildocb.SendTo = doc.user            
            doc.module2_met_flag = "done"
            Call emaildocb.Send (True)
      End If


Appreciate all the help
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16632922

    Dim tmpVar as variant
    tmpVar= Evaluate({(@if(@Contains("5":"6";Module_Met);"True";"False")},doc)

Would have allowed for either 5 or 6, so your select would have been:

    if tmpvar(0)="True" and module1_met_flag <> "done"  then


You gave up too fast!
0
 

Author Comment

by:jforget1
ID: 16634111
OK now I am really baffled, when I test these they all work perfectly, but now I have a bunch of users with Editor access who whe they select the new 6th module, they are getting a you are not authorized to perform that operation. But it only happens for this one selection. When I bumped one test user to Mgr they did not get the error. Also the graphics which show up in the image resource on the server are not showing up in the email the user is getting.

I am hoping this whole issue may be related to time to replicate to a server and will correct itself by tomorrow. Any ideas how one item in a checkbox selection could give a not authorized error?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16634252
Not the faintest idea. We only get to see part of your code, so I couldn't tell you where a Not Authorized comes from. Most likely is a doc.Delete or so, although even a Manager can be disallowed to delete documents. Another good possibility is the modification of a view using LotusScript. Suggestion: promote it to a new question.

Thanks for the reward :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

825 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