@Functions with Lotusscript + More

Hi,

I have been working on lotus notes databases for a few months now and am getting on well with @functions. However i have come to a point where i require lotusscript and need some help.

I have created a page, where a click of a button will launch a form, prompt for information and then autofill certain fields.

The idea behind this is so that the original form can remain the same without changes in the code.

The code for the page is below:

FIELD ShortDescription := ShortDescription;

@Command([Compose]; “Requirement3”);

@UpdateFormulaContext;

@SetField(“ShortDescription”; “Access to Machine Room”);

FIELD MacAccessName := MacAccessName;

FIELD MacAccessRoom := MacAccessRoom;

FIELD MacAccessText := MacAccessText;

@SetField(“MacAccessName”;@Prompt([OkCancelEdit]; “Enter Name” ; “Please type the name of the person who requires machine room access:” ; “”));

@SetField(“MacAccessRoom”; @Prompt([OkCancelListMult]; “Select Required Access”; “Please select the machine rooms that " + MacAccessName + " requires access to:” ; “” ; “Black Room” : “Blue Room” : “Green Room” : “Inner Red Room” : “Outer Red Room” ));

@SetField(“MacAccessText”; @NewLine + MacAccessName + " requires access to the following machine rooms:"+ @NewLine + @NewLine + @Implode(MacAccessRoom ; @NewLine) + @NewLine +@NewLine )

The field ‘MacAccessText’ that i have specified needs to be set in a field called ‘Description’. Unfortunately this is a rich text field so @SetField will not work.

However i have found some lotusscript which i have tested and works a treat! Only problem is “How do i put the @functions and lotusscript together?”

My first thought was to write everything in lotusscript, but obviously that requires more knowledge than i have :slight_smile:

Below is the lotusscript that i need:

Sub Click(Source As Button)

Dim uiw As New notesuiworkspace

Dim uidoc As NotesUIDocument



Set uidoc = uiw.CurrentDocument

Call uidoc.FieldSetText("Description",MacAccessText)

'take fieldappendtext to append if other data exist in the rtffield

Call uidoc.Refresh(True)

End Sub

Oh, and i also tried running this code by calling an agent, but it would not work because the document wasn’t saved - which it can’t be at this point.

Any help would be appreciated,

Richard

Subject: @Functions with Lotusscript + More

Hi RichardThe easiest way would be to convert it all LS and believe me it’s nto difficult at all.

However, I would suggest that you use the background NotesDocument class rather than the NotesUIDocument class.

Writing the whole code wouldn’t be possible but here’s the idea:

  1. Get the user responses in variables in LS using the Prompt method of the NotesUIWorkspace class.

e.g.

dim x as variant

x = uiws.Prompt(…)

  1. Instantiate a back-end NotesDocument object and assign the form “Requirement3” to the form field and user responses to the other fields.

e.g.

set doc = new NotesDocument( db )

doc.Form = “Requirement3”

doc. = x

  1. Then display this document using the Edit method in the NotesUIWorkspace class.

LotusScript now also provides Join and Split functions which can be used in place of the @implode and @explode functions.

Hope this makes sense.

Regards

Arshad

Subject: @Functions with Lotusscript + More

Not saying it can’t be done…

But it’s probably easier just to re-write the rest of the formula in script.

@Prompt is the same as Prompt Method in LS, lots of examples in the help, for example:

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim askme As Variant

askme = ws.Prompt (PROMPT_OKCANCELEDIT, _

“We want to hear from you!”, _

“Enter your message here.”)

If Not Isempty (askme) Then

Messagebox "Sending your message...", , _

"Message status"

End If

End Sub

You already have the code to set the fields with FieldSetText.

Compose is like create document:

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set doc = db.CreateDocument

doc.Subject = “New building”

Call doc.Save( True, True )

Have a play around and post on here if there is something you can’t do in script, someone will almost certainly know the answer

Subject: RE: @Functions with Lotusscript + More

Hi, Thanks for your help.

So far i have written this…

Sub Click(Source As Button)

' Create Doc  Using "Requirement3" Form

Dim Session As New NotesSession

Dim Db As NotesDatabase

Dim Doc As NotesDocument



Set Db = Session.CurrentDatabase

Set Doc = New NotesDocument(Db)



Doc.Form = "Requirement3"







' Set Workspace and Variants

Dim ws As New NotesUIWorkspace

Dim MacAccessName As Variant

Dim MacAccessRoom As Variant

Dim MacAccessText As Variant

Dim RoomNames(4) As Variant

RoomNames(0) = "Black Room"

RoomNames(1) = "Blue Room"

RoomNames(2) = "Green Room"

RoomNames(3) = "Inner Red Room"

RoomNames(4) = "Outer Red Room"



'Set 'ShortDescription' Field

Dim uiw As New notesuiworkspace

Dim uidoc As NotesUIDocument



Call uidoc.FieldSetText("ShortDescription","Access To Machine Room")



' Prompt For Name

While MacAccessName = ""

	MacAccessName = ws.Prompt (PROMPT_OKCANCELEDIT, _

	"Enter Name", _

	"Please type the name of the person who requires machine room access:")

	If MacAccessName = "" Then

		Messagebox "You Must Enter A Name", , "ERROR"

	Else

		MacAccessName = MacAccessName

	End If

Wend





' Prompt For Machine Rooms

While MacAccessRoom = ""

	MacAccessRoom = ws.Prompt (PROMPT_OKCANCELLISTMULT, _

	"Select Required Access", _

	"Please select the machine rooms that " + MacAccessName + " requires access to:", _

	"", RoomNames)

	If MacAccessRoom = "" Then

		Messagebox "You Must Select A Machine Room", , "ERROR"

	Else

		MacAccessRoom = MacAccessRoom

	End If

Wend



'Set text the text for 'Description' Field

MacAccessText = MacAccessName  + " requires access to the following machine rooms:" + Join(MacAccessRoom)



'Set 'Description' Field

Set uidoc = uiw.CurrentDocument

Call uidoc.FieldSetText("Description",MacAccessText)

'take fieldappendtext to append if other data exist in the rtffield

Call uidoc.Refresh(True)

End Sub

I cannot get my form ‘Requirement3’ to launch??? The prompts however work fine :slight_smile:

Could someone posibly set me in the right direction. I have looked up examples of the CreateDocument method but cannot make complete sense of it.

I need training really, but your help in the mean time would be most appreciated.

Regards,

Richard