I am checking 3 fields if they are empty or not using a if condition,
String.IsNullOrEmpty(in_Quantity) OR String.IsNullOrEmpty(in_Reference) OR String.IsNullOrEmpty(in_DeliveryDate)
in then part, logging a message-> field value is missing
But how to specify which field has empty values?(there can be more than 1 field having empty value)
Are the fields that your referring to in excel?
No, i will be getting as input from main xaml
What’s there datatype?
String is the datatype
@Shilpa_Mohanty , Hey!!
Have you tried using IF ELSE block separately for all the 3 condition
Ex :
if(String.IsNullOrEmpty(in_Quantity)
{ \\ log message for Quantity
}
else
if (String.IsNullOrEmpty(in_Reference)
{ \\ log message for Reference
}
Else
if(String.IsNullOrEmpty(in_DeliveryDate)
{ \\ log message for DeliveryDate
}
Disadvantage of using this is
- your code will be deep nested!
In UiPath activity we have ELSE IF , do check out!
as per my knowledge, this activity used to specify new condition if the condition is false
if(Condition1)
{ \\ exp to be executed if condition1 is true
}
else if(Condition2)
{ \\ exp to be executed if condition2 is true
}
What if both quantity and reference is empty
I need to have both the fields logged in as field quantity and reference is empty
Use three separate If-statements.
if(String.IsNullOrEmpty(in_Quantity)
{
\\ log message for Quantity
}
if (String.IsNullOrEmpty(in_Reference)
{
\\ log message for Reference
}
if(String.IsNullOrEmpty(in_DeliveryDate)
{
\\ log message for DeliveryDate
}
You can remove the else part like below
if(String.IsNullOrEmpty(in_Quantity)
{ \ log message for Quantity
}
if (String.IsNullOrEmpty(in_Reference)
{ \ log message for Reference
}
if(String.IsNullOrEmpty(in_DeliveryDate)
{ \ log message for DeliveryDate
}
Here you get all the variables that are empty.
can you give any linq query as there will be many if conditions
have a look at following idea
arrKeys = {“Quantity”,“Reference”,“DeliveryDate”}
arrValues = {in_Quantity,in_Reference,in_DeliveryDate}
arrResult =
arrKeys.Select(Function (x,i) If(String.IsNullOrEmpty(arrValues(i)), x,nothing)).Where(Function (x) Not isNothing(x)).toArray
with a particular length of parameters maybe using another datatype e.g. dictionary will be also a preferred option like
You could also use a Dictionary:
dict = New Dictionary(Of String, String) From { {"Reference", in_Reference}, {"Quantity", in_Quantity}, {"DeliveryDate", in_DeliveryDate} }
errorMsg = String.Join(vbNewLine, dict.Where(Function(kvp) String.IsNullOrEmpty(kvp.Value)).Select(Function(k) k.Key + " is empty.").ToArray)
what is the datatype of arrKeys, arrValues and arrResult?
I tried array[String] but dint work as expected
These are string of array
String Array - VB.Net: String()
the good thing on screenshots from immediate panel is, that we have the confirmation that the code is running sucessfully. What was done / implemented at your end. What is not working as expected
Any reasons for not using the dictionary approach?
used dictionary only
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.