Solved

How do you make a hyperlink within an email Notes button for a url - I'm using formula for the email text - urgent

Posted on 2009-04-07
26
1,325 Views
Last Modified: 2013-11-16
How do you make a hotspot text hyperlink within an email Notes button for a url - I'm using formula for the email text.  When the button is clicked the email newsletter is composed as a mail message , but need to make some of the text in the email note hyperlink.  Thanks


this doesnt work:   A HREF=\"http://www.ibm.com\">"BM's Home Site"
0
Comment
Question by:KTTKTT
  • 13
  • 13
26 Comments
 
LVL 22

Expert Comment

by:Bill-Hanson
Comment Utility
>> "I'm using formula for the email text"

You can't add formatted text, hyperlinks, etc using @Formula.  You'll have to switch to LotusScript to provide this functionality.

As a workaround, you could just put the URL directly in the body.  Most email clients will automatically turn URLs into hyperlinks.
0
 

Author Comment

by:KTTKTT
Comment Utility
Would this be the way to render the text as hyperlink in lotusScript?  Searching help, but not finding exactly what I need.

Call richText.AppendStyle(richStyle)
  Call richText.AppendText(A HREF=\"http://www.ibm.com">Click here</a></p>)
0
 
LVL 22

Expert Comment

by:Bill-Hanson
Comment Utility
Nope.

If you want to generate an HTML memo, you'll need to use the MIME classes.

First, tell the Notes Session not to automatically convert MIME while we are working on it.  We'll set this back to True later...

      Dim sess As New NotesSession
      sess.ConvertMime = False

Next, create the MIME entity.  This MIME will be displayed in the "Body" of the memo (Notes uses RichText fields to display MIME).

      Dim body As NotesMimeEntity
      Set body = doc.CreateMIMEEntity("Body")

Next, use a stream to set the MIME's HTML part to your HTML string...

      Dim stream As NotesStream
      Dim html as String
      html = {A HREF="http://www.ibm.com">Click here</a>}
      Set stream = sess.CreateStream
      Call stream.WriteText(html)
      Call mimeBody.SetContentFromText(stream, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)

All that's left is to restore the session property and close our MIME entity.

      sess.ConvertMime = True
      Call doc.CloseMIMEEntities(True, "Body")

That's it.
0
 

Author Comment

by:KTTKTT
Comment Utility

thanks

Getting error "Not a sub of function name" on this line:
Call mimeBody.SetContentFromText(stream, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)
0
 
LVL 22

Expert Comment

by:Bill-Hanson
Comment Utility
My bad.

I defined the MIME Entity with the variable 'body', but used 'mimeBody' later on.  Just change 'mimeBody' to 'body'.

This brings up an important point.  I recommend this to everyone, and require it of my own developers...  Always include 'Option Declare' in your Options module.  This helps prevent many errors.  If you had this option enabled, the compiler would have told you right away that mimeBody was not defined.
0
 
LVL 22

Expert Comment

by:Bill-Hanson
Comment Utility
So, how's this working out for you?
0
 

Author Comment

by:KTTKTT
Comment Utility
I'm trying to implement the code above with a LotusScript mail forward so when user clicks email button, a memo is composed with the To, Subject , body already filled in, and the user just forwards that mail to others.  I've done this before with simple actions and formula, so struggling a bit to pull it together in lotusScript.  The button will have a hyperlink as you've coded above in the body of the note for a url.  
0
 
LVL 22

Expert Comment

by:Bill-Hanson
Comment Utility
I understand.  Making the jump to a new language can be confusing.

So, here are a couple of presents for you...

