Click here to Skip to main content
Click here to Skip to main content

Functoid with more than one output value

, 10 Oct 2009
Rate this:
Please Sign up or sign in to vote.
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:

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

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:

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:

Figure 2.

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

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)

Share

About the Author

Sarmak.M.C
Software Developer accenture
India India
No Biography provided

Comments and Discussions

 
GeneralMy vote of 1 Pinmemberpintyo11-Oct-09 11:39 
GeneralMy vote of 1 Pinmemberron99klein10-Oct-09 22:39 
QuestionWhy? PinmemberSaurabh.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? Pinmembergaurav_verma_mca10-Oct-09 20:54 
GeneralRe: Why? PinmemberSaurabh.Garg10-Oct-09 23:37 
GeneralRe: Why? Pinmembergaurav_verma_mca10-Oct-09 23:50 
GeneralRe: Why? PinmemberSaurabh.Garg10-Oct-09 23:55 
GeneralRe: Why? Pinmembergaurav_verma_mca10-Oct-09 23:58 
GeneralRe: Why? PinmemberSaurabh.Garg11-Oct-09 0:00 
GeneralRe: Why? Pinmembergaurav_verma_mca11-Oct-09 0:02 
GeneralRe: Why? PinmemberSaurabh.Garg11-Oct-09 0:09 
GeneralRe: Why? Pinmembergaurav_verma_mca11-Oct-09 0:17 
GeneralRe: Why? PinmemberSarmak.M.C11-Oct-09 4:37 
GeneralGood work Pinmembergaurav_verma_mca10-Oct-09 5:29 
GeneralRe: Good work PinmemberSarmak.M.C10-Oct-09 7:07 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 10 Oct 2009
Article Copyright 2009 by Sarmak.M.C
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid