JavaScript for this Formula Language

I have this Formula Language which I need to write in JavaScript. Please help

  1. @If(

stringQuery =“1”; @ReplaceSubstring(@Trim(Query); " "; " AND ");

stringQuery =“2”; @ReplaceSubstring(@Trim(Query); " "; " OR ");

stringQuery)


  1. options:=@If(stringQuery=“1”; “”;

@If( SearchMaxResults=“0”; “”; “&SearchMax=” + SearchMaxResults )

+@If(SearchOrder=“0”; “”; “&SearchOrder=”+SearchOrder)

Subject: JavaScript for this Formula Language

  1. Here I would use .replace() in Javascript with a regexp to perform a global replace to do the same thing as @ReplaceSubString does.

In your case:

query.replace(/ /g," AND ");

  1. Just use regular string concatenation in in Javascript.

var options = “”

if(stringQuery!=“1”) {

if(searchMaxResults!=“0”) {

options=options + “&SearchMax=” + searchMaxResults;

}

if(searchOrder!=“0”) {

options=options + “&SearchOrder=” + searchOrder;

}

}

Something like that. My guess is that you are building a URL to call from within a web page. I would suggest that you use jQuery, and instead of building a long URL string with argument as name-value pair, you use $.ajax() to call the URL, with the argements in an object.

Below is a code snipped from a web application I am working on right now, doing exactly that. The code calls a Lotusscript agent on the server. The agent reads the argments passed to it and updates a Notes document, then pass back JSON sith success or failure info, error messages, etc.

$.ajax({

url: “/ajax_UpdateClient?OpenAgent”,

data: json,

cache: false

}).done(function(data) {

// add code here to parse response data

});

Subject: RE: JavaScript for this Formula Language

Thanks Karl. Nice guidance.