First, a simple function that will compose an HTML memo and display it to the user for sending.  The only problem with this function is that it does not pull in the user's signature.  If that is not a problem, then this is the function that you should use.
Public Function ComposeMimeMemo(Byval subject As String, Byval html As String) As NotesUIDocument

	

	Dim sess As New NotesSession

	Dim db As New NotesDatabase("", "")

	Dim doc As NotesDocument

	Dim body As NotesMimeEntity

	Dim stream As NotesStream

	

	' create the MIME memo

	Call db.OpenMail

	sess.ConvertMime = False

	Set doc = db.CreateDocument

	doc.Subject = subject

	Set body = doc.CreateMIMEEntity("Body")

	Set stream = sess.CreateStream

	Call stream.WriteText(html)

	Call body.SetContentFromText(stream, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)

	Call doc.CloseMIMEEntities(True, "Body")

	sess.ConvertMime = True

	

	' open the new memo

	Dim ws As New NotesUIWorkspace

	Call ws.EditDocument(True, doc)

	

End Function

Open in new window

0
 
LVL 22

Accepted Solution

by:
Bill-Hanson earned 500 total points
Comment Utility
Next, a more complicated function that includes the user's signature, but uses the clipboard in order to do so.  This means that if the user had something on the clipboard, this function will erase it.  So, if you need the signature and don't care about the clipboard, this function is for you.
Public Function ComposeMimeMemoEx(Byval subject As String, Byval html As String) As NotesUIDocument

	

	On Error Goto CATCH

	Dim ws As New NotesUIWorkspace

	Dim sess As New NotesSession

	Dim db As New NotesDatabase("", "")

	Dim uiTemp As NotesUIDocument, memo As NotesUiDocument

	Dim docTemp As NotesDocument

	Dim body As NotesMimeEntity

	Dim stream As NotesStream

	

	' create MIME using a temp document

	Call db.OpenMail

	sess.ConvertMime = False

	Set docTemp = db.CreateDocument

	Set body = docTemp.CreateMIMEEntity("Body")

	Set stream = sess.CreateStream

	Call stream.WriteText(html)

	Call body.SetContentFromText(stream, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)

	Call docTemp.CloseMIMEEntities(True, "Body")

	sess.ConvertMime = True

	Call docTemp.Save(True, False)

	

	' copy generated HTML to the clipboard

	Set uiTemp = ws.EditDocument(True, docTemp)

	Call uiTemp.GotoField("Body")

	Call uiTemp.SelectAll

	Call uiTemp.Copy

	uiTemp.Document.SaveOptions = "0"

	uiTemp.Document.MailOptions = "0"

	Call uiTemp.Close

	Call docTemp.Remove(True)

	Set docTemp = Nothing

	

	' compose the new memo

	Set memo = ws.ComposeDocument(db.Server, db.Filepath, "Memo")

	Call memo.FieldSetText("Subject", subject)

	Call memo.GotoField("Body")

	Call memo.Paste

	Set ComposeMimeMemoEx = memo

	Exit Function

	

CATCH:

	If (Not docTemp Is Nothing) Then If (Not docTemp.IsNewNote) Then Call docTemp.Remove(True)

	Exit Function

	

End Function

Open in new window

0
 
LVL 22

Assisted Solution

by:Bill-Hanson
Bill-Hanson earned 500 total points
Comment Utility
Using the 2 functions above...

Both functions return a NotesUIDocument so that you can further manipulate the form before giving control to the user (like adding addresses to the "To" field).

Here is a simple agent that you can use to test the functions above.
Sub Initialize

	

	Dim memo As NotesUIDocument

	Set memo = ComposeMimeMemo("test", "This is a <b>test</b>!<br><a href = 'http://www.google.com'>Google</a>")

	Call memo.FieldSetText("EnterSendTo", "user@domain.com")

	

End Sub

Open in new window

0
 

Author Comment

by:KTTKTT
Comment Utility
AWESOME ! you're the best ! works great ! thank you so much for your generosity ! I will study the code !

I placed the above in the email button:

