Skip to content
+1-888-319-3663

COMMUNITY FORUM

Global variable usage help

Mike asked 10 years ago
I have created a couple Global Variables (GBL_HeaderID & GBL_IMPORT_ERROR_STATUS).  In the map pre I created a SQL task that gets a value and returns it to GBL_HeaderID.  When I reference the GBL_HeaderID in the field mapping, it always has a value yet when I reference the same global value in the pre-map sequence step 2 SQL command, it is empty. 


———————————————————————————————- 
The Pre map sequence 1 is as follows:
–Update Global Variable with SQL command result = TRUE
–Variable Name GBL_HeaderID
 
Declare @ImportID varchar(20) = ''
exec Receipt_ReserveHeader @ImportID OUTPUT
Select @ImportID


———————————————————————————————-
The Pre-Map sequence 2 is as follows:
–Update Global Variable with SQL command result = FALSE


declare @MAPID varchar(20),@RunNumber int, @Error varchar(50)
select @MAPID = 'GlobalMapID', @RunNumber = GlobalRunNumber,
                @Error = 'Receipt Header ID: GBL_HEADERID Created'
exec SmartConnect_RecordMapExecuteStatus @MAPID, @RunNumber, @Error


———————————————————————————————-
In the MAP Post Success task sequence 1 (SQL Command) where I have the Update global variable with SQL command result = true.  The script is as follows:
–Update Global Variable with SQL command result = TRUE
–Variable Name GBL_IMPORT_ERROR_STATUS

Declare @ImportID varchar(20), @Status varchar(50)
Select @ImportID =  GBL_HEADERID
exec Receipt_UpdateStatus @ImportID, @Status  OUT
select  @Status


———————————————————————————————-
In Sequence 2, I call another proc and pass the GBL_IMPORT_ERROR_STATUS variable but the variable is always empty.  Script looks like this:
–Update Global Variable with SQL command result = FALSE


declare @MAPID varchar(50),@RunNumber int, @Error varchar(50)
select @MAPID = 'GlobalMapID', @RunNumber = GlobalRunNumber,
                @Error = 'GBL_IMPORT_ERROR_STATUS'
exec SmartConnect_RecordMapExecuteStatus @MAPID, @RunNumber, @Error
 
Answers
Best Answer
Chris Hanson answered 10 years ago
SQL tasks currently compile everything in each task level before sending it through. That means it is swapping out any variables for both those tasks at the same time so your variable does not have a value yet.

If youwere able to combine the commands into one task you wouldn't run into that issue, or if you needed to have them run separate and reutrn variables you could recreate the tasks both as scripting tasks. In the scripting tasks you could open the same connections to sql and run the commands you need. Scripts alwyas run sequentially so anythign set in one will be used in the next.

H

If you would like to submit an answer or comment, please sign in to the eOne portal.