Script failed with !=0 exit code

you can use if {true} and if {false} to test those branches

No luck

// create auto close incident via snow.bat
download http://server:52311/Uploads/stage/curl/curl.bfswd
extract “curl.bfswd” “{name of drive of windows folder}\temp\curl”

//checking c:\temp exists
if { not exists folder “c:\temp”}
folder create "c:\temp"
endif

prefetch e4ce8622391558f88271a3fb9a78061fc414eb7b sha1:e4ce8622391558f88271a3fb9a78061fc414eb7b size:31118 http://server:52311/Uploads/e4ce8622391558f88271a3fb9a78061fc414eb7b/SetDefaultBrowser.exe.tmp sha256:cff98bc01881ce34e08841c7661ef89c5bb723f24c6900cafc8675ec902e0a46
extract e4ce8622391558f88271a3fb9a78061fc414eb7b "c:\temp"
waithidden cmd.exe /C cacls.exe c:\temp\SetDefaultBrowser.exe /E /G Everyone:R

override wait
hidden=true
completion=job
RunAs=currentuser
wait c:\temp\SetDefaultBrowser1.exe HKLM “Google Chrome”

//given SetDefaultBrowser1.exe wrong name to test else part

parameter “error”="{exists action whose (exit code of it = 0)}"
if {true}

//if {exists action whose (exit code of it = 0)}
// Do not exit the action, leave it with Success

delete __createfile
delete c:\temp\snow.bat

createfile until eof
cd c:\temp\curl
curl -v -H “Accept: application/json” -H “Content-Type: application/json” -H “Authorization: Basic passwd==” -X POST --data “{{ ‘caller_id’: ‘{concatenation " " of tuple string items (integers in (length of it,0)) of (it as string) of ((full name of it) of user of logged on user whose (active of it = True))}’,‘assignment_group’: ‘Healing -GRP’,‘category’:‘End User Asset’,‘subcategory’:‘Desktop’,‘short_description’:‘Fix - Re-enable the SmartView Office - Action Completed - {name of logged on user whose (active of it = True)}’,‘description’:‘Fix - Re-enable the SmartView Office plugin’}” “https://service-now.com/api/now/table/incident” -o c:\temp\inc.txt
eof
move __createfile c:\temp\snow.bat

override wait
hidden=true
completion=job
RunAs=currentuser
wait c:\temp\snow.bat

else

// Terminate action and mark Failed

delete __createfile
delete c:\temp\snow.bat

createfile until eof
cd c:\temp\curl
curl -v -H “Accept: application/json” -H “Content-Type: application/json” -H “Authorization: Basic passwd==” -X POST --data “{{ ‘caller_id’: ‘{concatenation " " of tuple string items (integers in (length of it,0)) of (it as string) of ((full name of it) of user of logged on user whose (active of it = True))}’,‘assignment_group’: ‘Healing -GRP’,‘category’:‘End User Asset’,‘subcategory’:‘Desktop’,‘short_description’:‘Fix - Re-enable the SmartView Office - Action Failed - {name of logged on user whose (active of it = True)}’,‘description’:‘Fix - Re-enable the SmartView Office plugin’}” “https://service-now.com/api/now/table/incident” -o c:\temp\inc.txt
eof
move __createfile c:\temp\snow.bat

override wait
hidden=true
completion=job
RunAs=currentuser
wait c:\temp\snow.bat
exit {exit code of action}
endif

It seems you are trying to integrate a direct post of action result using curl in the action script as a sort of integration with ServiceNow.

1 the {} inside of your curl post look like they might need some additional escaping.

2 the fail side of will only be reached if nothing in the action had a fatal error. So this test will not result in a Failed posting, because this line stops the action right away with the thread execution failure.

1 Like

Ok got it…

1 Like