I have a task that gathers input from the user using ‘action parameter query’ items. Some of the parameters may be blank and I am not sure how to check for that. If a parameter is blank, that changes how I want to proceed with the rest of my script. For example:
action parameter query "ticket" with description "Ticket number (required): "
action parameter query "username" with description "User name (required): "
action parameter query "prigroup" with description "Primary group (not required): " with default ""
as you can see, prigroup doesn’t have to be provided (by the way, is there a way to force input on the others) and if it isn’t, the rest of my action script changes. For example (how it looks in my head, but doesn’t appear to work):
if { {parameter "prigroup" != ""} }
wait /example/path/to/updateuser.sh -t {parameter "ticket"} -u {parameter "username"} -p {parameter "prigroup"}
else
wait /example/path/to/updateuser.sh -t {parameter "ticket"} -u {parameter "username"}
endif
Any pointers on how to achieve what I’m trying to do? I’ve tried different syntax for the ‘if’ comparison but can’t get it to do what I want.
Hello!
I guess I’m not sure but I thought action parameter query’s had to be used with:
parameter "parametername" of action
and not just:
parameter "parameter name"
I do all my parameter validation at the beginning of my actions with appropriate comments to aid the operator:
// If the action fails here a blank parent was defined
continue if {parameter "parent" of action != ""}
Verbose validation during the taking of the action would require taking parameters in the description using javascript and passing them as a parameter to the function (doing the validation before passing the parameters). You can also do validation with parameterized fixlets but that is likely significantly more complex than what you’re hoping to achieve.
Thanks @strawgate you actually got me pointed in the right direction and now I have what I was working towards.
@strawgate I thought I was on the right track, but after running the action, it errors with the following:
Command failed (Relevance substitution error.) if {parameter "secgroup" of action != ""}
So I changed it to remove ‘of action’ and got the same error (minus the ‘of action’):
Command failed (Relevance substitution error.) if {parameter "secgroup" != ""}
Any other ideas on how to check if an action query parameter is not blank?
Here is the full action script:
action parameter query "fname" with description "First Name (required): "
action parameter query "lname" with description "Last Name (required): "
action parameter query "email" with description "User email address (required): "
action parameter query "ticket" with description "Ticket number (required): "
action parameter query "username" with description "User name (required): "
action parameter query "adminemail" with description "Your email for notifications (required): "
action parameter query "prigroup" with description "Primary group (not required): " with default ""
action parameter query "secgroup" with description "Secondary groups (comma separated, not required): " with default ""
action parameter query "userid" with description "UID (not required): " with default ""
delete "/tmp/useradd.sh"
if {exists file "/usr/sfw/bin/wget"}
wait /usr/sfw/bin/wget http://10.11.12.13/scripts/useradd.sh -O /tmp/useradd.sh
elseif {exists file "/usr/bin/wget"}
wait /usr/bin/wget http://10.11.12.13/scripts/useradd.sh -O /tmp/useradd.sh
else
wait curl -s http://10.11.12.13/scripts/useradd.sh -o /tmp/adduser.sh
endif
wait chmod 755 /tmp/useradd.sh
if {parameter "userid" != ""}
parameter "GoUserId" = "-i {parameter "userid"}"
else
parameter "GoUserId" = ""
endif
if {parameter "prigroup" != ""}
parameter "GoPriGroup" = "-p {parameter "prigroup"}"
else
parameter "GoPriGroup" = ""
endif
if {parameter "secgroup" != ""}
parameter "GoSecGroup" = "-s {parameter "secgroup"}"
else
parameter "GoSecGroup" = ""
endif
wait /tmp/useradd.sh -a {parameter "adminemail"} -f {parameter "fname"} -l {parameter "lname"} -e {parameter "email"} -t {parameter "ticket"} -u {parameter "username"} {parameter "GoUserId"} {parameter "GoPriGroup"} {parameter "GoSecGroup"}
Thanks for any other eyes on this as well.
Hey,
You should use this if you define the parameter in the action
parameter "name"
You should use this if you are using an action parameter query
parameter "name" of action
I performed a small test:
action parameter query "fname" with description "First Name (required): "
action parameter query "lname" with description "Last Name (required): "
if {parameter "fname" of action != ""}
parameter "work"="true"
else
parameter "work"="else"
endif
Leaving the fname parameter blank does not produce a relevance substitution error for me. Can you try again making sure all of the times you’re using an action parameter you type parameter “name” of action?
Can you isolate the steps that produce the error from everything else so it’s easier to try to reproduce?
Bill
So,the issue was on my API code side, I wasn’t sending parameters via post if it was blank. Changing it to send all parameters caused everything to work as intended. Thanks for the eyeballs @strawgate