I would like to ask about the if else expression in ireport jasper report. May I know is it possible to have multiple or more parameter in the if else statement?
(($P{endDate}.isEmpty()==true || $P{endDate}.equals(""))? "" :
" createDate>='" + $P{startDate} +"'" && " createDate<='" + $P{endDate} +"'")
Based on the code above, there are not allowed me to use "&&". It prompt out syntax error.
Besides that, May I know any solution to solve it? Thank you very much.
I'm assuming it's a query expression your trying to write. You probably would have to do something as follows:
Create a parameter for your dataset. This parameter should not be "prompted" and lets call it DATE_LIMIT_EXPRESSION. You should then set its default value as your expression. For example (if I a get what you meant), this could be your default expression:
"1" +
(($P{startDate}.isEmpty() == false) ? (" AND createDate >= " + $P{startDate}) : "") +
(($P{stopDate}.isEmpty() == false) ? (" AND stopDate <= " + $P{stopDate}) : "")
Now, your dataset query should be something like:
select
...
where $P!{DATE_LIMIT_EXPRESSION}
Just notice the "$P!" syntax. You can find more information about this in the Jasper Reports' documentation.
Related
I'm working with an api that excecutes an aws Insights query. I check some business layers and then add filters to the query.
Those filters are from a list of errors that I can't change.
The trouble is that I cant make an standard function to add the filters. Now I'm using
public CWL_InsightsQuery NotLike(string field, string value, int index = -1) {
if (index < 0) {
int Index = QSegments.FindIndex(x => x.StartsWith("filter"));
QSegments[Index] = QSegments[Index] + " and " + SetInternalField(field) + " not like /"" + value + "/" ";
} else {
QSegments[index] = QSegments[index] + " and " + SetInternalField(field) + " not like /"" + value + "/" ";
}
return this;
}
QSegments stands for the construction of the query.
In simple terms, I ended up with an string like
|filter Data not like "value here lol"
this IS working, and its fine. The trouble starts when value has quotation marks, or different special characters.
So, Value can be this "is a" very 'unique' value /and i hate it/
so, I cant use '', neither / or " to declare the filter string.
Is there any escape character, as # in C#?
Would need something in CloudWatch Log insights like
#"I love how ""this query"" works 'every' time /i/ need it"
Thank you very much!
Inside my data flow pipeline I would like to add a derived column and its datatype is array. I would like to split the existing column with 1000 characters without breaking words. I think we can use regexSplit,
regexSplit(<string to split> : string, <regex expression> : string) => array
But I do not know which regular expression I can use for split the existing column without breaking words.
Please help me to figure it out.
I created a workaround for this and it works fine for me.
filter(split(regexReplace(regexReplace(text, `[\t\n\r]`, ``), `(.{1,1000})(?:\s|$)`, `$1~~`), '~~'), #item !="")
I think, we have a better solution than this.
I wouldn't use a regex for this, but a truncating function like this one, courtesy of TimS:
public static string TruncateAtWord(this string input, int length)
{
if (input == null || input.Length < length)
return input;
int iNextSpace = input.LastIndexOf(" ", length, StringComparison.Ordinal);
return string.Format("{0}…", input.Substring(0, (iNextSpace > 0) ? iNextSpace : length).Trim());
}
Translated into expression functions it would look something* like this.
substring(Input, 1, iif(locate(Input, ' ', 1000) > 0, locate(Input, ' ', 1000) , length(Input)) )
Since you don't have a lastIndexOf available as an expression function, you would have to default to locate, which means that this expression truncates the string at the first space after the 1000th character.
*I don't have an environment where I can test this.
I'm trying to determine if it's between the hours of 12 am and 1 am. Here is my if statement:
If InStr(Time,"12") AND InStr(Time,"AM") Then
' Do something
Else
' Do something else
End If
The problem is that this statement evaluates to false, even if both of the conditions are true. I know this because I have tried a nested if like this
If InStr(Time,"12") Then
If InStr(Time,"AM") Then
' Do something
...
And that works. This also works
If InStr(Time,"12")<>0 AND InStr(Time,"AM")<>0 Then
' Do something
...
But if it works as a nested if, why can't I test both of the nested if conditions in a single if statement?
I replaced the InStr function calls with the values that they return
If 1 AND 10 Then
' Do something
Else
' Do something else
End If
And the same thing happened: the if statement evaluated as false and the "Do something else" commands were executed instead. But when I nested the second condition as another if statement inside the first if statement, the "Do something" commands were executed.
Why is that and is there any way to do this without the <>0 and without nesting?
If Time() >= TimeValue("12:00:00") AND Time() <= TimeValue("23:59:59") then
'Do Something
ElseIf Time() >= TimeValue("00:00:00") AND Time() <= TimeValue("01:00:00") then
'Do the same
Else
'Do something different
End If
This should work :)
The problem you observed is caused by the fact that VBScript uses the same operators for boolean and bit operations, depending on the data type of the operands. The InStr function returns a numeric value unless one of the strings is Null, so the operation becomes a bitwise comparison instead of a boolean comparison, as JosefZ pointed out. The behavior is documented:
The And operator also performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result [...]
Demonstration:
>>> WScript.Echo "" & (True And True)
True
>>> WScript.Echo "" & (6 And 1) '0b0110 && 0b0001 ⇒ 0b0000
0
>>> WScript.Echo "" & (6 And 2) '0b0110 && 0b0010 ⇒ 0b0010
2
To enforce a boolean comparison you need to use InStr(...) > 0 or CBool(InStr(...)) (both of which evaluate to a boolean result) instead of just InStr(...) (which evaluates to a numeric result).
Date and Time are stored as number of days, where midnight is 0.0, and 1 am is 1/24 :
If Time <= 1/24 Then ' or If Time <= #1am# Then
When you using Time() function and if result like that 10:12:12 AM in this way Instr will result Ture because Instr by default use vbbinarycompare looking For any 12in binary format in 10:12:12 AM and there is sec and min 12 so it will Return True .
just try this :
myHour=replace(Time,Right(Time,9),"") 'get only the hour from time
myAMPM=replace(Time,Time,Right(Time,2)) 'get only AM or PM from time
If InStr(1,myHour,12,1) > 0 AND InStr(1,myAMPM,"AM",1) > 0 Then
wscript.echo "True"
Else
wscript.echo "False"
End If
I don't know why this code doesn't work:
Dim a
a = InputBox("What time do you want?")
If InStr(a, "pm") Then
(Replace(a, "pm", ""))
a = a + 12
c = MsgBox(a, 0, Time)
WScript.Quit
Else
End If
b = MsgBox(a & form, 0, "L")
Whenever I try to start it, it responds with:
"Error: Expected Statement"
Is it because the Replace statement isn't right or because there's a mistake in the rest of the script?
When you try to run that code you should get the following error
Microsoft VBScript compilation error: Expected statement
Line 4
which will lead you to the culprit which is
(Replace(a, "pm",""))
which isn't a valid statement in VBScript hence the error.
Based on what you are trying to do the script needs to return the result of the Replace() function call, something like this
a = Replace(a, "pm","")
I am using a RegEx that is working in DevMode but not once compiled and deployed. It is part of a class extending com.google.gwt.user.client.ui.SuggestOracle.Suggestion:
#Override
public String getDisplayString() {
String toReturn = myUser.getName() + " (" + myUser.getUserid() + ") " + (myUser.getCompanyname() == null ? "N/A" : myUser.getCompanyname());
return toReturn.replaceAll("(?i)" + "(" + myInput + ")", "<b>$1</b>");
return toReturn;
}
The official documentation (http://www.gwtproject.org/javadoc/latest/com/google/gwt/regexp/shared/RegExp.html) states the following:
There are a few small incompatibilities between the two implementations. Java-specific constructs in the regular expression syntax (e.g. [a-z&&[^bc]], (?<=foo), \A, \Q) work only in the pure Java implementation, not the GWT implementation, and are not rejected by either. Also, the Javascript-specific constructs $` and $' in the replacement expression work only in the GWT implementation, not the pure Java implementation, which rejects them.
Still, I don't know how to adapt my RegEx so that it works once deployed.
This site (http://planet.jboss.org/post/smartgwt_tip_regex_evaluation) says this:
The solution was to order the OR options from most complex to least complex
The Any ideas how to adapt this solution to my probem ?
Cheers,
Tim
JavaScript does not support (?i) to switch to case-insensitive match.
Your best bet is to use com.google.gwt.regexp.shared.RegExp:
public String getDisplayString() {
String toReturn = myUser.getName() + " (" + myUser.getUserid() + ") " + (myUser.getCompanyname() == null ? "N/A" : myUser.getCompanyname());
return RegExp.compile(myInput, "ig").replace(toReturn, "<b>$&</b>");
}