Action Parameters and Substitution in an Action

(imported topic written by Tim.Rice)

I am writing a Fixlet and trying to use the Parameter command. I can create the Parameter just fine, and use it for basic substitutions. Where I’m running into a problem is when I try to make use of it ‘inside’ another substitution, as follows …

Consider the following …

if {x64 of Operating System}
Parameter “Path” = "C:\Program Files (x86)"
else
Parameter “Path” = "C:\Program Files"
endif

further down the action script I want to make use of the original PATH parameter to check if a sub-folder exists …

if {exists folder ({parameter “Path”} & “\SomeSub1”)}
{do some things here under SomeSub1}
endif

if {exists folder ({parameter “Path”} & “\SomeSub2”)}
{do somethings here under SomeSub2}
endif

I can’t get the substitution to work, so I’ve had to resort to nested IF/ELSE/ENDIF statements, and I’d rather avoid them when possible, for readability.

Is there a way to do this without nesting IF/ELSE/ENDIF statements?

(imported comment written by SergioBenavides)

The below lines work ( notice the concatenation )

if {x64 of Operating System}

parameter “Path” = “C:\Program Files (x86)”

else

parameter “Path” = “C:\Program Files”

endif

if {exists file (parameter “Path”& “\fake\fake.txt”)}

run ping www.google.com

endif

Hi all,

Not sure how closely related to the topic this will be, but I’m wanting to use IF THEN ELSE on the command, is that possible (and relatively straightforward)? If so, how would I make the following work?

parameter "ComponentsFactoriesFile" = "<pathname>"
delete {parameter "ComponentsFactoriesFile" of action}

parameter "ExportsFactoriesFile" = "<pathname>"
delete {parameter "ExportsFactoriesFile" of action}

if {exists file "<pathname>"}
then
createfile until DDDDDD
<Exports>
        <content>
</Exports>
DDDDDD

copy __createfile {parameter "ComponentsFactoriesFile" of action}

else
createfile until DDDDDD
<Exports>      
  <content>      
</Exports>
DDDDDD

copy __createfile {parameter "ExportsFactoriesFile" of action}

-Many thanks

Almost how you had it…

If {exists file (parameter "ComponentsFactoriesFile")}
// do something
else
// do something else
endif

Thank you!

:pray:

Is there an easy explanation regarding why THEN is not necessary in action script?

Sure (easy for me, anyway): https://developer.bigfix.com/action-script/reference/flow-control/if-elseif-else-endif.html

I can see the confusion, in Relevance language ‘then’ is required, but not in ActionScript language.

1 Like

You’re comment actually helped more (they aren’t the same language), thanks!