Sub Click(Source As Button)
      Dim memo As NotesUIDocument
      Set memo = ComposeMimeMemoEx("test", "This is a <b>test</b>!<br><a href = 'http://www.google.com'>Google</a>")
      Call memo.FieldSetText("EnterSendTo", "kimthom@us.ibm.com")
End Sub
0
 

Author Comment

by:KTTKTT
Comment Utility
oh forgot to mention that I received the error msg.:  "ComposeMimeMemoEx: Public not allowed in this module"  -
I removed "Public" from Public Function ComposeMimeMemoEx(Byval subject As String, Byval html As String) As NotesUIDocument"

Not sure what the difference is:  Public Function vs. Function  - will look it up
0
 
LVL 22

Expert Comment

by:Bill-Hanson
Comment Utility
Public / Private

These are called 'access specifiers' and are used to define where a function may be used.

Public - The function may be called from any context (action, agent, etc).

Private - The function may be called only by other functions in the current module.

For example, assume we have a LotusScript library named "Common Functions".  In that library are several functions that we want to use in several places (like ComposeMimeMemoEx).  Also in that library are a few "helper functions" that are used only by other functions inside the "Common Functions" library.  Assume that these "helper functions" would fail if they were called directly from an action or agent (maybe the "helper function" relies on a temp doc that is first created by one of the main functions in the library).  You could just remember to never use these "helper functions" outside the library, but there's a better way.  By including the Private keyword, you make the "helper function" invisible to modules outside the library, thus preventing accidental use.

Now that we know this, the error that you mentioned above makes sense.  Code that is stored inside of a form cannot be called from outside of the form, so the Public keyword is not valid.  The code could never be Public.

BTW: You really should place these functions inside of a shared library.  That way, you can reuse them in all of your apps.  Let me know if you want help setting one up.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:KTTKTT
Comment Utility
Hi Bill,

that would be great. thx.  The emal text for the Set memo = ComposeMimeMemoEx works great until I add a lot of text - get error msg. "Wrong number of arguments for ComposeMimeMemoEx"  I tried placing quotes around each line and adding the continuation line (&_), but that didn't work.  Let me know if this needs to be a separate question, because I also need to add an image to the memo.  The script is in a notes email button for now.
0
 

Author Comment

by:KTTKTT
Comment Utility
I was able to get the long text to work - removed spaces after &_ each continuation line
0
 

Author Comment

by:KTTKTT
Comment Utility
Bill,

Do you know if there is a reason why this won't work on a Notes 7 client.  I have Notes 8 and it works great on Notes 8 client.  A user still on Notes 7 gets error msg. "Object Variable not set" at this line:
Call memo.FieldSetText("EnterSendTo", "user notes id here")

thanks
0
 
LVL 22

Expert Comment

by:Bill-Hanson
Comment Utility
There's no reason that I can think of.  The client version should not matter.  I'm using R7 myself, and that is what I tested this script on.

The only object variable on that line is "memo".  Take a look at your code to make sure that you have not changed the variable name to something else.  Make sure that your ComposeMimeMemoEx function is returning the NotesUIDocument that was created by the function and assigning it to the correct variable.

Also, if you still need to add images, let me know.  I have examples, but have not had time to respond until now.
0
 

Author Comment

by:KTTKTT
Comment Utility
I didn't change your code above, but...added this additional email confirmation note code that works on notes 8 but gives object variable not set on notes 7 :

'1st email note automatically sent to inform you that a user clicked this button
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set doc = New NotesDocument( db )
      doc.Form = "Memo"
      doc.SendTo = "xxx.......com"    'CHANGE SEND TO HERE
      doc.Subject = "confirmation note"   'CHANGE SUBJECT LINE HERE
      doc.body = "I clicked on this button - will attend event' "   'CHANGE BODY TEXT HERE
      Call doc.Send( False )
      'end of 1st email note

------------
Also, I'm using an email button that will be forwarded via Notes email to others to click button to compose memo - I placed all code in the Click object - now I'm moving this line to Initialize to see what happens w/Notes 7:  
Dim memo As NotesUIDocument
0
 
LVL 22

Expert Comment

by:Bill-Hanson
Comment Utility
I'm a little confused.  I don't see any reference to memo in the code above.  Is this a different error?

Also, not sure why you're declaring memo in Initialize.
0
 

Author Comment

by:KTTKTT
Comment Utility
I got the image to work using this, but since i have so much text i probably should be using better html and the paragraph tag <p>:

"<br><br><font size=4><b>Lets build a smarter planet.</font></b>" &_
      "<br><br><font size=4><b><a href ='http://www.google.com'>Click here for information.</a>"&_
      "<br><br><img src='http://www.xyz.com/images/pic05075.jpg'/>"&_
0
 
LVL 22

Expert Comment

by:Bill-Hanson
Comment Utility
Now I'm really confused.  Please post all of your code and use the "Attach Code Snippet" so that it will not be interpreted as HTML.
0
 

Author Comment

by:KTTKTT
Comment Utility
my apologies. Here is code.  thanks
Sub Click(Source As Button)

	

	'1st email note automatically sent to inform you that a user clicked this button

	Dim session As New NotesSession

	Dim db As NotesDatabase

	Dim doc As NotesDocument

	Set db = session.CurrentDatabase

	Set doc = New NotesDocument( db )

	doc.Form = "Memo"

	doc.SendTo = "xxx.xxx.com"    'CHANGE SEND TO HERE

	doc.Subject = "confirmation note - I will attend this function"  'CHANGE SUBJECT LINE HERE

	doc.body = "I clicked on this button and plan to attend....' "   'CHANGE BODY TEXT HERE

	Call doc.Send( False )

	'end of 1st email note

	

	'-----------------------------------

	

	'2nd Email note - Allow user to Compose Memo 

	Dim memo As NotesUIDocument

	

	' the first line BEFORE THE COMMA, is the Subject text .  Body text follows> Be sure there are no spaces after each continuation line of text: &_.   

'Also notice that the url and image links are in 'single' quotes

	' Each line of text/html should be enclosed in double quotes

	' Do not remove the apostrophe ) from the last line of text which closes the entire text string

	

	Set memo = ComposeMimeMemoEx("subject text here", _

	"<font size=6><b>This is my body text"&_

	"</font></b><br><br>More Body Text" &_

	"New text, new text.....:<br><br><font size=4><b>Bold text, font 4 here.</font></b>and more text " &_

	"<br><br><font size=4><b><a href ='http://www.google.com'>Click here for more information.</a>"&_

	"<br><br><img src='http://www.xxx.com/images/pic050555.jpg'/>"&_

	"<br><br><font size = 1>This information ...All rights reserved.)"   )

	

	Call memo.FieldSetText("EnterSendTo", "ktt@xxx.com")	  'Add intranet id in the quotes for the SendTo field 	

End Sub
 
 
 

Function ComposeMimeMemoEx(Byval subject As String, Byval html As String) As NotesUIDocument

	

	Dim ws As New NotesUIWorkspace

	Dim sess As New NotesSession

	Dim db As New NotesDatabase("", "")

	Dim uiTemp As NotesUIDocument, memo As NotesUiDocument

	Dim docTemp As NotesDocument

	Dim body As NotesMimeEntity

	Dim stream As NotesStream

	On Error Goto CATCH

	

        ' create MIME using a temp document

	Call db.OpenMail

	sess.ConvertMime = False

	Set docTemp = db.CreateDocument

	Set body = docTemp.CreateMIMEEntity("Body")

	Set stream = sess.CreateStream

	Call stream.WriteText(html)

	Call body.SetContentFromText(stream, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)

	Call docTemp.CloseMIMEEntities(True, "Body")

	sess.ConvertMime = True

	Call docTemp.Save(True, False)

	

        ' copy generated HTML to the clipboard

	Set uiTemp = ws.EditDocument(True, docTemp)

	Call uiTemp.GotoField("Body")

	Call uiTemp.SelectAll

	Call uiTemp.Copy

	uiTemp.Document.SaveOptions = "0"

	uiTemp.Document.MailOptions = "0"

	Call uiTemp.Close

	Call docTemp.Remove(True)

	Set docTemp = Nothing

	

        ' compose the new memo

	Set memo = ws.ComposeDocument(db.Server, db.Filepath, "Memo")

	Call memo.FieldSetText("Subject", subject)

	Call memo.GotoField("Body")

	Call memo.Paste

	

	Set ComposeMimeMemoEx = memo

	

	Exit Function

	

