null/nil values for a custum functoid

Home Page Forums BizTalk 2004 – BizTalk 2010 null/nil values for a custum functoid

Viewing 1 reply thread
  • Author
    Posts
    • #17529

      Hi,

      I just tried to create a custom functoid like the coalesce function in SQL. A function returning the first non-null value. But I experience the following problem: When I connect strings, it works fine, but if I connect a value mapper my function as a parameter, and the value mapper does not result in a value, my function does not return any value, even if another parameter to my function has a value. What does the value mapper generate on false? nil? nothing? it seems that the function afterwards is not called at all.

       Any ideas?

       
      using System;
      using System.Collections.Generic;
      using System.Text;
      using Microsoft.BizTalk.BaseFunctoids;
      using System.Reflection;

      namespace TTBiztalkFunctoids
      {
          public class CoalesceFunctoid : BaseFunctoid
          {
              public CoalesceFunctoid()
                  : base() {

                  this.ID = 7000;
                  this.Category = FunctoidCategory.String;

                  // this to get the resources embedded in the resx file,
                  // call GetExecutingAssembly because the resource is compiled and embedded into the DLL.
                  SetupResourceAssembly("TTBiztalkFunctoids.Resources", Assembly.GetExecutingAssembly());

                  SetDescription("Coalesce_Description");
                  SetTooltip("Coalesce_Tooltip");
                  SetBitmap("Coalesce_Icon");             // must be an embedded BITMAP, not icon!!!
                  SetName("Coalesce_Name");
                 
                  AddScriptTypeSupport(ScriptType.CSharp);

                  //this function can accept variable inputs. The overidden function "GetInlineScriptBuffer" will
                  //provide inline script code for various number of inputs.
                  this.HasVariableInputs = true;

                  //Set the minimum number of parameters to be 1
                  this.SetMinParams(1);

                  //// this method call tells the mapper what function to call, when functoid is deployed to GAC.
                  //SetExternalFunctionName(GetType().Assembly.FullName,
                  //    "TTBiztalkFunctoids.Coalesce", "Coalesce");

                  // define output and input connection types..
                  this.OutputConnectionType = ConnectionType.AllExceptRecord;
                  AddInputConnectionType(ConnectionType.AllExceptRecord);

              }

              //this overidden function provides inline code for various number of inputs.
              protected override string GetInlineScriptBuffer(ScriptType scriptType, int numParams, int functionNumber) {
                  if (ScriptType.CSharp == scriptType) {
                      StringBuilder builder = new StringBuilder();

                      builder.Append("public string Coalesce(");

                      for (int i = 0; i < numParams; i++) {
                          if (i > 0) {
                              builder.Append(", ");
                          }

                          builder.Append("string param");
                          builder.Append(i.ToString());
                      }

                      builder.Append(")\n");
                      builder.Append("{\n");

                      builder.Append("   System.Collections.ArrayList listStrings = new System.Collections.ArrayList();\n");

                      for (int j = 0; j < numParams; j++) {
                          builder.Append("   listStrings.Add(param");
                          builder.Append(j.ToString());
                          builder.Append(");\n");
                      }

                      builder.Append("   foreach (string s in listStrings)\n");
                      builder.Append("   {\n");
                      builder.Append("       if (s!=null)\n");
                      builder.Append("       {\n");
                      builder.Append("           return s;\n");
                      builder.Append("       }\n");
                      builder.Append("   }\n");
                      builder.Append("   return null;\n");
                      builder.Append("}\n");

                      return builder.ToString();
                  } else {
                      return "";
                  }
              }

              //public string Coalesce(params string[] inputs) {
              //    foreach (string input in inputs) {
              //        if (input != null) return input;
              //    }
              //    return null;
              //}
          }

      }

       

       

    • #17532

      make sure the logical is the FIRST parameter in your value mapper.
      – wa 

       

Viewing 1 reply thread
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.