Tuesday, November 16, 2010

JS staff: Use Object instead of Switch.

Links to this post
Well, many of us use switch to solve own tasks, but there is another way I would like to show. We can use Object approach to solve our problem and it looks more intelligent from my point of view.

Let me show couple examples

1. Example with switch
function FoodType(food) {
var getfoodtype;

switch(food) {
case 'apple': getfoodtype = 'fruit'; break;
case 'cucumbers': getfoodtype = 'vegetable'; break;
case 'watermelon': getfoodtype = 'strawberry'; break;
default: getfoodtype = 'not recognized';

return getfoodtype;


var getfoodtype, case, and break, we can avoid them.

2. Example with Object
FoodType {
apple: fruit,
cucumbers: vegetable,
watermelon: strawberry,

GetFoodType: function(type) {

return(this[type] || 'not recognized');


Ofc there could be cases where Object approach does not work and we have to use switch, but it is alternative, so keep in mind this.

Friday, November 12, 2010

Dynamical counter in Lotus Notes client

Have you ever tried to show length of field (f.x. just below the field) ?

Let me show my example, I've a form, there I have couple fields I need to show length of it (because there is some validation of length for this field).

So when user input new char in Title field, Character count should increase to 1. Know how to do that? I believe many of you know, but anywhere I would like to share this approach.

There are actually 2 fields: 1 for input and another one is just below the Title of field (computed type).

What we need to do - use some simple JavaScript lines..

step 1.
go to JS Header even in form/subform and put there couple lines of JS (select Run: Client and JavaScript)

 var f = document.forms[0];  
 var stopDynamicalCounter = 0;  
 function updateCharCounter(delay) {  
   if(stopDynamicalCounter == 0) return;  
   f.AlternateTitle_length.value = f.AlternateTitle.value.length;  
   setTimeout( 'updateCharCounter( ' + delay + ' )', delay);  

step 2.
select input-field, and go to onFocus event, select Run: Client and JavaScript and put there 2 lines
 stopDynamicalCounter = 1;  

step 3.
select input-field, and go to onBlur event, select Run: Client and JavaScript and put there 1 line

 stopDynamicalCounter = 0;  

That's all.

Computewithform does not work properly at 8.5.2

Many people + me as well faced up with strange issue after migrated to 8.5.2.
Computewithform just stopped to work (but when you use debugger and look into document before computewithform it works fine).
Here is my solution to avoid this problem
Set doc=view.GetDocumentByKey(key, True)
Dim bug as String
bug=doc.UniversalID '(or any item) '// that is actually the main line, funny?
Call doc.ComputeWithForm(False, False)

Tuesday, November 09, 2010

Very nice SOAP client (java)

Links to this post
Here is link to nice java soap client
I've implement also LS2J approach

here is my example. There are some enhancements need to do, but anywhere this also works fine.

Java library

import java.io.*;
import java.net.*;

public class ECWebservice {
String cResponse;
String wsurl;
String msg;
String contentType;

public ECWebservice(String init_url) throws IOException {
wsurl = init_url;
msg = "";
contentType = "text/xml; charset=utf-8";
cResponse = "";

public String GetResponce() {
return cResponse;

public void SetContentType(String init_contenttype) {
contentType = init_contenttype;

public boolean Send(String init_msg) {
boolean result = true;
try {
msg = init_msg;

// Create the connection where we're going to send the file.
URL url = new URL(wsurl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;

String SOAPAction = msg;

byte[] b = SOAPAction.getBytes();

// Set the appropriate HTTP parameters.
httpConn.setRequestProperty( "Content-Length", String.valueOf(SOAPAction.length()));
httpConn.setRequestProperty("Content-Type", contentType);
httpConn.setRequestProperty("SOAPAction", SOAPAction);

// Everything's set up; send the XML that was read in to b.
OutputStream out = httpConn.getOutputStream();

// Read the response and write it to standard out.
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream(), "utf-8");
BufferedReader in = new BufferedReader(isr);

String inputLine;
while ((inputLine = in.readLine()) != null) {
cResponse += inputLine;
} catch(Exception e) {
cResponse = "Main: Exception occured - check Java Debug Console";
result = false;

return result;

LS2J library

Option Public
Option Declare

Use "webservice.core"
UseLSX "*javacon"
Class ECWebservice
responce As string
connection As string
contentType As string

Sub New(connection_url As string)
connection = connection_url
contentType = "text/xml; charset=utf-8"
End Sub

Public Property Get GetResponce As string
GetResponce = responce
End Property

public Property Set SetConnection
connection = SetConnection
End Property

Public Property Set SetContentType
contentType = SetContentType
End Property

Function SendXMLRequest(xmldata) As Boolean
On Error Goto errorproc

'** everything we'll need to access our Java classes
Dim jSession As New JavaSession
Dim jClass As JavaClass
Dim jObject As JavaObject

'** get the IGWebservice class and instantiate an instance of it
Set jClass = jSession.GetClass("ECWebservice")

'** version of CreateObject and init with path to WSDL)
Set jObject = jClass.CreateObject("(Ljava/lang/String;)V", connection)
'** send message and get result: true/false, if true then we got result
If jObject.send(xmldata) Then
me.responce = jObject.GetResponce()
End If

SendXMLRequest = True

Exit Function
MsgBox "Error #" & Err & " on line " & Erl & " in function " & Lsi_info(2) & " : " & Error, 48, "Runtime error"
Resume endofsub
End Function

End Class