Order of commands within an action

This may seem like a very straight forward question but I’m unable to locate anything in the documentation that answers the question.

Do actions run from line 1 to line x in order?

I ask as I have created a task whos first job is to create folders however rather than create the folders it seems to look down the rest of that action and see that the folders aren’t there (later checks) and throw a wobbler over relevance substitution errors.

I know this is a problem because if I remove the data after creating the folders and execute it then the action works as planned and the folders are created.

If I then add the rest of the data I removed and run the action as a whole, it runs without problem and doesn’t throw any more errors now that the folders are there.

Yes…and no. You’re hitting a particularly troublesome edge case.

When the action is running, the lines are executed in order. But, before the action starts executing, all of the relevance substitutions are evaluated to check for downloads. If any of them throw an error (like a singular expression for a folder that doesn’t exist yet), the action won’t start.

You can avoid that by using a prefetch block (only the prefetch block is evaluated before the action starts), or by using plural relevance, or by trapping the substitution errors with pipe operators ( | ), or with if/then/else clauses.

I usually find it easiest to use prefetch blocks. I’ll try to give some examples for the other methods later.

1 Like

Mostly troublesome because you can test in the debugger and all works as expected, line by line, only to collapse in a heap when deployed as a fixlet.

Don’t ask how I know this…

Especially don’t ask which technique I use to remind myself of this quirk…

1 Like

I’m really struggling with it :frowning:

I’ve got pressure being put on internally to get it working before Thursday and right now it’s causing me hours of headaches trying to move parts around.

I wish there was a way of saying:

Do this before even thinking about the rest of the script then when that’s done you can do what you like.

I’m gonna submit an idea to add this - I’m sure this has caused headaches for a lot of people over time.

Is adding a prefetch block an option? Or do you need to request different downloads based on calculations later?

Having a prefetch block sort of does that, but I’m not actually sure whether that was intentional or a side-effect.

I don’t think the prefetch block will work as it needs to download a .tmp (zip) file which has 2 folders in it and they have multiple items in there

I think a prefetch would work for this - as long as you don’t have to trigger another download later based on the contents of this download or something like that.

1 Like

Found this prior post from @JasonWalker and others that might help:

2 Likes

Not sure if this helps you John, but I have an old (Bigfix 8.1 level) pdf document that explains ‘not active of action’ that I can’t find on developer.bigfix.com.

Cut & Paste from the document (apologies, the formatting may be a little awry):

For instance, an Action may create and access a file that doesn’t yet exist in the prefetch phase:

wait chkntfs c: > c:\output.txt
if {line 2 of file "c:\output.txt" as lowercase contains "not dirty"}
regset "HKLM\Software\MyCompany\" "Last NTFS Check"="OK"
else
regset "HKLM\Software\MyCompany\" "Last NTFS Check"="FAIL"
endif

In this Windows example, the output file doesn’t exist until the script is actually executed. The prefetch parser will notice that the file doesn’t exist when it checks for its contents. It will then throw an error and terminate the Action. However, you can adjust the if-condition to allow the prefetch pass to succeed. One technique is to use the “not active of action” expression which always returns TRUE during the prefetch pass. You can use this to avoid the problematic block during the pre-parse:

wait chkntfs c: > c:\output.txt
if {not active of action OR (line 2 of file "c:\output.txt" as lowercase contains "not dirty")}
regset "HKLM\Software\MyCompany\" "Last NTFS Check"="OK"
else
regset "HKLM\Software\MyCompany\" "Last NTFS Check"="FAIL"
endif

By checking first to see whether the Action is being pre-parsed or executed, you get a successful prefetch pass and the desired behavior when the action is running.

Correction:
I have found this documented: https://developer.bigfix.com/action-script/reference/flow-control/if-elseif-else-endif.html

6 Likes

Love this! Active of Action

https://developer.bigfix.com/relevance/reference/action.html

2 Likes

Huge thanks guys, Jason helped me get this fixed but I was out of the office for a week at short notice so didn’t get a chance to reply.

The prefetch block worked an absolute treat :smiley:

3 Likes

“Active of Action” just saved my bacon! Fortunately I remembered reading this thread and was able to skip over a file that didn’t yet exist.

2 Likes

OK, I know I’m a bit late to the party, but could this simplify the code to resolve @FatScottishGuy’s problem?

Use a Baseline, and have a component (BigFix Task) create the folders needed. (If needed, have that component record the names of the folders created (in a file) for use in the next component of the baseline)

Then, have the next component go on and do what is needed? (Pulling folder names from the file used for that purpose, and then clean up that file when done)

Or… am I missing something?

Part of the relevance for the 2nd component could be checking for the presence of the file containing folder names, and the folder names would get stored toward the end of the first component, so the folder should be there.

Thanks,
Bob_K