Manage Learn to apply best practices and optimize your operations.

Paste templated text into Lotus Designer

To save the trouble of typing code many times, this tip will allow you to paste templated text into your designer, all by using the Tools Menu Bar.

View member feedback to this tip.

NOTE -- After receiving feedback from several members of the SearchDomino community suggesting that a piece of code was missing from the tip below, the author of the tip sent us an update, which appears as the third item in the Member Feedback section of the tip. The author was using a compiled program called from this code and forgot to update the document. The author apologizes for any inconvenience this may have caused. (Posted June 6, 2005)

As a coder I get sick of having to write the same code over and over and over again. Sure, I can make script libraries and copy and paste templated code, but all that window changing is a chore.

So, I thought, what if I could push a button and a templated piece of code would be automatically inserted anywhere into my designer, Lotus Script, Java Script, Formula, you name it?

This tip will allow you to paste templated text into your designer, all by using the Tools Menu Bar. This code could be extended to work on templates stored in a Lotus Notes DB or offer prompt choices, but I thought that a simple example is the best way to explain it.

Follow the example below to see how it works. The example shows a scenario in which I am working in the Designer and have just created a Script Library. The code below allows me to click on "Tools -- Sub Routine Insert", and the following templated Sub Routine will be added to the Script Library.

This has been tested with IE6 and works on Win98, @k and XP.

Sub MySub() 
' **********************************************
' Created By &ltPersonName> 
on &ltDate Created>
'
' &ltSub Description Here>
' 
' **********************************************
 gCurrentMethodName = "[MySub]"
 On Error Goto errHandle
 
 '&ltCode Starts Here>
 
 Exit Sub
' ********* Error Handling 
Code Here ******* 
errHandle: 
 Call LogError( Err, Error$)
 Exit Sub
End Sub

1. Use Notepad to create a text document called InsertSub.vbs

2. Paste the following code into InsertSub.vbs

' *********** Start Of Code *****
dim txtToPaste
txtToPaste =" Sub MySub() " & chr(13) & _ 
"' **********************************************" 
& chr(13) & _ 
"' Created By &ltPersonName> 
on &ltDate Created>" & chr(13) & _ 
"'" & chr(13) & _ 
"' &ltSub Description Here>" & chr(13) & _ 
"' " & chr(13) & _ 
"' **********************************************" 
& chr(13) & _ 
" gCurrentMethodName = 
""[MySub]""" & chr(13) & _ 
" On Error Goto errHandle" 
& chr(13) & _ 
"" & chr(13) & _  
" '&ltCode Starts Here>" & chr(13) & _ 
"" & chr(13) & _  
" Exit Sub" & chr(13) & _ 
"' ********* Error Handling Code Here ******* " 
& chr(13) & _ 
"errHandle: " & chr(13) & _ 
" Call LogError( Err, Error$)" & chr(13) & _ 
" Exit Sub" & chr(13) & _ 
"End Sub"  & chr(13) 

Set objIE = 
CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.document.parentwindow.
clipboardData.SetData "text", txtToPaste
objIE.document.parentwindow.
clipboardData.GetData "text"
objIE.Quit
' ******* End Of Code *******

3. Save the document. For my example it is saved as h:InsertSub.vbs.

4. Go to the Tools Menu in the Lotus Designer.

5. Select 'Tools -- Add Tool'.

6. In the Tool Name box type 'Sub Insert'.

7. Leave the Tool Action on 'Run Program' and type in the exact name of the file you saved in step 3.

8. Leave the Context as '... Always' for the mean time and Click 'OK'.

9. Create a blank Script Library. Make sure your cursor in at the place in the library that you want your new subroutine to appear.

10. Click on 'Tools - Sub Insert' (this is the new tool you just created).

11. Answer Yes to the prompt that appears.

12. Voila. Now make a few more short cuts to save you hours of typing.

13. If you go mad and make lots of tools shortcuts it might be worth changing the context (Step 8) to only show the tool where it is needed. The example code for instance might be best moved from '...always' to the section titled 'Script Library Design' so it only shows up there. To do this click on 'Tools - Customize Tools', select the tool you want to move and drag it to the section you want it in.

14. Last notes: Do not remove the prompt from the code. It stops the formula from pasting before the script has finished running. Until we get a sleep command in formula this will have to suffice. Also, double quote all speech marks in the 'TextToPaste' string. The pipe symbol doesn't work in this context.

MEMBER FEEDBACK TO THIS TIP

Is something missing in the code? I tried it and it is put into a clipboard, but it is never pasted in. I also noticed that the author is referrring to a prompt (in point #14 listed above) which I can't find.

—Thomas A.

******************************************

I have the same comment; as pasted, the code is incomplete and does not run.

—Joel P.

******************************************

It looks like I missed a change to my documentation for Step 7. Sorry. Originally I was using a compiled program called from this code and forgot to update my document for Step 7. Again my apologies. Step 7 should read:

@Command( [Execute]; 
"h:\\pasteNewSub.vbs");
@If( @Prompt([YesNo]; 
"Paste From Clipboard?"; 
"This will paste text in from the clipboard.") = 
@True; @Command([EditPaste] ); "")

This should solve the problem.

—Shane Hollis, tip submitter

******************************************

While this is an interesting tip, a much better method can be found here: www.alanlepofsky.com/alepofsky/alanblog.nsf/dx/paste-information-application This method lets you store your code or code template in a Notes document. You then choose which document you want to grab and paste into designer. It is infinitely more flexible.

—Dave L.

******************************************

Unfortunately this previous comment is incorrect. The link he mentions above does not work in the Lotus Notes Designer client for pasting text into the Lotus Script Designer and other areas. It works great for the Lotus Notes Client and especially for storing and pasting rich text. However, my tip was expressly created for developers trying to paste templated text into the designer.

—Shane Hollis, tip submitter

Do you have more comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Shane Hollis. Please let others know how useful it is via the rating scale at the end of the tip. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Dig Deeper on Lotus Notes Domino Formula Language

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close