Crystal Report-FORMULA - crystal-reports

I am trying to create two FORMULA fields in Crystal Reports with the same Column in the Database using the following Syntax:
FORMULA1- COLL_DATE
if Collection_Rejection_Desc = 'Cleared'
then Coll_Rej_Dt
else null
FORMULA2- REJ_DATE
if Collection_Rejection_Desc = 'Rejected'
then Coll_Rej_Dt
else null
But it is giving me error saying "a Date and Time Field is expected here"
How can I resolve this?

you can't give one value as date time and other as null in a if condition.. change like this:
FORMULA1- COLL_DATE
if Collection_Rejection_Desc = 'Cleared'
then ToText(Coll_Rej_Dt)
else ""
FORMULA2- REJ_DATE
if Collection_Rejection_Desc = 'Rejected'
then ToText(Coll_Rej_Dt )
else ""

You may want to return Coll_Rej_Dt when the condition is correct, otherwise return null.
you can use Switch by replace if condition. Because in if condition, you need to return same data type in true part and false part.
So, try this...
Switch (Collection_Rejection_Desc = 'Cleared', Coll_Rej_Dt)
Switch (Collection_Rejection_Desc = 'Rejected', Coll_Rej_Dt)
this will return value when the condition is true.

Related

empty form text filed

I'm using a FormTextField in a Flutter app
To update a certain column value, the user types in the FormTextField, otherwise leaves the field empty.
I tried this code, but it was adding a null value to the column, deleting the existing value. I'm not happy with this behavior.
String _getProd5Name() {
if ((_prod5Controller.text).isNotEmpty == true) {
_prod5String = _prod5Controller.text;
}
return _prod5String;
}
Is there a way to do it?
I found similar questions, but they are relevant to other languages and their solutions don't solve my case.
String _getProd5Name() {
// Actually you don't have to make it private
// since this is a local variable inside a function
String _prod5String = variableContainingInitialValue;
if (_prod5Controller.text.isNotEmpty) {
_prod5String = _prod5Controller.text;
}
return _prod5String;
}
Here is my advice, since I love wrapping everything on 1 line. You can change the "" part with your result expectation. It's the same with your logic but it's shorter and instead of returning null I make it returning the empty string "". And also (_prod5Controller.text).isNotEmpty == true you can just shorten it to (_prod5Controller.text).isNotEmpty because .isNotEmpty always returning boolean true/false and if-else consuming boolean
String _getProd5Name() {
return ((_prod5Controller.text).isNotEmpty) ? _prod5String = _prod5Controller.text : "";
}

I have a query that returns '[ ]'. I want it to be shown on a widget as not having any value, how do I do this?

I have a query in my flutter app that should return empty if 'archived' 'isNull' is set to true. I accomplished that, but the issue I'm having now is the fact that the query returns empty (i.e [ ]). And on the widget, I want this to be shown as not having any value but instead, an empty pair of brackets '()' keep showing up.
I have tried checking for when query data equals null, something like this:
if (queryResult.data == null){
// The idea is for it not to just return '()' as the value
value = null;
}
else{
value = queryResult.data;
}
And also:
if (queryResult.data == []){
value = null;
}
else{
value = queryResult.data;
}
How do I go about this? Thanks in advance.
If "data" is a list why not try data.isEmpty() ? And also if you only need to avoid the brackets (dirty fix alert ⚠️) whatever you did it's returning a string value '()' then you check that
if(yourResults == '()' )value == null;
And please add more details for a better answer .

Show nothing if the item doesn't have a date

I want my code to display nothing if it doesn't have a date.
Here is my code:
=format(IIF(Fields!Phase.Value = "Pre-Feasibility" OR Fields!Phase.Value = "Selection", Fields!PreFeasibilityCurrentTargetDate.Value, IIF(Fields!Phase.Value = "Feasibility" OR Fields!Phase.Value = "Definition", Fields!FeasibilityCurrentTargetDate.Value, IIF(Fields!Phase.Value = "Implementation", Fields!ImplementationCurrentTargetDate.Value, ""))), "dd-MMM-yy")
Because I am formatting it to dd-MMM-yy, it displays that when the item doesn't have a date. How can i have this changed to display nothing if it doesn't have a date.
Change the blank values of your expression to nothing
=Iif(Fields!Phase.Value="Operation","-", format(
IIF(Fields!Phase.Value = "Pre-Feasibility" OR Fields!Phase.Value = "Selection",
Fields!PreFeasibilityCurrentTargetDate.Value,
IIF(Fields!Phase.Value = "Feasibility" OR Fields!Phase.Value = "Definition",
Fields!FeasibilityCurrentTargetDate.Value,
IIF(Fields!Phase.Value = "Implementation",
Fields!ImplementationCurrentTargetDate.Value, Nothing)))
, "dd-MMM-yy") )
I would also advice you to use the field format property instead of the format function inside the value expression. In this case it works even if the field value is blank
check the MSDN form here,
https://msdn.microsoft.com/en-us/library/ms157406.aspx
it clearly mention that "If you specify an invalid format string, the formatted text is interpreted as a literal string which overrides the formatting."
So. you need to check the string after formatting,
IIF(output="dd-MMM-yy","",output)

Why does my ternary operator give a different result to an if else?

The problem I am having is I am trying to use ternary operators over if else for smaller code but when using it in my case it is returning a different result than if I use an if else.
The problem code is below;
If Else
if(string.IsNullOrEmpty(jn["LARM"].Value))
pm.ItemLeftArm = null;
else
pm.ItemLeftArm = jn["LARM"];
Ternary
pm.ItemLeftArm = string.IsNullOrEmpty(jn["LARM"].Value) ? null : jn["LARM"];
The jn["LARM"] is a json node from simpleJSON and it is either a number e.g. "0" or nothing e.g. "".
It returns null form the if else but it returns the jn object which transforms from "" into 0.
Im not sure why Im getting this issue.
The code is ok, the problem must be in the JSON. Have you tried logging the jn["LARM"].Value just before the terniary operator in order to be sure that the value is null/empty or not?
BTW, why are you using simpleJSON instead of the new Unity integrated JsonUtility?

MySQL boolean type to return boolean query?

I'm trying to see if its possible to test for a certain result specific to a boolean value in an SQL database.
if($result = $mysqli->query("SELECT * FROM `work_orders` WHERE `is_open` = '1' "))
{
show_workorder($result);
}
I would then want to execute:
#TRUE allows this to show
if($result = True){
echo "<p> No current work orders are open. Good Work !</p>\n";
return;
}
If i change database in work_orders.is_open , the boolean is 0, meaning its "not open" .. the if statement for TRUE above, still shows...
I am sure that I'm missing something.
Seems I have solved my own question:
the if statement should just test for rows that were returned or not.
if($result->num_rows == 0)
this would allow it to show if there is nothing returned. If results are returned then it will continue moving forward.