How to use If Else in SSRS expression - sql

I am trying to evaluate a text box value using SSSRS expression.
Currently I am doing something like following:
=IIF(Fields!VariableValue.Value =1,"Pass",IIF(Fields!VariableValue.Value = 2,"Fail",IIF(Fields!VariableValue.Value = 3,"Abort",IIF(Fields!VariableValue.Value = 4,"ByPass",IIF(Fields!VariableValue.Value ="#Error","NA",Fields!VariableValue.Value)))))
Is there a better way of doing this?

It's not perfect, but you can use SWITCH to make it a bit easier to read:
=Switch
(
Fields!VariableValue.Value = 1, "Pass",
Fields!VariableValue.Value = 2, "Fail",
Fields!VariableValue.Value = 3, "Abort",
Fields!VariableValue.Value = 4, "ByPass",
Fields!VariableValue.Value = "#Error", "NA"
true, Fields!VariableValue.Value
)
Looking at your example, I'm not 100% sure the original or the new expression will even work (is VariableValue a number or text?) but hopefully this is better way for you.

Related

Polarion Velocity Script adding a custom field integer

I'm new to Velocity scripting and made a few simple scripts and they work ok.
I'm now trying something else, which should be simple but I can't seem to get it to work.
I'm selecting a bunch of Work Items, reading a custom field (NumberPack) and I just want to sum them.
My script is as follow:
#set($PCR = $transaction.workItems.search.query("type:Paramrequest AND created:[20220101 TO 30000000] AND NumberPack.1:[00000000001 TO 02147483647]"))
#set($Total = 0)
#set($Pack = 0)
#set($x = 0)
#foreach($PCR in $PCR)
##set($Pack = $Pack.parseInt($PCR.fields.get("NumberPack")))
##set($x = $Total.add($Pack))
$PCR.fields.get("NumberPack").render ## this renders each NumberPack of each WI
#set($Pack = $PCR.fields.get("NumberPack"))
##set($x = $Total2.add($PCR.fields.get("NumberPack")))
##set($Total2 = $Total2 + 1)
#set($x = $math.add($x, 1))
#end
<br> Total: $Total
<br> $x
As you can see I tried a few methods but I keep getting the total 0.
Any ideas what I'm doing wrong?
Thanks
If you write
#set($Pack = $PCR.fields.get("NumberPack"))
Pack: $Pack <br>
the output is something like:
Pack: com.polarion.alm.server.api.model.fields.ProxyIntegerField#67807d51
In the API Javadoc (https://almdemo.polarion.com/polarion/sdk/doc/javadoc-rendering/com/polarion/alm/shared/api/model/fields/IntegerField.html), you'll find that api.model.fields IntegerField has a get() method, which gives you the value. Though I agree this is never explicitly stated in the documentation.
You need to write
#set($Pack = $PCR.fields.get("NumberPack").get())
to get the value. The following statement will give you the cumulative sum.
#set($Total = $math.add($Total, $PCR.fields.get("NumberPack").get()))
Also be careful with your #foreach statement. In this case it seems to work, but it would be safer to give your iterator variable a name differing from the collection you are iterating through. For example:
#foreach($PCR in $PCRs)

Why does R.all with R.both does not equal R.allPass with the same arguments?

I'm just learning while doing ramda.js. Well, there are many ways to reach a goal with ramda, but there is on thing I do not understand.
I would like to check the input for an array of strings that all match one regular expression. I thought I could do it R.all(R.both(isString, isRegExp)), but it seems to deliver a true when the input is a number.
As expected R.allPass([isString, isRegExp]) gives a false with a number input.
But can anyone please explain me why R.all is returning a true? Or what and where is mistake (in thinking)?
Complete code:
var isString = R.is(String),
isMyRegExp = R.test(/^[a-z]+$/),
isMyRegExpString = R.both(isString, isMyRegExp),
isArrayOfMyRegExpStrings = R.all(isMyRegExpString),
isArrayOfMyRegExpStringsPass = R.allPass([isString, isMyRegExp]),
result = {
'all': isArrayOfMyRegExpStrings(9),
'allPass': isArrayOfMyRegExpStringsPass(9)
};
console.log(result);
// {
// all: true,
// allPass: false
// }
https://codepen.io/Eisenhardt/pen/PKLZqj
PS:
I know that I could shorten conditions with just the regexp, but there could be other situations where I need both conditions to be true. eg. isArrayOfNumber and sumOfNumbersOver50.
The second argument to R.all is expecting a list of values to test. Due to the way the function is implemented it is treating the 9 in your example as an empty list, resulting in a vacuous truth and evaluating to true.

Lua property accessor

I'm confused by how Lua properties are working in some of the code I'm trying to maintain. I've spent a good amount of time in the Lua documentation before this. So...
There is a function in one of those Lua tables, like this (we'll call this the 'nested tables' example):
function addItem(item)
index = itemTable.getIndex(item.position[1], item.position[2])
itemTable.items[index] = item
end;
a = Xpl3dSwitch { position = { 27, 0, 1, 1} }
itemTable.addItem(a) --doesn't seem to 'register' the position property
whereas
a = Xpl3dSwitch { }
a.position[0] = 27
a.position[1] = 0
itemTable.addItem(a) --this 'registers' the position properties
...etc, seems to work. Why are the position tables not sticking in the 'nested table' example?
Also, regarding 'a = Xpl3dSwitch { }' - is it an object constructor? It's not clear from the Lua 'documentation' what this is.
Look inside the table a and compare them. That should point you in the direction where the error happens.
to look inside a use something like:
function getTableContent(tab, str)
str = str or "table"
for i, v in pairs(tab) do
if type(v) == "table" and v ~= _G then
str = str.."->"..tostring(i)
getTableContent(v, str)
else
print(str.." Index: "..tostring(i).." Value: "..tostring(v))
end
end
end
getTableContent(a)
io.read()
Once you know how the working and the not working one are structured you should be able to make the adjustments needed.
Edit:
Also you could use:
a = Xpl3dSwitch { }
a.position = {27, 0, 1, 1}

IsDayLightSavingTime changed?

Before, this code would return True, now it returns False. Have any of you hear of an update on this function?
d2 = New DateTime(2010, 11, 7, 1, 0, 0)
Console.WriteLine("D2: " & System.TimeZone.CurrentTimeZone.IsDaylightSavingTime(d2))
We parse files and put the data into a database, if I parse the exact same file with the same code (it was never changed) I get different results.
Update
This is EST/EDT

rdlc expression iif use?

In an rdlc report I want to compare integers like
if(expression)
{
// do something
}
else if(expression)
{
// do something else
}
What is the syntax for this?
Rather than using nested IIF statements I prefer the Switch statement.
From the MSDN...
=Switch(
Fields!PctComplete.Value >= 10, "Green",
Fields!PctComplete.Value >= 1, "Blue",
Fields!PctComplete.Value = 1, "Yellow",
Fields!PctComplete.Value <= 0, "Red"
)
Hope it helps :)
You will have to nest IIF statements like this:
= IIF (expression = 1, "Is 1", IIF (expression = 2, "Is 2"))
Use switch instead. I know I reached late here,but hope that it may help someone.
=Switch(Fields!Parameter.value = 2,"somethingnew", 1=1 ,"somethingelse")
1=1 refers to default in switch case.
It is similar like
if(Parameter.Value == 2)
{
somethingnew
}
else
{
somethingelse
}
This is the Syntax for your requirement:
=IIf(CInt(Fields!expression1.value)==1,true,IIf(Cint(Fields!expression2.value)==2,true,nothing))
In true part you can specify the statement to be executed.
In addition to what has been said, the If(condition, true_part, false_part) ternary operator should (with one I) be preferred over the IIf(condition, true_part, false_part) function (with two I's) in most cases.
The If() ternary operator will short-circuit evaluate only the part that corresponds to condition outcome (e.g. a condition that is True will only evaluate the true_part).
The IIf() function will always evaluate the condition and both parts, because it is just a function call and all parameters of the function will be evaluated before the call.
Since developers usually expect short-circuit evaluation in IF statements, the usage of the If() ternary operator should be the default choice.
It allows you to run expressions that check for Nothing, like the following, which would not work without lazy evaluation:
=If(Fields!Blog.Value IsNot Nothing, Fields!Blog.Value.Name, "Blog is missing")
You could also try this example
= IIF(Parameters!expression.Value = True, 'somethingnew', 'somethingelse')