Question

Accessing FME_MacroValues['FME_JOB_ID']

  • 31 March 2017
  • 5 replies
  • 16 views

I'm trying to figure out how to access the FME_MacroValues['FME_JOB_ID'] system parameter. 

 

I'm trying to link this script to a writers destination. Basically want to include the job ID in the file name of the output. I've attempted this using the code below but am getting the error shown in this log:

Starting translation...

INCLUDE -- failed to evaluate Python script `def ParamFunc():
  import fme

  return '\\\\ServerLocation\\logging\\failed_logs\\' + 'failed_load_' + FME_MacroValues['FME_JOB_ID'] + '.xlsx'
value = ParamFunc()
macroName = 'DestDataset_XLSXW2'
if value == None:
  return { macroName : '' }
else:
  return { macroName : str(value) }
'
Program Terminating

Translation FAILED.

Traceback (most recent call last):
  File "<string>", line 5, in MF_Include_1490921734471
  File "<string>", line 4, in ParamFunc
KeyError: 'FME_JOB_ID'

This is the python code:

import fme

return '\\ServerLocation\\logging\\failed_logs\\' + 'failed_load_' + FME_MacroValues['FME_JOB_ID'] + '.xlsx'

5 replies

Badge +16

why not use the rest API to query for all failed jobs?

why not use the rest API to query for all failed jobs?

The job doesn't actually fail but instead the it is successful. The output file I'm trying to name are records which were not written to the database.

 

 

For the user, any records which were not written are errors and need to be sent back to them as a load error list to review and fix.

 

 

I've got a solution to the initial problem which was to create a unique ID and pass that to the FME job to use so the client can still find the correct file. It's not the job ID but it's something.

 

 

I'd still like an answer to this one though.

 

 

Badge +16
The job doesn't actually fail but instead the it is successful. The output file I'm trying to name are records which were not written to the database.

 

 

For the user, any records which were not written are errors and need to be sent back to them as a load error list to review and fix.

 

 

I've got a solution to the initial problem which was to create a unique ID and pass that to the FME job to use so the client can still find the correct file. It's not the job ID but it's something.

 

 

I'd still like an answer to this one though.

 

 

Why not use a fan out containing the FME_JOB_ID parameter?

 

works just fine.

 

 

Userlevel 4

The error message indicates that FME_JOB_ID hasn't been inserted into the FME_MacroValues dictionary yet.  Are you running your workspace from FME Desktop or Server when this happens? If it's from the Desktop, it's as expected as there is no job id.

To avoid having the workspace crash when running from Desktop, you can tell the dictionary to return a default value if the key doesn't exist, like this:

FME_MacroValues.get('FME_JOB_ID', '0')

This way you'll get the default value '0' rather than an exception if FME_JOB_ID doesn't exist.

Userlevel 2
Badge +17

Hi @mattdoa2, if you just need to create a file path containing the job ID as a user parameter, I think you can define it as a Text type or Filename type parameter whose default value is a string expression referring to the FME_JOB_ID parameter, rather than a scripted parameter. The expression looks like this.

\\ServerLocation\logging\failed_logs\failed_load_$(FME_JOB_ID).xlsx

$(FME_JOB_ID) will be the empty string if you run the workspace with FME Desktop.
I've not tested it with FME Server. Please check it yourself how it works with FME Server.

Reply