Tuesday, August 28, 2007

Document values "changer"

I'm sure that every Lotus Notes developer during debugging has problems with changing values of fields. So I want to show a code which will help you (I hope) in this. Just try it !

(author is here http://www.sbacode.com/pageTips.aspx?id=208&)


REM {Get a listing of all the fields on the current document};
List := @DocFields;

REM {Possible data types to choose from.};
REM {I called Number Integer because use keyboard to select what you want with keyboard quicker.};
DataTypes := "Text" : "Date" : "Integer" : "Password" : "Name" : "Common Name" : "**** Remove Field ****" : "Text Multi Value" : "Date Multi Value" : "Integer Multi Value" : "Name Multi Value";

REM {Prompt for which field needs to be updated.};
EditField := @Prompt([OkCancelList]; "Select Field To Update"; "Select the field you wish to update:"; ""; List : "**** ADD A NEW FIELD ****");

REM {If adding a new field, prompt for the field name};
NewFieldName := @If(EditField = "**** ADD A NEW FIELD ****"; @Prompt([OkCancelEdit]; "Enter Field Name"; "Enter the name of the new field:"; ""); "");
CheckFieldName := @If(@IsMember(NewFieldName; List) & NewFieldName != ""; @Return(@Prompt([Ok]; "Already In List"; "The field " + NewFieldName + " already exists on the document.")); "");
UpdateVariable := @If(NewFieldName = ""; ""; EditField := NewFieldName);

REM {Prompt for which data type you would like the data to be};
REM {This needs to be done before value prompt to determine if the};
REM { Picklist or any prompting needs to be used.};
DataType := @Prompt([OkCancelList] : [NoSort]; "Choose Data Type"; "Please Select the correct data type or action for field: " + EditField; "Text"; DataTypes);

REM {For multi-valued fields, let the user choose the separator to use};
Separator := @If(@Contains(DataType; "Multi Value"); @Prompt([OkCancelList] : [NoSort]; "Choose Separator"; "Choose the separator to split out your multiple values"; ":"; (":" : ";" : "+" : "-" : "*")); "");

REM {Pull out the current value of the field};
CurrValue1 := @Eval(@Text(EditField));
CurrValue2 := @Abstract([TextOnly]; 254; ""; @Text(EditField));
CurrValue := @If(@IsNumber(CurrValue1) | @IsTime(CurrValue1); @Implode(@Text(CurrValue1); Separator); CurrValue2 != ""; CurrValue2; @Implode(@Text(CurrValue1); Separator));

REM {Based on what type of data is being entered different prompts will happen if any at all.};
RawValue := @If(
@Contains(DataType; "Name Multi Value"); @PickList([Name]);
@Contains(DataType; "Name"); @PickList([Name] : [Single]);
DataType = "**** Remove Field ****"; "";
@Contains(DataType; "Multi Value"); @Prompt([OkCancelEdit]; "New Value"; "Please enter the new desired value for: " + EditField + " seperated with " + Separator + " for each value."; CurrValue);
@Prompt([OkCancelEdit]; "New Value"; "Please enter the new desired value for: " + EditField + "."; CurrValue)
);

REM {If data conversion doesn't work then don't set field.};
@If(
DataType = "Date"; @If(@SetField(EditField; @TextToTime(RawValue)));
DataType = "Integer"; @If(@IsError(@TextToNumber(RawValue)); ""; @SetField(EditField; @TextToNumber(RawValue)));
DataType = "Password"; @SetField(EditField; @Password(RawValue));
DataType = "**** Remove Field ****"; @SetField(EditField; @DeleteField);
DataType = "Text Multi Value"; @SetField(EditField; @Explode(RawValue; Separator));
DataType = "Date Multi Value"; @SetField(EditField; @TextToTime(@Explode(RawValue; Separator)));
DataType = "Integer Multi Value"; @If(@IsError(@TextToNumber(@Explode(RawValue; Separator))); ""; @SetField(EditField; @TextToNumber(@Explode(RawValue; Separator))));
DataType = "Name Multi Value"; @SetField(EditField; @Explode(@Name([Canonicalize]; RawValue); Separator));
@SetField(EditField; RawValue)
);
""

Wednesday, August 22, 2007

CGI variables (Remote_Addr)

here are some examples of getting the CGI variables from a web-agent.

LotusScript
Sub Initialize
Dim session As NotesSession
Set session = New NotesSession
Dim doc As NotesDocument
Set doc = session.DocumentContext
Print "IP address =" + doc.Remote_Addr(0)
End Sub

Java
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Document doc = agentContext.getDocumentContext();
getAgentOutput().println("IP address = " + doc.getItemValueString("Remote_Addr"));
}
catch(Exception e) {
e.printStackTrace();
}
}
}

Thursday, August 09, 2007

office's "moved"

Our office "moved" to another place. now I ride to office usually near 20-30 minutes. Not bad. Really.

Tuesday, July 24, 2007

DesignNoInitialInfobox

All Lotus Notes developers know that when we open the design's document of view or agent, the properties dialog is opening too. But I dont like this feature, really, I hate it. Actually why in views and agents only? why not in forms too?
To disable this properties dialog you should add variable to notes.ini DesignNoInitialInfobox=1 . try it and you like it :)

Monday, July 16, 2007

Microsoft Excel Worksheet (Embedded Object)

Today I did a simple task, but I never do it before. So, I had a simple form with Microsoft Excel Worksheet (Embedded Object). My task was to extract this embedded object from notes's documents to disk in folder. I had 2 problems:
- how I can choose a folder on my own PC from Lotus Notes client?
- how I can extract object as MS Excek file and save it in chosen folder?

the first task I solved by using undocumented method of NotesUIWorkspace: Let folderTo = w.prompt(14, "", "")

second task I solved by using next code:

If doc.HasEmbedded Then
Forall o In doc.EmbeddedObjects
Set handle = o.Activate(True)
If Not handle Is Nothing Then
Set exWb = handle.Application.ActiveWorkBook

'
Let VNumber = doc.GetItemValue("VNumber")(0)
Let Agreement_1 = doc.GetItemValue("Agreement_1")(0)
Let fileName = VNumber & SEP & Agreement_1 & ".xls"
'


On Error Resume Next
Call exWb.SaveAs(folderTo & fileName)
Print {Operate with file '} & folderTo & fileName & {'}
On Error Goto ERR_THIS
End If
End Forall
End If