xpages ftsearch documents from an interval of dates - xpages

I made an xpage element for ftsearch using a tutorial from IBM
My request: is there possible having 2 date fields ( as input requirements for the search ) to find those documents having the creation date inside the interval consisting of those 2 dates?
Should I create a computed field dtCreated where I will store the creation date and then in the search property of the view I should add something like this:
var tmpArray = new Array("");
var cTerms = 0;
if (sessionScope.searchDate1) && (sessionScope.searchDate2) {
tmpArray[cTerms++] = "(Field dtCreated > \"" + sessionScope.searhcDate1 + "\")" && "(Field dtCreated < \"" + sessionScope.searhcDate2 + "\")";
}
....
....
Or there is another alternative?
My 2 session variables are having Short (5/5/14) Date format. Also, my default value for those 2 dates (session variables) are "" but of course I add some values before clicking the Submit button.
Thanks for your time!

You can use the special field _creationDate as creation date (see answer from Tommy). Based on this the following example query will work in the Notes client:
Field _creationDate > 01-01-2014 AND Field _creationDate < 01-03-2014
In order to get this query to work with your specific code do this:
var tmpArray = new Array("");
var cTerms = 0;
var dateFormatter = new java.text.SimpleDateFormat( "dd-MM-yyyy" );
if (sessionScope.searchDate1) && (sessionScope.searchDate2) {
tmpArray[cTerms++] = "Field _creationDate > " + dateFormatter.format(sessionScope.searchDate1) + " AND Field _creationDate < " + dateFormatter.format(sessionScope.searchDate2);
}

If you want to do an FTSearch, _CreationDate can be used
Documentation (scroll to Searching for Header Information):
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=%2Fcom.ibm.designer.domino.main.doc%2FH_CUSTOMIZING_SEARCH_FORMS_7304.html
E.g. (there might be typos):
tmpArray[cTerms++] = "(Field _creationDate>" + sessionScope.searhcDate1 + ") AND (Field _creationDate<" + sessionScope.searhcDate2 + ")";
Or my preferred syntax:
tmpArray[cTerms++] = "[_creationDate>" + sessionScope.searhcDate1 + "] AND [_creationDate<" + sessionScope.searhcDate2 + "]";

To build on Tommy's answer:
Specifically, try "yyyy/m/d" as the format. If those values in sessionScope are java.util.Date (the type that date fields use), you could try something like this (typing off the top of my head, not in an app, so my apologies for typos):
var tmpArray = [];
var cTerms = 0;
if(sessionScope.searchDate1 && sessionScope.searchDate2) {
var formatter = new java.text.SimpleDateFormat("yyyy/M/d");
tmpArray[cTerms++] = "[_CreationDate] >= " + formatter.format(sessionScope.searchDate1) + " and [_CreaationDate] <= " + formatter.format(sessionScope.searchDate2)
}
What you want to end up with is a FT query like:
[_CreationDate] >= 2014/1/1 and [_CreationDate] <= 2014/2/1

Related

How can I match exact text in a particular column and output the entire row of information?

