Click here to Skip to main content
15,879,535 members
Articles / Programming Languages / C#

Functoid with more than one output value

Rate me:
Please Sign up or sign in to vote.
2.43/5 (4 votes)
10 Oct 2009CPOL2 min read 39.3K   3   15
Functoid with more than one output value

Introduction

When we were working on one of the BizTalk projects, we were facing difficulties because of not having a built in functoid that will have more than one return value. To overcome this issue, we came up with the following solution.

Problem Statement

Retrieve two field’s values from the database based on the input values. And the retrieved two field’s values should be assigned to the three different fields in the destination schema of the map. And all these activities should happen in the map.

Solution

1. Create a Method for Retrieving the Value from the Database

Given below is the sample code:

C#
public static string GetSuppRecordForAP(string input1, string input2, string input3)
{
Database db = null;
IDataReader dr = null;
DbCommand cmd = null;
string suppQuery = string.Empty;
string SPSTID = string.Empty;
string outString = string.Empty;
String query = String.Empty;
Int32 orgId = 0;
try
{
db = DatabaseHelper.Instance.CreateDatabase("database1");
cmd = db.GetSqlStringCommand
("select out1,out2 from table where field1='" + input1 +
"' AND field2='" + input2 + "' AND field3='" + input3 + "'");
cmd.CommandType = CommandType.Text;
dr = db.ExecuteReader(cmd);
if (dr.Read())
{
outString = "out1~out2#";
outString += Convert.ToString(dr["out1"]) + "~" + Convert.ToString(dr["out2"]);
}
else
{
throw;
}
return outString;
}
catch
{
throw;
}
finally
{
if (dr != null)
{
dr.Close();
}
}
}

The output of the above method will be like out1~out2#value1~value2.

Note: Make sure that the special characters used will not be part of the data.

2. Create a Custom Functoid that will Accept 2 Input String Parameters

The custom functoid should accept 2 input parameters, and the first parameter is for accepting the string in the format out1~out2#value1~value2 and the second parameter is for receiving the name of the field whose value needs to be retrieved.

3. Sample Code for Main Function that will Help to Retrieve the Value in the Custom Functoid

C#
public string ColumnValueExtractor(string fieldsAndValues, string columnName)
{
ResourceManager resmgr = new ResourceManager
("Sample.Functoid.KeyValueExtractor.KeyValueExtractorResource",
Assembly.GetExecutingAssembly());
string fields = string.Empty;
string values = string.Empty;
string[] fieldsArray = null;
string[] valueArray = null;
string result = string.Empty;
try
{
fields = fieldsAndValues.Split('#')[0];
values = fieldsAndValues.Split('#')[1];
fieldsArray = fields.Split('~');
valueArray = values.Split('~');
for (int i = 0; i < fieldsArray.Length; i++)
{
if (fieldsArray[i] == columnName)
{
result = valueArray[i];
return result;
}
}
return result;
}
catch 
{
throw;
}
}

Note

Use this link for help with creating a custom functoid.

4. Use the Custom Functoid in the Map

You can find more details below:

Use a scripting functoid that will call the .NET method that is created in step 1. The figure is as shown below:

Image 1

Figure 1.

Use the custom functoid that is created in step 2 & 3 and give the output of the above scripting functoid as the first parameter and the name of the field whose value needs to be retrieved as the second parameter. Find the figure as follows:

Image 2

Figure 2.

Map the output of the custom functoid to the respective fields in the destination schema. Find the figure below:

Image 3

Figure 3.

Note: The blue colored functoids are the new custom functoids created in steps 2 & 3. And based on your requirements, customize the methods used in the .NET component to retrieve the value and the customer functoid method.

History

  • 10th October, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer accenture
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 PinPopular
pintyo11-Oct-09 11:39
pintyo11-Oct-09 11:39 
GeneralMy vote of 1 Pin
Klein Ron10-Oct-09 22:39
Klein Ron10-Oct-09 22:39 
QuestionWhy? Pin
Saurabh.Garg10-Oct-09 15:33
Saurabh.Garg10-Oct-09 15:33 
Why encode and decode results in a string? Why not just use a structure and return an instance of the structure. Unsure | :~

-Saurabh
AnswerRe: Why? Pin
gaurav_verma_mca10-Oct-09 20:54
gaurav_verma_mca10-Oct-09 20:54 
GeneralRe: Why? Pin
Saurabh.Garg10-Oct-09 23:37
Saurabh.Garg10-Oct-09 23:37 
GeneralRe: Why? Pin
gaurav_verma_mca10-Oct-09 23:50
gaurav_verma_mca10-Oct-09 23:50 
GeneralRe: Why? Pin
Saurabh.Garg10-Oct-09 23:55
Saurabh.Garg10-Oct-09 23:55 
GeneralRe: Why? Pin
gaurav_verma_mca10-Oct-09 23:58
gaurav_verma_mca10-Oct-09 23:58 
GeneralRe: Why? Pin
Saurabh.Garg11-Oct-09 0:00
Saurabh.Garg11-Oct-09 0:00 
GeneralRe: Why? Pin
gaurav_verma_mca11-Oct-09 0:02
gaurav_verma_mca11-Oct-09 0:02 
GeneralRe: Why? Pin
Saurabh.Garg11-Oct-09 0:09
Saurabh.Garg11-Oct-09 0:09 
GeneralRe: Why? Pin
gaurav_verma_mca11-Oct-09 0:17
gaurav_verma_mca11-Oct-09 0:17 
GeneralRe: Why? Pin
Sarmak.M.C11-Oct-09 4:37
Sarmak.M.C11-Oct-09 4:37 
GeneralGood work Pin
gaurav_verma_mca10-Oct-09 5:29
gaurav_verma_mca10-Oct-09 5:29 
GeneralRe: Good work Pin
Sarmak.M.C10-Oct-09 7:07
Sarmak.M.C10-Oct-09 7:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.