If/then/else statement in action script is not working

I am trying to use the following if/then/else statement and it is failing. Any insight would be appreciated:

Thanks,
-Mac

if ((exists true whose (if true then (exists (computer name) whose (it as string as lowercase contains “bos” as lowercase)) else false)) AND (exists true whose (if true then (exists (computer name) whose (it as string as lowercase contains “dr” as lowercase)) else false)))

prefetch…

else

prefetch…

endif

In ActionScript you need to enclose the relevance substitution in curly brackets. Try

if {((exists true whose (if true then (exists (computer name) whose (it as string as lowercase contains “bos” as lowercase)) else false)) AND (exists true whose (if true then (exists (computer name) whose (it as string as lowercase contains “dr” as lowercase)) else false)))}

1 Like

Thanks Jason, I tried it and still got the same error. Is there something else you think I can try?

Thanks,
-Mac

What error are you getting?

I wish I had a real error, all I get is:

Invalid action content: the action script contains a syntax error.
This action has been applied 1 time and will not be applied again.

If I take out the IF,THEN,ELSE, the script works. I test the script in the fixlet debugger, it fails if I have the { in , but passed if I don’t. I have tried both ways in my actual action script and they both fail.

Thanks again for your help Jason.

  • Mac

Are you able to provide us the full actionscript (with any sensitive elements removed)?

Hi Aram,

The script is below, I just took out the servername. If we get this right, I would like have a second computer name conditional of “dr”… so, the server name contains “bos” or “dr”.

Thanks for any help.

-Mac

if {((exists true whose (if true then (exists (computer name) whose (it as string as lowercase contains “bos” as lowercase))}

prefetch e1f87e437da42bbd1f873a38adad3a9df4635d28 sha1:e1f87e437da42bbd1f873a38adad3a9df4635d28 size:4772505 http://servername:52311/Uploads/e1f87e437da42bbd1f873a38adad3a9df4635d28/Bos-RubrikBackupService.tmp sha256:3a086307b70d07c9efd6fccb9bc28da4be3bc5c36f1e4c03857fdc1f1a6a7683

extract e1f87e437da42bbd1f873a38adad3a9df4635d28

wait “{pathname of system folder & “\msiexec.exe”}” /i “{(pathname of client folder of current site) & “__Download\RubrikBackupService.msi”}” /qn

Is this the entire script? If so, we’ll also need an endif at least:

if {((exists true whose (if true then (exists (computer name) whose (it as string as lowercase contains "bos" as lowercase))}

prefetch e1f87e437da42bbd1f873a38adad3a9df4635d28 sha1:e1f87e437da42bbd1f873a38adad3a9df4635d28 size:4772505 http://servername:52311/Uploads/e1f87e437da42bbd1f873a38adad3a9df4635d28/Bos-RubrikBackupService.tmp sha256:3a086307b70d07c9efd6fccb9bc28da4be3bc5c36f1e4c03857fdc1f1a6a7683

extract e1f87e437da42bbd1f873a38adad3a9df4635d28

wait "{pathname of system folder & "\msiexec.exe"}" /i "{(pathname of client folder of current site) & "__Download\RubrikBackupService.msi"}" /qn

endif

And for reference: https://developer.bigfix.com/action-script/reference/flow-control/if-elseif-else-endif.html

I added then endif and I still get the same error:

   Invalid action content: the action script contains a syntax error.
   This action has been applied 1 time and will not be applied again.

If I didn’t say it earlier, if I take out the IF command, the actual action script works fine.

I didn’t check it earlier (though I should have), but it appears that the syntax error may be within the relevance defined for the if statement. Let’s try a simplified version:

if {(computer name) as lowercase contains "bos" as lowercase}

prefetch e1f87e437da42bbd1f873a38adad3a9df4635d28 sha1:e1f87e437da42bbd1f873a38adad3a9df4635d28 size:4772505 http://servername:52311/Uploads/e1f87e437da42bbd1f873a38adad3a9df4635d28/Bos-RubrikBackupService.tmp sha256:3a086307b70d07c9efd6fccb9bc28da4be3bc5c36f1e4c03857fdc1f1a6a7683

extract e1f87e437da42bbd1f873a38adad3a9df4635d28

wait "{pathname of system folder & "\msiexec.exe"}" /i "{(pathname of client folder of current site) & "__Download\RubrikBackupService.msi"}" /qn

endif

Doesn’t the prefetch command have to be first, before the IF/ELSE/ELSEIF/ENDIF code block?

2 Likes

Actually, no. You can have a prefetch command within an IF/ENDIF conditional. See the last example here: https://developer.bigfix.com/action-script/reference/download/prefetch.html

However, to your point, I believe these are pre-processed by the Client prior to executing the rest of the actionscript.

Yes, I believe there is an error in the relevance condition. An ‘if’ statement requires both a ‘then’ and ‘else’ clause. This one has no ‘else’. I believe the form you will need is

if {exists true whose(if true then (conditions) else false)}

1 Like

I’m pretty sure I’ve used if statements without a corresponding “else” before. Ran a quick fixlet debugger test which also indicates it executes fine:

BigFixIfElse

1 Like

Yes, for the flow control within actionscript, that’s correct. However, I believe Jason was referring to the conditional within the relevance statement being used in the relevance substitution :slight_smile:

The previous logic was the following:

if {((exists true whose (if true then (exists (computer name) whose (it as string as lowercase contains "bos" as lowercase))}

When we look at the relevance within the curly braces (the substitution), there are at least two issues:

  1. There are unmatched parens
  2. The if statement contains a then but not an else

In such cases, to troubleshoot, it’s useful to evaluate the portion within the curly braces within Fixlet Debugger (particularly the single clause tab, and depending on your preference, with indentation formatting via CTRL-D) to showcase these:

3 Likes