Service Desk Practitioners Forum

Command Exec Action - Problem with batch file parameters!

Go to solution
Valued Contributor.

Command Exec Action - Problem with batch file parameters!


I created a script in PHP that executes via “Command Exec Action” that will email the history lines of a given case to a customer when a service call is updated or created, etc...The scripts is called from a batch file and works fine providing all of the parameters ("[ID]" "[Entered by person]" "[Caller]" "[Description Code]" "[Organization]" "[Priority]" "[Status]" "[Assignment;To person]" "[Assignment;To person;E-mail]" "[Caller;E-mail]" "[CC List]") are passed to the batch file. The batch file handles parameters with white spaces, and I can access more 10 parameters with the help of “shift”.

However, if a particular parameter is not passed to the batch file, or if no parameters are passed, the batch file will error out causing the script NOT to be executed with error: “set was unexpected at this time”. The batch file is expecting all 11 parameters to be passed.

Test 1 (works as expected)

C:\>test.bat "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" " "
"1" "2" "3" "4" "5" "6" "7" "8" "9" "10" N/A

Test 2 (produces error: set was unexpected at this time as parameters 11 is not passed to batch file, need to fix this)

C:\>test.bat "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"
set was unexpected at this time.

I need help modifying my batch file so that if it doesn’t receive a parameter from the “Command Exec Action” it will assign a N/A to the %variable within the batch file which will in turn keep all attributes in the correct position for the PHP script. I guess I could force the “Command Exec Action” to pass a parameter using a Service Desk template, but I would rather fix the problem within the batch file. Any suggestions or ideas are welcome at this point…

Below is the batch file:

@echo off
@REM ---- Begin of parameter list----
@REM itsm_history_lines.bat script
@REM %1 is assigned “id”
@REM %2 is assigned “entered_by”
@REM %3 is assigned “caller”
@REM %4 is assigned “description”
@REM %5 is assigned “organization”
@REM %6 is assigned “priority”
@REM %7 is assigned “status”
@REM %8 is assigned “assigned_to”
@REM %9 is assigned “assignment_to_person_email”
@REM %10 is assigned “caller_email”
@REM %11 is assigned “cc_list”
@REM --- End of parameter list ----
set p1=%1
IF %p1% == " " set p1=0
set p2=%2
IF %p2% == " " set p2=N/A
set p3=%3
IF %p3% == " " set p3=N/A
set p4=%4
IF %p4% == " " set p4=N/A
set p5=%5
IF %p5% == " " set p5=N/A
set p6=%6
IF %p6% == " " set p6=N/A
set p7=%7
IF %p7% == " " set p7=N/A
set p8=%8
IF %p8% == " " set p8=N/A
set p9=%9
IF %p9% == " " set p9=N/A
set p10=%9
IF %p10% == " " set p10=N/A
set p11=%9
IF %p11% == " " set p11=N/A
@echo %p1% %p2% %p3% %p4% %p5% %p6% %p7% %p8% %p9% %p10% %p11%

@REM C:\php\cli\php.exe -f C:\itsm_history_lines_created.php %p1% %p2% %p3% %p4% %p5% %p6% %p7% %p8% %p9% %p10% %p11%

Thank you.
Saurabh Dubey
Acclaimed Contributor.

Re: Command Exec Action - Problem with batch file parameters!

Hi Roger,

I have two suggestions for you.

1. Pertaining to the batch file - Try to put the N/A as NA instead since the / can be taken as a special character. Or try to put the same values in double quotes. ("N/A" or "NA").

2. Pertaining to your requirement - You can do what we have done. Add a history Notes Diary field, which keeps getting updated by the updates made by the engineer, and then the field is sent as a single entity in the mail, without having to attend to the parsing of the text. Although your requirements may be beyond the scope which I can think, I still thought I'd make a simpler suggestion.



PS: Can you please chare the php file as well? I would like to see if that turns out to be a better solution for a lot of our general problems. :-)
Modesty is good!! But remember, all your life other people will try and take your achievements away from you, don't make it easy for them.
Valued Contributor.

Re: Command Exec Action - Problem with batch file parameters!


To resolve this issue I executed the script directly without the aid of a batch file, and passed a single parameter from SD containing all of the required attributes:

Command line:
cmd /c php.exe -f C:\itsm_history_lines.php >> C:\itsm_history_lines.log 2>&1


"[ID]#[Enteredbyperson]#[Caller]#[DescriptionCode]#[Organization]#[Priority]#[Status]#[Assignment;To person]#[Assignment;To person;E-mail]#[Caller;E-mail]#[CC List]"

An example of the PHP script is attached; let me know if you have any questions. I apologize for taking so long to respond back.

Thank you to those who provided feedback!