getSubmittedValue() vs. getValue() - xpages

Is that correct:
When I query a value before validation (or if validation failed) I have to use getSubmittedValue();. Once the value is validated, even if I query it in another validation later in the page/control I have to use .getValue(); since getSubmittedValue(); returns null after successful validation?

This xsnippet makes it easier to handle this. It allows you to just call getComponentValue("inputText1") to get either value or submittedValue.
Here's the function for reference:
function getComponentValue(id){
  var field = getComponent(id);
  var value = field.getSubmittedValue();
  if( null == value ){
         // else not yet submitted
         value = field.getValue();
  }
 
  return value
}

There's a slightly easier way: if you're just expecting a simple single-value String, just call:
var compare = firstField.getValueAsString();
Otherwise, call:
var compare = com.ibm.xsp.util.FacesUtil.convertValue(facesContext, firstField);
The former calls the latter anyway, but is obviously a terser syntax. This does what you're looking for and more:
If the value hasn't yet been validated, returns the submitted value
If validation has already passed, returns the value after it's already been processed by any converters and / or content filters, so particularly in cases where you're trying to compare two field values, this should ensure that both values have been properly trimmed, etc., and is therefore less likely to return a false positive than just comparing the raw submitted values.

Found the answer here. So when you want to ensure that 2 text fields have the same value (use case: please repeat your email) and the first box already has a validation that might fail, you need to use submittedValue unless it is null, then you use the value. Code in the validation expression for the second field looks like this:
var firstField = getComponent("inputText1");
var compare = firstField.getSubmittedValue() || firstField.getValue();
compare == value;
You have to love it.

Related

Nodejs (Infinispan) : Does Infinispan put method returns null for key inserted in cache for first time?

I have been reviewing the infinispan documentation and overloaded put method returns the value being replaced, or null if nothing is being replaced.
I am using overloaded put method with nodejs and it's not returning expected data, getting undefined.
how can I achieve this with nodejs?
Looked at the documentation, need assistance to understand the behavior with Nodejs
Documentation Link : https://docs.jboss.org/infinispan/9.2/apidocs/org/infinispan/commons/api/BasicCache.html#put-K-V-
V put(K key,
V value,
long lifespan,
TimeUnit unit)
An overloaded form of put(Object, Object), which takes in lifespan parameters.
Parameters:
key - key to use
value - value to store
lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
unit - unit of measurement for the lifespan
Returns:
the value being replaced, or null if nothing is being replaced.
Looked at the documentation, need assistance to understand the behavior with Nodejs
From https://github.com/infinispan/js-client/blob/main/lib/infinispan.js#L327 it looks like put's third argument opts can have property previous that makes it return the old value, so try:
const oldValue = client.put('key', 'value', { previous: true })

Get all collection result if null value appears in match filter in mongoose

Really don't know how to describe my problem. I tried my best. I have a collection and I want anyone to search through multiple parameters. I used the $match filter for this. here is my code.
db.product.aggregate([{$match:{lastStatus:req.query.status,name:req.query.name}}])
This is working fine. but I am taking the match values from the user via API and there is a chance that the user didn't pass these values, in that case, I return the products based on the applied match. suppose the user only passes the name, then the result comes on the basis of the name, not on lastStatus. right now this query does not work if any of the provided values is empty or undefined.
what can be the solutions
You can check the condition if any of the field has value then set the value in the match variable.
let match = {};
// MATCH STATUS
if (req.query.status) match["lastStatus"] = req.query.status;
// MATCH NAME
if (req.query.name && req.query.name.trim() != "") match["name"] = req.query.name.trim();
db.product.aggregate([{ $match: match }]);

Filter leading to different results when typed manually and via defined as a variable

I'm trying to create a calculated column indicating if a team has a prize or not from the table below:
To do that I need to count within the group if there's a player whose "Prize" field is not empty. Here's the 1st attempt:
Dax Formula:
=
Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = len(Table4[Prize])>0
Return
calculate(countrows(filter(Table4,len(Table4[Prize])>0)),Player_Same_Team)>0
Looks like it's going what I intend it to do. However, when I swap the filter content to a pre-defined variable, it gave me results that don't make sense:
Dax Formula:
=
Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = len(Table4[Prize])>0
Return
calculate(countrows(filter(Table4,Has_Prize)),Player_Same_Team)>0
The typed content len(Table4[Prize])>0 is the same as that in the variable, so what may be causing the difference? Thanks for your help.
As soon as you assign it to a variable, the value of the variable remains constant. Therefore the Len is evaluated to a value, that you are then passing as a filter.
The first example works because the CALCULATE accepts a table as a parameter, and player_same_team is evaluated to a table, by using the FILTER expression.
In order for what you are trying to do to work it would have to be something like this:
= Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = filter(Table4,len(Table4[Prize])>0)
Return calculate(countrows(Has_Prize),Player_Same_Team)>0
You can also write the measure in a slightly different way:
= CALCULATE ( COUNT(Table4[Team]),
ALLEXCEPT(Table4[Team]),
LEN(Table4[Prize])>0) > 0

Xpages SSJS Time part of NotesDateTime does not return its real value

One of my date/Time filed value always return with 12:00:00. I have the same field with another document which always return with the correct value.
I am trying to calculate timeDifferences of these two fields values. Because of this issue calculation always returns wrong. What did i miss?
var hdt1:NotesDateTime = doc.getItemValueDateTimeArray("Tarih").elementAt(0);
var hdt2:NotesDateTime = hhDoc.getItemValueDateTimeArray("Tarih").elementAt(0);
var frk:int=0;
print(hdt1);print(hdt2);print("------------------");
frk = hdt2.timeDifference(hdt1);
doc.getFirstItem("Tarih").getDateTimeValue()

NotesXSPDocument and NotesDocument

I have created a function in SSJS Library. Because I use it in more than one XPages.
When I call this function behind a button I cannot see the value in the field
If I print it out I can see the value at the Admin Console but cannot see it in the form Even if I get page with full refreshed.
Actually my another question is.. is it possible to compare notesXSPDocument and NotesDocument. Maybe someoen can say that what is the best way for that?
function deneme(document1:NotesXSPDocument,otherDocfromOtherDatabase:NotesDocument)
{
//do staff here
if (document1.getItemValueString("field1")==otherDocfromOtherDatabase.getItemValueString("field2"))
{ //do some staff here...
document1.replaceItemValue("fieldName","FieldValue");}
}
You can compare item values from Document and XSPDocument, just be careful with the type you are comparing.
In your code you are comparing 2 javascript strings with == operator.
The code seems to be OK, just remember to save the document1 after the changes and maybe check that the items have some value.
var valueFromXspDoc = document1.getItemValueString("field1");
var valueFromDoc = otherDocfromOtherDatabase.getItemValueString("field2");
if (valueFromXspDoc && valueFromDoc && (valueFromXspDoc === valueFromDoc)) {
// stuff here...
document1.replaceItemValue("fieldName","FieldValue");
document1.save();
}
Don not compare it with == sign. A better way is to document1.getItemValueString("field1").equals(otherDocfromOtherDatabase.getItemValueString("field2"))

Resources