I have been attempting to create a Telegram bot that searches a preexisting database and outputs information based on search query, essentially I want the bot to just receive a text via Telegram that contains an invoice number and output all relevant information regarding that order (The entire row of information).
Since I am dealing with invoice numbers and tracking numbers, sometimes the bot is exporting incorrect information given the current script is not matching exact text or a specific column.
For instance, rather than searching and finding invoice number it picks up a partial match of tracking number and outputs the wrong information.
I would like to set it up to search a specific column, ie. Column 3 - "Invoice #" and then output the entire row of information.
Thanks in advance!
I have been working in Google App Script:
var token = "";
var telegramUrl = "https://api.telegram.org/bot" + token;
var webAppUrl = "";
var ssId = "";
function getMe() {
var url = telegramUrl + "/getMe";
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function setWebhook() {
var url = telegramUrl + "/setWebhook?url=" + webAppUrl;
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function sendText(id,text) {
var url = telegramUrl + "/sendMessage?chat_id=" + id + "&text=" + text;
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function doGet(e) {
return HtmlService.createHtmlOutput("Hi there");
}
function doPost(e) {
var data = JSON.parse(e.postData.contents);
var text = data.message.text;
var id = data.message.chat.id;
var name = data.message.chat.first_name + " " + data.message.chat.last_name;
var answer = "Hi " + name + ", please enter invoice number.";
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Orders");
var search_string = text
var textFinder = sheet.createTextFinder(search_string)
var search_row = textFinder.findNext().getRow();
var value = SpreadsheetApp.getActiveSheet().getRange("F"+search_row).getValues();
var value_a = SpreadsheetApp.getActiveSheet().getRange("G"+search_row).getValues();
sendText(id,value+" "+ value_a)
}
You want to find rows where the content in column 3 is exactly equal to your variable "text"
Modify your function doPost as following:
function doPost(e) {
var data = JSON.parse(e.postData.contents);
var text = data.message.text;
var id = data.message.chat.id;
var name = data.message.chat.first_name + " " + data.message.chat.last_name;
var answer = "Hi " + name + ", please enter invoice number.";
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Orders");
var range = sheet.getRange(1,1, sheet.getLastRow(), sheet.getLastColumn());
var values = range.getValues();
for (var i=0; i< values.length; i++){
var column3Value = values[i][2];
if(column3Value == text){
var rowValues = values[i].toString();
sendText(id,rowValues)
}
}
}
Explanations
The for loop iterates through all rows and compares the values in column 3 (array element[2] against the value of text
The operator == makes sure that only exact matches are found (indexOf() would also retrieve partial matches)
In case a match is found, the values from the whole row are converted to a comma separated string with toString() (You can procced the values differntly if desired)
Every row with a match will be sent to the function sendText() (you could alternatively push all rows with matches into an array / string and call sendText() only once, after exiting the for loop
I hope this answer helps you to solve your problem and adapt the provided code snippet to your needs!
I would look for a specific column where the order number is stored.
I`m not sure if it is the best way from performance side, but I think it should work.
function orderInformation(orderNumber){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Orders");
//Gets last row in Orders sheet
var lastRow = sheet.getLastRow();
//Here you can change column where is order number stored
var orderNumberRange = sheet.getRange("A1:A" + lastRow);
//Gets all order number values
var orderNumbers = orderNumberRange.getValues();
//You can use indexOf to find which row has information about requested order
var orderLocation = orderNumbers.indexOf(orderNumber);
//Now get row with order data, lets suppose that your order information is from column A to Z
var orderData = sheet.getRange("A" + (orderLocation + 1) + ":Z" + (orderLocation + 1)).getValues();
//Now you have all data in array, where you can loop through and generate response text for a customer.
}
Sorry, I have not tested it, at the moment I don`t have time to make a test sheet, but this is the way I would do it and I think it should work.
I will test it maybe later when I will be able to make a test sheet.

How do I access table elements in cheerio?

I have a Table let's say. The elements have no classes, ids or anything except a value. They only have applied style but inside the element. The rest are TD and TR's. Now in Python and BeautifulSoup4 I can do this:
status = soup.select('._lMf')
table = soup.select('.g table td')
departure = table[8].getText()
deptime = table[4].getText() + " " + table[5].getText()
terminal = table[6].getText() + " "+ table[11].getText()
arrival = table[19].getText()
arrtime = table[15].getText() + " " + table[16].getText()
arrterminal = table[17].getText() + " " + table[22].getText()
info = table[1].getText()
Select the table and the elements i'm looking for which is a TD and access them. Now I tried almost the same techniques in Cheerio but didn't do it. I got like:
TypeError: table[5].text is not a function and Objects.
It successfully logged the easiest 2 that can be directly accessed but it fails on table elements.
This is how i do it in Cheerio:
var table = $('.g table td')
var deptime = table[5]
var city = table[8].text()
var terminal = table[6].text()
Help!
Use
var table = $('.g table td')
var deptime = table.eq(5).text()
var city = table.eq(8).text()
var terminal = table.eq(6).text()

Trying to use a xpages dynamic view panel with search on fields value

I have created an xPages custom control based on Dynamic View Panel. I then added 2 comboboxes filled with various values (States, Departments) and an editbox field and a Search button. I then coded the follow to return the search string onto a computed "Search in view results" for the panel.
var tmpArray = new Array("");
var cTerms = 0;
if(viewScope.categoryText1 != null) {
if ( viewScope.categoryText1.trim() != "") {
tmpArray[cTerms++] = "(FIELD State CONTAINS \"" + viewScope.categoryText1 + "\")";
}
}
if(viewScope.categoryText2 != null ){
if ( viewScope.categoryText2.trim() != "") {
tmpArray[cTerms++] = "(FIELD Department = \"" + viewScope.categoryText2 + "\")";
}
}
if(viewScope.searchString != null ) {
if ( viewScope.searchString != "") {
tmpArray[cTerms++] = "( \"" + viewScope.searchString + "\")";
}
}
qstring = tmpArray.join(" AND ").trim();
viewScope.queryString = qstring; // this just displays the query
return qstring // this is what sets the search property
The search works for the editbox field values but not for the strings generated by the comboboxes: 'FIELD State CONTAINS "some state"' or 'FIELD Department = "some deptname"'. These search strings return an empty view.
The Column names match the underlying Notesview (both programmatically and column title).
I think this might have something to do with what are the column names surfaced by the Dynamic View Panel but I'm not sure.
Full text search looks in document fields for search strings, not in column values.
So, make sure fields State and Department contain the strings you are looking for.
Do you use aliases? Maybe you save abbreviation for State in document only but user can select State's full name for search...

Get Latitude and Longitude [Google Api and Yahoo Api]

I am working in c#.Net. My requirement is to get the latitude and longitude from the api, based on the address,city,state and zip which had given as a parameter.
I am having 350 stores details in a excel sheet. Initially i had used google api.
if (strAdd != "" && strCity != "" && strState != "" && strZip != "" && strStoreNo != "")
{
Address = strAdd.Trim() + "," + strCity.Trim() + "," + strState.Trim() + "," + strZip.Trim();
string routeReqUrl = "http://maps.google.com/maps/geo?q={0}&output=xml&oe=utf8&sensor=true_or_false&key={1}";
string url = string.Format(routeReqUrl, Address.Replace(' ', '+'), "ABQIAAAA5rV-auhZekuhPKBTkuTC3hSAmVUytQSqQDODadyYeWY4ZYaVyRRv4thyrzzOQ7AMUl_hIjoG8LomGA");
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "GET";
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream respStream = resp.GetResponseStream();
XmlDocument xDoc = new XmlDocument();
xDoc.Load(respStream);
if (xDoc.GetElementsByTagName("coordinates")[0].InnerText.Contains(","))
{
string[] coordinates = xDoc.GetElementsByTagName("coordinates")[0].InnerText.Split(',');
string Latitude = coordinates[1];
string Longtitude = coordinates[0];
Logger.Log.Debug("[Latitude and Longitude] " + " Store - No " + strStoreNo + " Addr Line 1 " + strAdd + " Latitude " + Latitude + " Longitude " + Longtitude);
}
}
In the above code, only around for 10 to 15 stores i can able to get the latitude and longitude details. After that i am getting the object reference error in "(xDoc.GetElementsByTagName("coordinates")[0].......".
After that i had tried with yahoo api, i am using the same excel sheet which had 350 stores.
dsxml.ReadXml("http://where.yahooapis.com/geocode?appid=capelinks&location=" + Address + "&Geocode=Geocode");
if (dsxml.Tables[0].Rows.Count > 0)
{
if (dsxml.Tables[1].TableName == "Result")
{
string Latitude = dsxml.Tables[1].Rows[0]["Latitude"].ToString();
string Longtitude = dsxml.Tables[1].Rows[0]["Longitude"].ToString();
Logger.Log.Debug("[Latitude and Longitude] " + " Store - No " + strStoreNo + " Addr Line 1 " + strAdd + " Latitude " + Latitude + " Longitude " + Longtitude);
}
}
Here, its process all the 350 stores correctly without any error.
What will be the issue with google api. whether there are any restrictions for taking the latitude and longitude details for large number of stores.
I'm not sure if this is your example problem, but the Google Geocoding API V2 docs mention that the V2 version is deprecated now:
Note: The Google Maps Geocoding API Version 2 has been officially deprecated as of March 8, 2010. The V2 API will continue to work until Mar 8, 2013. We encourage you to migrate your code to the new Geocoding API.
You could try switching to the latest Geocoding API V3. One thing to keep in mind is Google terms mention only allowing this service when you are displaying results in the context of a Google Map.
If the Yahoo service is providing the data you need, I would stick with it.

search view with the exact value

I have a view in which I search for products. I'm for example looking for product 1234.
The problem is their also exist products called 1234A and 1234 C etc. When I look with the code mentioned below I get all the items from product 1234 but also from 1234A and 1234 C etc.
It has to be limited to items from product 1234 only
Search code (under Data / Search in view results):
var tmpArray = new Array("");
var cTerms = 0;
if (sessionScope.SelectedProduct != null & sessionScope.SelectedProduct != "") {
tmpArray[cTerms++] = "(FIELD spareProduct = \"" + sessionScope.SelectedProduct +
"\")";
}
if (sessionScope.Development != null & sessionScope.Development != "") {
tmpArray[cTerms++] = "(FIELD spareStatus = \"*" + sessionScope.Development +
"*\")";
}
qstring = tmpArray.join(" AND ").trim();
return qstring
I used the suggestion from Frantisek :
I made a view with a combined column . (combined with the different "keys" I search for)
Then instead of using data / search , I used data/keys with exact keymatch. In this key I combined the searched items.
Since I had a field in wich I had sometimes at the end a character "°" , and it seems that this character doesn't work with a lookup , I took it out of my view and searched item with #Word(FIELDNAME; "°" ; 1).
As Frantisek suggested I could have used #ReplaceSubstring( field; "°"; "" ) also.

Resources