CATCH:

	If (Not docTemp Is Nothing) Then If (Not docTemp.IsNewNote) Then Call docTemp.Remove(True)

	Exit Function

	

End Function

Open in new window

0
 
LVL 22

Expert Comment

by:Bill-Hanson
Comment Utility
Thanks.

I don't see anything wrong with the LotusScript here.  I do see a few HTML errors, but that should not cause an object variable error.

I recommend that you store the HTML in a separate variable for clarity, and use the pipe (|) char instead of double-quotes to surround the string.  This does a couple of things for you:  1) you don't need the line continuation operators to span multiple lines, 2) you can include quotes in the HTML, 3) it's easier to read.

Here's a short example with the HTML errors fixed for you :)
        Dim html as String
 

        html = |<font size=6><b>This is my body text</b></font><br><br>

More Body Text New text, new text.....:<br><br>

<font size=4><b>Bold text, font 4 here.</b></font> and more text<br><br>

<font size=4><b><a href ='http://www.google.com'>Click here for more information.</a></b></font><br><br>

<img src='http://www.xxx.com/images/pic050555.jpg'/><br><br>

<font size = 1>This information ...All rights reserved.</font>|
 

        Set memo = ComposeMimeMemoEx(html)

Open in new window

0
 

Author Comment

by:KTTKTT
Comment Utility
thanks Bill.

Receiving following error for:  Set memo = ComposeMimeMemoEx ( html )
"missing argument for: COMPOSEMIMEMEMOEX"




Dim memo As NotesUIDocument

	

Dim html As String
 

html = | <font size = 6><B>This is my body text</b></font><br><br>

More Body text...:<br><br>

<font size = 4><b>Bold text here, font size 4

</b></font> and more text <br><br> <font size = 4><b><a href = 'http:/www.google.com'>Click here for information.</a></b></font><br>

<img src = 'http://www.xxx.com/images/pic05555.jpg' /><br><br>

<font size = 1>This information...all rightrs reserved.</font>  |

	

Set memo = ComposeMimeMemoEx( html )

	

Call memo.FieldSetText("EnterSendTo", "")

Open in new window

0
 
LVL 22

Expert Comment

by:Bill-Hanson
Comment Utility
Sorry, I missed the subject param...
Dim memo As NotesUIDocument

        

Dim html As String

 

html = | <font size = 6><B>This is my body text</b></font><br><br>

More Body text...:<br><br>

<font size = 4><b>Bold text here, font size 4

</b></font> and more text <br><br> <font size = 4><b><a href = 'http:/www.google.com'>Click here for information.</a></b></font><br>

<img src = 'http://www.xxx.com/images/pic05555.jpg' /><br><br>

<font size = 1>This information...all rightrs reserved.</font>  |

        

Set memo = ComposeMimeMemoEx( "subject text here", html )

        

Call memo.FieldSetText("EnterSendTo", "user@domain.com")

Open in new window

0
 

Author Comment

by:KTTKTT
Comment Utility
Thanks again Bill.  Working great for Notes 8 clients.  I know that you mentioned it works for you on Notes 7.

I'm investigating reason for Notes 7 Object Variable not set - not sure if it's workstation configuration/settings or not.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now