How to break .all().each() loop in Protractor once expected element is found? - protractor

I have list of values present in table (one column table). I want to check whether XXX value is present in this table.
For e.g., list of values are as below:
ABC
PQR
XXX
XYZ
LMN
I am able to do this using .all().each() loop in Protractor as below:
element.all(by.className('table_values')).each(function(value){
console.log(value)
if(value == 'XXX'){
console.log('Element found')
}
});
Based on above code snippet, I have 2 questions:
Even after XXX is found at Position 3, it iterates over remaining 2 values. How can I stop the loop as soon as value is found? I tried using break statement, but it gave me Illegal break statement error.
How can I return false if XXX is not present?

Array.some should help you. It checks atleast one satisfies the condition.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some
It returns if false no element meets the condition.

Related

Multiple Conditions in MailMerge Field

I would like to include up to 3 conditions in a MailMerge field. Below is my current field which returns 1 if checkbox1 is checked.
if"<<cb1>>"="Yes" "Checked""Unchecked"
I would like to include checking of additional cb2 and cb3, to check if any of them are checked.
May I know how can it be done?
p.s. I left out the { } colons which I am not sure if it will be required here.
Edit: Tried the following structure but the output was Yes
if
"if"<<cb1>>"="Yes" "1""0""
+
"if"<<cb2>>"="Yes" "1""0""
+
"if"<<cb3>>"="Yes" "1""0""
>0
"1 or more checked""None checked"
Try a field coded as:
{IF{={IF«cb1»= "Yes" 1 0}+{IF«cb2»= "Yes" 1 0}+{IF«cb3»= "Yes" 1 0}}> 0 "1 or more checked" "None checked"}
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac or, if you’re using a laptop, you might need to use Ctrl-Fn-F9); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. Likewise, the chevrons (i.e. '« »') are part of the actual mergefields - which you can insert from the 'Insert Merge Field' dropdown (i.e. you can't type or copy & paste them from this message, either). The spaces represented in the field constructions are all required.
For example, you can create a field with logic such as: “If Condition 1 is met, then if Condition 2 is also met, display Result 1”. This is equivalent to saying “if both conditions are met, display Result 1”; but unfortunately you can't use “and” in Word fields.
Such a field would look something this:
{ IF [Condition 1] { IF [Condition 2] [Display Result 1] "" } "" }
The easiest way to create nested fields of this type is to create them separately, then cut and paste one field into the other.
Source

i want to find out the names of employee whose sallery is greater than 15000

the question create a class name employe which has employe details of three people and I want to find out how much people have sallery greater than 15000
class employe:
def __init__ (self,i,name,sallery):
self.i=i
self.name=name
self.sallery=sallery
a=employe(1,"vinod",10000)
b=employe(2,"vikas",20000)
c=employe(3,"kailash",30000)
def sort(a,b,c):
pay=[]
if a.sallery>15000:
pay.append(a.name)
elif b.sallery>15000:
pay.append(b.name)
elif c.sallery>15000:
pay.append(c.name)
return pay
sort(a,b,c)
according to me the output should be vikas and kailash but it is only shows vikas the kailash is not seen the code is running till elif b.sallery>15000:
pay.append(b.name)
If you change your elif conditions for single if conditions that will do the trick.
That's because of the behavior of if-elif-else structure, If you look at it carefully, you'll find out that when you're calling your function, in that call, it first passes through the first if if a.sallery > 15000 which is not true, then it goes through the second condition if b.sallery > 15000 which is true, then vikas gets inserted into the array and that's it, the code doesn't need to go through the third condition, because the previous one already returned true.
Hope I have explained myself well.

How to update JSON node that matches criteria based on attribute value (instead of index)?

Postgresql 10+
Example from the documentation...
jsonb_set('[{"f1":1,"f2":null},2,null,3]', '{0,f1}','[2,3,4]', false)
results in...
[{"f1":[2,3,4],"f2":null},2,null,3]
Fair enough. But I need to find my target node by attribute value, not index. For the life of me, I cannot figure out how do something like...
jsonb_set('[{"f1":1,"f2":null},2,null,3]', '{(where f1 = 1),f1}','[2,3,4]', false)
Any advice on how to accomplish this?
Thanks!
You can split the steps into two jobs:
Split in elements (jsonb_arral_elements)
Indentify wich elements must change (case when...)
Update that element (jsonb_set)
Join all together (jsonb_agg)
solution
select jsonb_agg(case when element->>'f1'='1' then jsonb_set(element, '{f1}', '[2,3,4]') else element end)
from jsonb_array_elements('[{"f1":1,"f2":null},2,null,3,{"f1":3},{"f1":1,"f2":2}]'::jsonb) element
note
I changed the input adding two more elements with "f1" key

How to instantiate local variables in decision tables

I am pretty new to drools and am given the below task.
I am inserting a few POJO into my KieSession object and am retreiving them into variables in my decision table as follows.
CONDITION CONDITION CONDITION ACTION
abc: classABC xyz: classXYZ lmn : classLMN
var1 == $param var2 == $param
1 2 3
As far as I understand, the above table would yield the following rule
when
abc:classABC(var1==1)
xyz:classXYZ(var2==2)
lmn:classLMN(var3==3)
then
some action
What I want is to get the following.
when
abc:classABC(var1==1)
xyz:classXYZ(var2==2)
lmn:classLMN(var3==3)
fgh:classFGH($var:var4) // I think this step is creating a new variable to hold value of var4
then
some action
How do I get this on a decision table ?
I tried just adding a condition column with the variable declaration as fgh :classFGH, but since there is no data to be provided in the data row, this column would be ignored. If I do, give some data, there is an error at compile time "no code sinppet at xyz column". All I need is to declare a variable that can hold the value of the object that I have passed in my main method and use that object later in a different column of my decision table.
I'm not sure I get the requirement around the decision table, but you can 'use' the firing of a rule to create new facts and insert them, with parameters from the original events. These can then be used to trigger further rules, like so (assuming var4 is boolean):
declare AllMoonsInAlignmentEvent
#role (event)
extraCheese : boolean
end
rule "Some Rule"
when
$abc:classABC(var1==1)
$xyz:classXYZ(var2==2)
$lmn:classLMN(var3==3)
$fgh:classFGH($var:var4)
then
... some action using `$var`, `$abc` etc
AllMoonsInAlignmentEvent myEvent= new AllMoonsInAlignmentEvent();
myEvent.extraCheese = $var;
insert(myEvent);
rule "With Extra Cheese"
when
$moonsAligned:AllMoonsInAlignmentEvent(extraCheese == true)
then
...
rule "Without Extra Cheese"
when
$moonsAligned:AllMoonsInAlignmentEvent(extraCheese == false)
then
...
You can get X($y:y) into a spreadsheet in two ways. First, in column 4
X($y:y /*$param*/)
and fill the column with any character you like. The other way might be in column 3 (!)
fgh:classFGH($var:var4) lmn:classLMN
var3==$param
These tricks are always a bit iffy. Rules requiring the simple "grab" of a fact aren't typical for spreadsheets and could be the first indication that you aren't pursuing the best approach.
CONDITION
fgh:classFGH
$param:var4
Comment cell
$var

MS Access Form events, VBA

I have 3 fields in an access form.
Field 1 - is a text field pre-populated with some data. There are no null records
Field 2 - is a text field pre-populated with some data. It can either have a value or be null.
Field 3 - Is a text field. The user will enter information into the field.
There is a rule. If there is a null value in field 2, then field 3 will equal the value from field 1 and so I want it to automatically populate field 3 from field 1. if the value is not null, then the user will populate the field record manually.
I have set up a form load event to:
If Me.field2 = "" Then
Me.field3 = Me.field1
The problem I am having is, the user may want to change the pre-populated value of field 1 and if the corresponding field 2 record is blank, I want field 3 to be updated with the same value the user changed in field 1. I don't want to have to reload the form all the time for this update to occur. I've tried the above syntax in a After_Update event and a change event, but it's not updating.
Can anyone suggest what I am doing wrong?
Thanks,
Mike
another test for empty string or null is
if len(field1 & "")=0 then 'do null stuff
appending an empty string to null or an empty string results in an empty string, which you can then test for length
Mike's already got his answer, but I'll give a fuller answer in the form of an explanation.
The problem here is that you are trying to compare a field that is null to an empty string. It's like you've done
if null = "" then
'do stuff
end if
The problem is when null is used in a comparison, the result is always null - which causes the if to evaluate to false. You can't even do this:
if not(null) then
'do stuff
end if
or
if not (null <> "") then
'do stuff
end if
The conventional solution is to us isnull(x), which evaluates to true if x is null.
As Tim Williams indicate, you can use:
IsNull(x) or x=""
Some might consider the x="" to be redundant if x can only return null for an empty string.
This works too:
if Nz(Field1, "") <> "" then 'do null / empty stuff