Repeat control error in xpage - xpages

JavaScript code
1: db=database;
2: theView=db.getView(compositeData.PDviewname);
Error while executing JavaScript computed expression
Script interpreter error, line=2, col=12: [TypeError] Exception occurred calling method NotesDatabase.getView(null) null

You don't catch null values. One possible way:
var viewName = compositeDate.PDViewName == null ? 'someDefaultName' | compositeDate.PDViewName;
var theView = database.getView(viewName);
Of course you could also stop the code if viewName is null. You shouldn't use sessionScope here -> your code will break if a user has the unheard idea of opening 2 browser tabs in your application.

Related

Getting a subset of string from multivalue field SSJS

In an XPage bound to a document I have a multivalue field containing email addresses. I simply wish to loop through the email addresses and return a subset of addresses which contain mydomain. To then use them in 'recipient' field for emailing.
Seems straight forward, but I receive the following error, even though 'typeof()' returns strings. I can't seem to get away from the [JavaScript Object]. Tried toString() and all sorts. Any help is appreciated.
Error message
Error while executing JavaScript computed expression
Script interpreter error[TypeError] Error calling method 'includes(string)' on an object of type 'String [JavaScript Object]'
JavaScript code
var array = documentContract.getItemValueArray("EmailAddress")
var result = "";
for (var i=0; i<array.length; i++) {
if ( array[i].includes("#mydomain.com")) {
result = result + array[i] + "\n";}
}
return result;
The error message says that includes is not an available method on the string object.
You can use #Contains:
if (#Contains(array[i], "#mydomain.com")) {
Gotta love Formula language:
evaluate('#Trim(#Left(EmailAddress, "#mydomain.com"))+"#mydomain.com"', documentContract)
Watch out for uppercase and no mydomain at all. Maybe the evaluate isn't even necessary, it might just function in SSJS without it.

Node.js - Pass Session Variables to a SQL Server function call

In a MS Teams BOT I have working dialog code to ask a series of questions and return the formatted response back to the user in a session like so:
session.send(`Details: <br/>Question1: ${session.dialogData.Question1} <br/>Question2: ${session.dialogData.Question2} <br/>Question3: ${session.dialogData.Question3}`);
So I know the values I need are in the session variables. Now I want to pass the session variables to an SQL insert function (executeStatement):
var session_username = session.dialogData.username
var session_yesterday = session.dialogData.yesterday
var session_today = session.dialogData.today
var session_obstacles = session.dialogData.obstacles
executeStatement(session_username, session_yesterday, session_today, session_obstacles)
I can pass strings and the function works fine. But when I try to pass the session variables like above or just passing session.dialogData.yesterday for instance, straight into the function all of the code runs fine - no errors are thrown - but the session variables are not inserted and 0 rows are returned.
What is the proper way to pass a session variable? Google has not been kind in this regard. :)
Thank you in advance...
Edit:
So I couldn't sleep and had a (weird) idea. Use the session.send when assigning the values to the variable like so:
session_username = session.send(`${session.dialogData.username}`)
or
session_username = session.send(session.dialogData.username)
It writes to the database but it is an [object Object] value. So how do I get to the actual value? Hmmm...Still looking
Edit 2:
To get at the object value I tried:
session_yesterday = session.dialogData.yesterday.text()
and
session_yesterday = session.dialogData.yesterday.value()
For the 1st attempt, .text() I received the following error:
TypeError: Cannot read property 'text' of undefined
at Array.<anonymous> (C:\Developer\dailyStatus\index.js:96:56)
at C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\WaterfallDialog.js:67:39
at next (C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\WaterfallDialog.js:92:21)
at WaterfallDialog.beforeStep (C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\WaterfallDialog.js:99:9)
at WaterfallDialog.doStep (C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\WaterfallDialog.js:61:14)
at WaterfallDialog.dialogResumed (C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\WaterfallDialog.js:46:14)
at Session.endDialogWithResult (C:\Developer\dailyStatus\node_modules\botbuilder\lib\Session.js:358:28)
at PromptText.Prompt.invokeIntent (C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\Prompt.js:331:21)
at PromptText.Prompt.replyReceived (C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\Prompt.js:147:18)
at Session.routeToActiveDialog (C:\Developer\dailyStatus\node_modules\botbuilder\lib\Session.js:525:24)
/ - ERROR: Cannot read property 'text' of undefined
/ - Session.endConversation()
I was stubbornly trying to access the variables because I KNEW that the information was there.
I tested going back up into the dialog results.response like below and it worked:
session.dialogData.yesterday = session_yesterday = results.response;
It honestly is still a little odd to me that I couldn't just access the variable directly but oh well - lesson learned I guess.
Thank you

