Help with IF statement

hi guys,
I need your help please.
I’m trying to write some action that queries registry branch and looking for couple of keys with partial name.
the occurrences of these keys can be with “1 or 2 or 3” / “(1 and 2) or 3” / “1 or (2 and 3)” etc.
so I’ve decided to use the if statement on each reg key.

the issue is on the 2nd IF statement that I get errors on it.
please see my action code:

parameter "oracleHomeRegData" = "\\\\network\\admin\\myFile.txt"
parameter "oraRegKeyPath" = "HKEY_LOCAL_MACHINE\SOFTWARE\myKey\"
parameter "regHome0" = "home0"
parameter "regHome1" = "home1"

action uses wow64 redirection false
delete __createfile
delete reg1.reg
delete reg2.reg

if{((exists it whose (name of it as lowercase contains (parameter "regHome0")) of (it;keys of it; keys of keys of it; keys of keys of keys of it) of key (parameter "oraRegKeyPath") of native registry))}
	parameter "regKeyName" = "{ ((name of key whose (name of it as lowercase contains (parameter "regHome0")) of (it;keys of it; keys of keys of it; keys of keys of keys of it) of key (parameter "oraRegKeyPath") of native registry)) }"
	createfile until _END_
	Windows Registry Editor Version 5.00

	[{parameter "oraRegKeyPath"}{parameter "regKeyName"}]
	"ORACLE_HOME"="{parameter "oracleHomeRegData"}"
	_END_
	move __createfile reg1.reg
	waithidden regedit /s "reg1.reg"
endif
if{((exists it whose (name of it as lowercase contains (parameter "regHome1")) of (it;keys of it; keys of keys of it; keys of keys of keys of it) of key (parameter "oraRegKeyPath") of native registry))}
	parameter "regKeyName" = "{ ((name of key whose (name of it as lowercase contains (parameter "regHome1")) of (it;keys of it; keys of keys of it; keys of keys of keys of it) of key (parameter "oraRegKeyPath") of native registry)) }"
	createfile until _END_
	Windows Registry Editor Version 5.00

	[{parameter "oraRegKeyPath"}{parameter "regKeyName"}]
	"ORACLE_HOME"="{parameter "oracleHomeRegData"}"
	_END_
	move __createfile reg2.reg
	waithidden regedit /s "reg2.reg"
endif

error


I’m attaching also screenshots for output, error and ClientLog of this action

please show me where am I wrong.

thank you

Once set, a parameter cannot be set to another value.
Where you have multiple sections that set parameter “regKeyName” just update the code so one section uses “regKeyName1”, then next “regKeyName2” etc.

1 Like

hi,
just tried it, and you are right. thank you.

but I have there another issue.
as I have multiple reg keys, couple of them might be with same partial name, example: “key_frhome1”, “home1”

both of these keys are with same partial name. seems like it won’t work while it’s the case.

please see the code:

parameter "oracleHomeRegData" = "\\\\network\\admin\\myFile.txt"
parameter "oraRegKeyPath" = "HKEY_LOCAL_MACHINE\SOFTWARE\myKey\"
parameter "regHome0" = "home0"
parameter "regHome1" = "home1"
parameter "regKeyFrHome1" = "key_frhome1"

action uses wow64 redirection false
delete __createfile
delete reg1.reg
delete __createfile
delete reg2.reg
delete __createfile
delete reg3.reg

if{((exists it whose (name of it as lowercase contains (parameter "regHome0")) of (it;keys of it; keys of keys of it; keys of keys of keys of it) of key (parameter "oraRegKeyPath") of native registry))}
	parameter "regKeyName1" = "{ ((name of key whose (name of it as lowercase contains (parameter "regHome0")) of (it;keys of it; keys of keys of it; keys of keys of keys of it) of key (parameter "oraRegKeyPath") of native registry)) }"
	createfile until _END_
	Windows Registry Editor Version 5.00

	[{parameter "oraRegKeyPath"}{parameter "regKeyName1"}]
	"ORACLE_HOME"="{parameter "oracleHomeRegData"}"
	_END_
	move __createfile reg1.reg
	waithidden regedit /s "reg1.reg"
endif
if{((exists it whose (name of it as lowercase contains (parameter "regHome1")) of (it;keys of it; keys of keys of it; keys of keys of keys of it) of key (parameter "oraRegKeyPath") of native registry))}
	parameter "regKeyName2" = "{ ((name of key whose (name of it as lowercase contains (parameter "regHome1")) of (it;keys of it; keys of keys of it; keys of keys of keys of it) of key (parameter "oraRegKeyPath") of native registry)) }"
	createfile until _END_
	Windows Registry Editor Version 5.00

	[{parameter "oraRegKeyPath"}{parameter "regKeyName2"}]
	"ORACLE_HOME"="{parameter "oracleHomeRegData"}"
	_END_
	move __createfile reg2.reg
	waithidden regedit /s "reg2.reg"
endif
if{((exists it whose (name of it as lowercase contains (parameter "regKeyFrHome1")) of (it;keys of it; keys of keys of it; keys of keys of keys of it) of key (parameter "oraRegKeyPath") of native registry))}
	parameter "regKeyName3" = "{ ((name of key whose (name of it as lowercase contains (parameter "regKeyFrHome1")) of (it;keys of it; keys of keys of it; keys of keys of keys of it) of key (parameter "oraRegKeyPath") of native registry)) }"
	createfile until _END_
	Windows Registry Editor Version 5.00

	[{parameter "oraRegKeyPath"}{parameter "regKeyName3"}]
	"ORACLE_HOME"="{parameter "oracleHomeRegData"}"
	_END_
	move __createfile reg3.reg
	waithidden regedit /s "reg3.reg"
endif

the error I get is:
Command failed (Relevance clauses must be surrounded by { and } guards.) parameter “regKeyName2” = “{ ((name of key whose (name of it as lowercase contains (parameter “regHome1”)) of (it;keys of it; keys of keys of it; keys of keys of keys of it) of key (parameter “oraRegKeyPath”) of native registry)) }”

but once I rename one of the keys, and adjust the code with their new names, it works.

is there a way to overcome it?

I suspect that if you test

((name of key whose (name of it as lowercase contains (parameter “regHome1”)) of (it;keys of it; keys of keys of it; keys of keys of keys of it) of key (parameter “oraRegKeyPath”) of native registry))

in the fixlet debugger it will return multiple values.

That works OK in an analysis, but a parameter can only contain a single value

I didn’t say that at all.

I said that a parameter can only hold a single value. Relevance can return multiple values, but if you try to put multiple values into a parameter it will fail.

See the reference page: https://developer.bigfix.com/action-script/reference/flow-control/parameter.html

If there is any error in evaluating the relevance expression to create the parameter, then the parameter will not be set. If the relevance expression results in multiple values then, then the command fails.

Ok,
but I did not use the same parameter for multiple values.
or maybe I miss something here?
can you please point me on the parameter that repeats it self with different values?

I believe what @trn is saying is that you can have this error if a single relevance expression returns two or more results, for example if you had two registry keys with that oraRegKeyPath in the key name.

There are also simpler things that could be causing the error. Check for Smart Quotes - where your browser, Word, or wherever else you are copying the code is replacing "quotes". If you paste into the QNA tab the should show up with red highlighting.

1 Like

+1 for smart quotes.
copy/paste issues between office products with autocorrect. I turn off the hyphen to emdash and endash. also disable the quotes to smart quotes. problem is the substitutions look the same or very similar, depending where you paste them, but wreak havok on scripts…