How to compare unknown values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2024 05:42 AM
Using a FD Flow, how can I compare unknown values?
Use Case:
If there are multiple install base items attached to the CI, and all the companies on all the install base items are the Same {
do something
}
If there are multiple install base items attached to the CI, and all the companies on all the install base items are Not the same{
do something different
}
Help is greatly appreciated!
Thank you,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2024 06:14 AM
Hi,
For this you need to create a Custom Script Action and in that you can do a GlideRecord of Install Base table and add your filter and get all your records and do something like below
var ibcompany = '';
var gr = new GlideRecord('install_base_table_name');
gr.addEncodedQuery('your_query');
gr.query();
while(gr.next()){
if(gs.nil(company)){
ibcompany = gr.company(); //this will set the Company value of the first record from the List for the first timwe
}
if(ibcompany == gr.company){ // for the first time this condition will be true and from next time it will compare with the first record compnay from the above step.
continue;
}
else{
break
}
}
Something like above you can try.
Please modify the code according to your need and then execute it.(This is an untested Code).
Please Mark my answer as Correct if this helps you...!!!!!
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2024 11:39 AM - edited ‎04-22-2024 11:44 AM
Thank you. I really appreciate your help.
I think I almost have it now, but its returning a False value when it should return True.
I put this code in a FD Action with a Script Step and I'm returning a true/false value to a Flow
Here is the code I have now, can you please take a look and advise:
(function execute(inputs, outputs) {
var ibRec = inputs.ibRecord;
var match = true;
var ibAcc = '';
var gr = new GlideRecord('sn_install_base_item');
gr.addQuery('configuration_item',ibRec.configuration_item);
gr.query();
while(gr.next()){
if(gr.nil(gr.account)){
ibAcc = gr.account(); //Sets Account value of 1st record from the List for the 1st time
}
if(ibAcc == gr.account){ //For the 1st time this condition will be true & from next time it will compare with the 1st record account from above step
outputs.match = true;
}
else{
outputs.match = false;
}
}
outputs.matchedAcc = match;
})(inputs, outputs);
(see attached)
I really appreciate your help!!
Thank you,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2024 11:58 AM - edited ‎04-22-2024 12:10 PM
Can you share the Outputs of the execution.
Also I see that you are not setting the company value correctly
ibAcc = gr.account();
correct the above line to "ibAcc = gr.account;"
(function execute(inputs, outputs) {
var ibRec = inputs.ibRecord;
var match = true;
var ibAcc = '';
var gr = new GlideRecord('sn_install_base_item');
gr.addQuery('configuration_item',ibRec.configuration_item);
gr.query();
while(gr.next()){
if(gr.nil(gr.account)){
ibAcc = gr.account; //Sets Account value of 1st record from the List for the 1st time
}
if(ibAcc == gr.account){ //For the 1st time this condition will be true & from next time it will compare with the 1st record account from above step
continue;
}
else{
match = false;
break;
}
}
outputs.matchedAcc = match;
})(inputs, outputs);
I think that will fix your issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2024 12:15 PM
Or the Other way of doing is as below
var ibRec = inputs.ibRecord;
var match = true;
var ibAcc = '';
var gr = new GlideRecord('sn_install_base_item');
gr.addQuery('configuration_item', ibRec.configuration_item);
gr.query();
while (gr.next()) {
if (gr.nil(gr.account)) {
ibAcc = gr.account; //Sets Account value of 1st record from the List for the 1st time
}
if (ibAcc != gr.account) {
break;
}
}