Skip to main content

AlteryxEngine API Example

The AlteryxEngine API is a collection of methods and callbacks that allow you to call into the AlteryxEngine. This code is a sample usage of the AlteryxEngine API.

const int STATUS_Info = 1;
const int STATUS_Warning = 2;
const int STATUS_Error = 3; 
const int STATUS_FieldConversionError = 5;
const int STATUS_File_Input = 8; 
const int STATUS_File_Output = 9; 
const int STATUS_Flag_Transient = 0x40000000;  // in combination with Info, Warning or FieldConversionError

// Example RuntimeData struct
struct RuntimeData
{
   int nWarnings;
   int nFieldConversionErrors;
   int nErrors;
   std::wofstream logFile;
   RuntimeData()
        : nWarnings(0)
        , nFieldConversionErrors(0)
        , nErrors(0)
   {
   }
};


long _stdcall ProgressMessage(__int64 userData, int nToolID, double dPercentProgress)
{
   // See TCallbackToolProgress for actions you can accomplish here....
   return 0;
}

long _stdcall CallbackMessage(__int64 userData, int nToolID, int nStatus, const wchar_t *pMessage)
{
   // See callback documentation for what you can do when you define your own callback message
   switch (nStatus & ~STATUS_Flag_Transient)
   {
   case STATUS_Info:
   case STATUS_File_Input:
   case STATUS_File_Output:
        break;
   case STATUS_Warning:
     reinterpret_cast<RuntimeData *>(userData)->nWarnings++;
     reinterpret_cast<RuntimeData *>(userData)->logFile << L"Warning - ";
        break;
   case STATUS_Error:
   reinterpret_cast<RuntimeData *>(userData)->nErrors++;
   reinterpret_cast<RuntimeData *>(userData)->logFile << L"Error - ";
        break;
   case STATUS_FieldConversionError:
     reinterpret_cast<RuntimeData *>(userData)->nFieldConversionErrors++;
     reinterpret_cast<RuntimeData *>(userData)->logFile << L"FieldConversionError - ";
        break;
   default:
        return 0;
   }

   if (nToolID<0)
     reinterpret_cast<RuntimeData *>(userData)->logFile << L"Alteryx Engine";
   else
     reinterpret_cast<RuntimeData *>(userData)->logFile << L"ToolId " << nToolID;
     reinterpret_cast<RuntimeData *>(userData)->logFile << L": " << pMessage << L"\n";
     return 0;
}
//      Later in your API code...
{
   RuntimeData runtimeData;

   AlteryxRunModule2(L"<workflowPath>", L"",
        ProgressMessage, CallbackMessage,
        reinterpret_cast<__int64>(&runtimeData));
}