Set Flow Variable Script to Return TRUE if Master Image conditions are met for a computer

Jordan Humphrey
Giga Expert

Hello,

 

I am having some trouble figuring out why the following logic is returning TRUE when the following conditions exist:

 

deviceModel = Notebook

DNSDomain = "WORKGROUP"

reqType = "Re-Install Computer"

shared = "Personal Device"

 

My expectation is to return FALSE in this case because I only want to return TRUE when:

1. DNSDomain is NOT "WORKGROUP" AND reqType = "Re-Install Computer"

2. Shared = "Shared Device"

3. deviceModel = "Desktop"

 

Am I missing something?

 

var dnsdomain = fd_data._1__get_catalog_variables.PC_Name.dns_domain;
var shared = fd_data._1__get_catalog_variables.Shared_Device;
var reqType = fd_data._1__get_catalog_variables.Requested_Action;
var deviceModel = fd_data._1__get_catalog_variables.PC_Name.model_id.type;

gs.info('[TRANSFER COMPUTER] Request Type value: ' + reqType);
gs.info('[TRANSFER COMPUTER] DNS Domain found: ' + dnsdomain);
gs.info('[TRANSFER COMPUTER] Shared Device value: ' + shared);
gs.info('[TRANSFER COMPUTER] Device Model value: ' + deviceModel);

// Logic: Return true if (dnsdomain is NOT "WORKGROUP") OR (shared is "Shared Device") OR (deviceModel is "Desktop")
if ((reqType === "Re-Install Computer" && dnsdomain !== "WORKGROUP") || (shared === "Shared Device") || (deviceModel === "Desktop")) {
    return true;
} 
else {
    return false;
}

 

1 ACCEPTED SOLUTION

Jordan Humphrey
Giga Expert

I think I figured out the issue, which is REALLY weird... When using fd_data to pull the flow data into the script, some things you'd think would be String text aren't actually coming into the variable as such. My workaround is to use toString() on the var's that need to be strings before the logic picks them up. I have NO CLUE why it's suddenly doing this.

View solution in original post

3 REPLIES 3

Voona Rohila
Mega Patron
Mega Patron

Hi @Jordan Humphrey 

Looks good, Are the values showing properly in logs?

 

Maybe try validating by converting to either lowercase or uppercase so that there is no mismatch.

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Sanjay Bagri1
Tera Guru

Hello @Jordan Humphrey ,

 

Please could you try to add && Condition because i tried and its working because if you are adding || condition after first block so its taking second value as true that's why returning true. 

 

Check the If condition I changed. 

 

var dnsdomain = "WORKGROUP";
var shared = "Shared Device";
var reqType = "Re-Install Computer";
var deviceModel = "Desktop";

// gs.info('[TRANSFER COMPUTER] Request Type value: ' + reqType);
// gs.info('[TRANSFER COMPUTER] DNS Domain found: ' + dnsdomain);
// gs.info('[TRANSFER COMPUTER] Shared Device value: ' + shared);
// gs.info('[TRANSFER COMPUTER] Device Model value: ' + deviceModel);

// Logic: Return true if (dnsdomain is NOT "WORKGROUP") OR (shared is "Shared Device") OR (deviceModel is "Desktop")
 if ((reqType === "Re-Install Computer" && dnsdomain !== "WORKGROUP") && (shared === "Shared Device") && (deviceModel === "Desktop")) {   
gs.print("Return : true");
} 
else {
      gs.print("Return : False");
}

 

 

Please mark my response correct and helpful if response resolves your query.

Thanks

Sanjay Bagri

Jordan Humphrey
Giga Expert

I think I figured out the issue, which is REALLY weird... When using fd_data to pull the flow data into the script, some things you'd think would be String text aren't actually coming into the variable as such. My workaround is to use toString() on the var's that need to be strings before the logic picks them up. I have NO CLUE why it's suddenly doing this.