Problem

You need to pass variable information into a map.

If data is not available in the message content, or relevant to being assigned via a Distinguished Field or XPath() call then you can use this method to pass in other data.

Solution

Use a .NET assembly with a ThreadStatic attribute to create a variable that can be accessed from the mapper.  Assignment and reading to this variable should be done within an Atomic Scope to ensure data is not lost during Dehydration.

Using a Static variable would make your value available to all instances of your map running within the same AppDomain (or Host Instance), by using ThreadStatic the variable is scoped to the current thread that is being processed.

Example

This is an example C# class that provides a reusable solution.  As the BizTalk Orchestration XLANG/s engine does not play ball with generics, this wrapper provides an interface through standard methods.

/// <summary>
/// Helper for passing information into the BizTalk Mapper
/// Author: Alastair Grant
/// </summary>
public class Mapping
{
    [System.ThreadStaticAttribute]
    private static System.Collections.Generic.Dictionary<string, string> _data = new System.Collections.Generic.Dictionary<string,string>();
 
    public static System.Collections.Generic.Dictionary<string, string> Data
    {
        get
        {
            if (_data == null)
            {
                _data = new System.Collections.Generic.Dictionary<string, string>();
            }
            return _data;
        }
        set
        {
            _data = value;
        }
    }
 
 
    /// <summary>
    /// Method to retrieve value from dictionary
    /// </summary>
    /// <param name="key">Key</param>
    /// <returns>Previous saved value</returns>
    public static string GetDataValue(string key)
    {
        if (Data.ContainsKey(key))
        {
            return Data[key];
        }
        else
        {
            return System.String.Empty;
        }
    }
 
    /// <summary>
    /// Method to store value in dictionary against a key
    /// </summary>
    /// <param name="key">key</param>
    /// <param name="value">value</param>
    public static void SetDataValue(string key, string value)
    {
        if(Data.ContainsKey(key))
        {
            Data[key] = value;
        }
        else
        {
            Data.Add(key, value);
        }
    }
}
  1. Call the SetDataValue() method from your Orchestration, within your Atomic Shape with a key and the value you wish to retrieve in the map
  2. Add an Advanced Scripting Functoid to your map, select your External Assembly with the above helper class defined and the GetDataValue method
  3. Add your key as the input parameter to the functoid

See Also

Another important place to find a huge amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki