Issue with Extensibility Rule in C# using FdxExecuteDataUnit
We are working on a POC to extract data using FdxExecuteDataUnit. We are using an Extensibility business rule and running it using a DM job. I am getting assistance from our corporate IT group as I am not good with C#. The business rule is writing data to a table and then is taking the data from the table and putting it in a text file. There is something missing or wrong with this and I am hoping someone can help with the code since I do not have access to the TechTalks that focus on FdxExecute.
The code was written to do the FdxExecuteDataUnit and then also write some sample data to the table. This way if the FdxExecute does not generate any data we at least get a file with the sample data. I am getting a file but it only has the sample data spelled out in lines 100-150 of the business rule. I am also getting the following warning when I compile the rule:
"1) Warning at line 54: Unreachable code detected"
If I comment out that line (54) and put the cubeview name directly in the FdxExecuteDataUnit statement then I get the same warning but for line 55.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Globalization;
using System.IO;
using System.Linq;
using Microsoft.CSharp;
using OneStream.Finance.Database;
using OneStream.Finance.Engine;
using OneStream.Shared.Common;
using OneStream.Shared.Database;
using OneStream.Shared.Engine;
using OneStream.Shared.Wcf;
using OneStream.Stage.Database;
using OneStream.Stage.Engine;
namespace OneStream.BusinessRule.Extender.TEST_FDX_Csharp
{
public class MainClass
{
public object Main(SessionInfo si, BRGlobals globals, object api, ExtenderArgs args)
{
try
{
DataTable employeeData = CreateSampleData();
AppServerConfigSettings configSettings = AppServerConfig.GetSettings(si);
string folderPath = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, true, configSettings.FileShareRootFolder, si.AppToken.AppName) + "\\" + DateTime.UtcNow.ToString("yyyyMMdd") + "\\Extracts";
Directory.CreateDirectory(folderPath);
string filePath = folderPath + "\\AppTypes.xml";
// File.Delete(filePath);
// File.WriteAllText(filePath, outer.accountRecs.ToString());
string fileName = "OneStream_MassDataExtract.txt";
// Write text file
ExportDataTableToFile(employeeData," ", folderPath+fileName);
switch (args.FunctionType)
{
case ExtenderFunctionType.Unknown:
break;
case ExtenderFunctionType.ExecuteDataMgmtBusinessRuleStep:
break;
case ExtenderFunctionType.ExecuteExternalDimensionSource:
// Add External Members
var externalMembers = new List<NameValuePair>();
externalMembers.Add(new NameValuePair("YourMember1Name", "YourMember1Value"));
externalMembers.Add(new NameValuePair("YourMember2Name", "YourMember2Value"));
return externalMembers;
}
return null;
string cubeName = "FinancialDetail";
string entityMemFilter = "E#1001";
string consName = "Local";
int scenarioTypeId = 1;//ScenarioTypeID.Actual;
string scenarioMemFilter = "S#Actual";
string timeMemFilter = "T#2024M6";
string viewName = "YTD";
string filter = "UD7=‘None’";
bool suppressNoData = true;
int parallelQueryCount = 1;
bool logStatistics = false;
DataTable dt = BRApi.Import.Data.FdxExecuteDataUnit(si, cubeName, entityMemFilter, consName, scenarioTypeId, scenarioMemFilter, timeMemFilter, viewName, suppressNoData, filter, parallelQueryCount, logStatistics);
}
catch (Exception ex)
{
throw ErrorHandler.LogWrite(si, new XFException(si, ex));
}
}
public void ExportDataTableToFile(DataTable datatable, string delimited, string file)
{
StreamWriter str = new StreamWriter(file, false, System.Text.Encoding.Default);
// Export columns
string Columns = string.Empty;
foreach (DataColumn column in datatable.Columns)
{
Columns += column.ColumnName + delimited;
}
str.WriteLine(Columns.Remove(Columns.Length - 1, 1));
// Export rows
foreach (DataRow datarow in datatable.Rows)
{
string row = string.Empty;
foreach (object items in datarow.ItemArray)
{
row += items.ToString() + delimited;
}
str.WriteLine(row.Remove(row.Length - 1, 1));
}
str.Flush();
str.Close();
}
// Create Sample Data
private DataTable CreateSampleData()
{
// Create a DataTable
DataTable employeeData = new DataTable("EmployeeData");
DataColumn dtColumn;
DataRow dtRow;
// Create Name column.
dtColumn = new DataColumn();
dtColumn.DataType = Type.GetType("System.String");
dtColumn.ColumnName = "Name";
dtColumn.Caption = "Name";
employeeData.Columns.Add(dtColumn);
// Create EmpID column.
dtColumn = new DataColumn();
dtColumn.DataType = Type.GetType("System.String");
dtColumn.ColumnName = "EmpID";
dtColumn.Caption = "EmpID";
employeeData.Columns.Add(dtColumn);
// Create Address column.
dtColumn = new DataColumn();
dtColumn.DataType = Type.GetType("System.String");
dtColumn.ColumnName = "Address";
dtColumn.Caption = "Address";
employeeData.Columns.Add(dtColumn);
// Add new row
dtRow = employeeData.NewRow();
dtRow["Name"] = "Employee 1";
dtRow["EmpID"] = "EmpID-1";
dtRow["Address"] = "Bangalore, India";
employeeData.Rows.Add(dtRow);
// Add new row
dtRow = employeeData.NewRow();
dtRow["Name"] = "Employee 2";
dtRow["EmpID"] = "EmpID-2";
dtRow["Address"] = "Bangalore, India";
employeeData.Rows.Add(dtRow);
// Add new row
dtRow = employeeData.NewRow();
dtRow["Name"] = "Employee 3";
dtRow["EmpID"] = "EmpID-3";
dtRow["Address"] = "Bangalore, India";
employeeData.Rows.Add(dtRow);
return employeeData;
}
}
}
Thank you so much for any assistance. I always seem to find answers to a lot of my questions here.
Denise
I am not a C# expert either but it looks like the line return null; is the end of the executable code in the procedure. Move that line to be after line 66.