Passing String to Prepared Statement in Golang

The idea is I want to update the status and returning the id only if the status is different.
So, I have a prepared statement like this:
var theQuery = `UPDATE process SET status=$1 WHERE status!=$1 AND id=$2 RETURNING id`
Then, I called it with this:
err = statement.QueryRow("set", 12).Scan(&id)
Then there is an error appear like this.
runtime error: invalid memory address or nil pointer dereference
When I tried:
var theQuery = `UPDATE process SET status='$1' WHERE status!='$1' AND id=$2 RETURNING id`
It runs. Then, when I run it again, I am expecting to get no rows, but it still returning the id. It looked like it still updating the rows and ignored the status!='$1' part.
Thank you
So, I just find the solution. Instead of using $1 twice, the prepared statement will received 3 arguments:
var theQuery = `UPDATE process SET status=$1 WHERE status!=$2 AND id=$3 RETURNING id`
Then, I call the prepared statement like this.
status := "set"
err = statement.QueryRow(status, status, 12).Scan(&id)
I know maybe this is not the best approach to solve the problem. But it worked for me.

NullPointerException when executing same action multiple times

In my xhtml page, I have a search button and a p:datatable to display the search results. I added a c:if condition to hide and display the datatable.
<c:if test="#{!search_bean.isResultList}">
In my managedBean, I created the flag isResultEmpty and set it to true in my doInit(). In the action of my search button (actSearchForData), I've set it to true if my List is not empty.
private String actSearchForData() throws Exception {
if(resultList.size > 0) {
isResultEmpty = false;
}
}
Now this works without any errors the first time I execute actSearchForData and my resultList is displayed. But when I try to run actSearchForData the second time, I encounter nullpointer exception. I've tried debugging by returning isResultEmpty = true after getting the resultList but this only causes my flag to always return isResultEmpty = true.
How can I execute my search function multiple times and display the results in the datatable without getting any nullpointer exceptions?
UPDATE: I've tried using render again this time for the flag like rendered="!#{search_bean.isResultEmpty}". I no longer get nullpointerexception and my result list count displays the correct number of results but my data table does not show.
The JSF way to control conditional rendering is to use the rendered attribute like
<p:dataTable id="..."
value="#{search_bean.resultList}"
var="..."
rendered="#{not empty search_bean.resultList}" />
This will not render the datatable if resultList is null or resultList.size() is 0.
you must be getting NullPointerException (maybe) - because your "resultList" is null and still you are executing "resultList.size" inside "if(..)" statement
try something like This...
private String actSearchForData() {
if(resultList==null || resultList.size>0) {
isResultEmpty=false;
}
}
This code executes "isResultEmpty=false" - if(resultList is null)
Hope this works for you...

Exception occured with replaceItem and date value

I am getting the following error when trying to set a date value using #Date value with replaceItemValue.
The error I am getting occurs on the last line of code here:
var dt = #Date(2012,1,1);
docContractor.replaceItemValue("NewField","Hello World");
docContractor.replaceItemValue("ContractorStartDateTime",dt);
The error is:
Error while executing JavaScript action expression
Script interpreter error, line=21, col=31: [TypeError] Exception occurred calling method NotesDocument.replaceItemValue(string, Date) null
How can I fix this?
The following works:
docContractor.replaceItemValue("ContractorStartDateTime", session.createDateTime("Today"));
You can find more examples in the Notes and Domino App Dev wiki: http://www-10.lotus.com/ldd/ddwiki.nsf/dx/NotesDateTime_sample_JavaScript_code_for_XPages
Did you try to use a NotesDateTime object instead?
Or use toString ()

Resources