Windows CallAPI - How to Tell the Job Submitted Successfully

Discussion created by Harriet_Kim_1764 on Jan 3, 2017
Use Case:
A user wants their Windows CallAPI job to be able to detect if it was submitted successfully or not.

They referenced a JOBS object to be activated, but it does not exist.

Expected:  The CallAPI JOBS fails because the JOBS object being activated does not exist.
Actual: The CallAPI JOBS ends successfully even though the JOBS object being activated does not exist.  This is because it only checks if the use of the callapi was successful.  If it is, therefore, the job ends normally.

Implement a logic condition that verifies if that JOBS object being activated exists or not.

1. Create a callapi script (i.e. test.txt) that has the following:
failed_dummy_name# is a script object that just has a wait 2
and is used to show that the activate_uc_object failed

Contents of the callapi script (i.e. test.txt):
:set &ret# = activate_uc_object('this_does_not_exist',WAIT)
:p &ret#
:IF &ret# = 0
:set &failed_dummy_name# = 'scri.failed'
: set &failed_ret# = activate_uc_object(&failed_dummy_name#,WAIT)

2. Create a dummy object with the same name as the
&failed_dummy_name# variable shows in step 1 (i.e. scri.failed).  It will have
a single line:

3. If you have not already, create a Windows JOBS that calls the callapi:
cd C:\automic\v10\callapi
ucxbxxxc script=test.txt
 @set retcode=%errorlevel%
 @if NOT %ERRORLEVEL% == 0 goto :retcode

4) Copy the Post Process below and put it into the job's post process
from step 3 above:

!This script below will look for the runid from a windows callapi run
!and then based on a dummy script run, will say whether the callapi
!actually failed on an activate_uc_object for an object that did not exist

!get the line from the report where we show the run number
:set &callapi_num# = prep_process_report(,,,'*U3000004*')
!output of this will be just the run number - please note, this is for
!     version 10 and below, version 11 and above need to use "40" instead
!     of "39" due to the extra '0' in U codes
:process &callapi_num#
:  set &callapi_number# = get_process_line(&callapi_num#)
:  set &callapi_number_len# = str_length(&callapi_number#)
:  set &callapi_number_len# = sub(&callapi_number_len#, 39)
:  set &callapi_number# = str_cut(&callapi_number#, 39, &callapi_number_len#)
!your dummy script gets kicked off by the callapi script if the
!     activate_uc_object returned '0' (no object kicked off)
:set &failed_dummy_name# = 'scri.failed'
!get the parent number for the last run id for the dummy script -
!     this is the callapi runid that kicked off the dummy script
:set &failed_parent# = get_statistic_detail(,'PARENT_ACT',&failed_dummy_name#)
!If the failed parent (the callapi that kicked off the dummy script)
!     is the same as the callapi number for THIS object, change the retcode
!     on THIS object to 1
:if &failed_parent# = &callapi_number#
:  p 'the activate_uc_object in the callapi kicked off by this job was trying to kick off an object that does not exist!'
:  modify_state retcode='1'