|
Home > Archive > BizTalk Server General > February 2005 > Add a new field element to a message in Rule Composer
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Add a new field element to a message in Rule Composer
|
|
| Andre Afonso 2005-02-20, 6:12 pm |
| Hello,
I wan't to create a policy that validates a message and appends a new child
field element to the message for each error found. For simplicity I'm not
presenting the message as is but a bogus one:
<record>
<field1>value1</field1>
<field2>value2</field2>
</record>
After the rules are fired by the message and if erros are found I want it to
look like this:
<record>
<field1>value1</field1>
<field2>value2</field2>
<error number="12" message="some error description" />
<error number="41" message="another error description" />
</record>
Now, I'm very fresh at this so I might be getting it wrong. I think it would
need a .NET class to create this new "error" field and append it to the
message, so I've created the following method:
public static void GetErrorMessage(TypedXmlDocument message, string
errorNumber)
{
XmlDocument document = (XmlDocument) message.Document; //doe the sdk
says that this returns a XmlDocument, it in in fact returns XmlNode so the
type cast
XmlElement newElement = document.CreateElement("error");
XmlAttribute newAttribute = document.CreateAttribute("number");
newAttribute.InnerText = errorNumber;
newElement.Attributes.Append(newAttribute);
newAttribute = document.CreateAttribute("message");
newAttribute.InnerText = "some error description";
newElement.Attributes.Append(newAttribute);
document.DocumentElement.AppendChild(newElement);
}
Next I've added this method and the root element for the message as a fact
in the Vocabulary of the Rule Composer, and called the method as an action
of the rule passing it the root element of the message. But nothing happens,
the rule fires fine but simply the message is not altered by the method. How
can I return the message modified by the method back to the orchestration
that calls the rule?
Thank you,
Andre
| |
| Matt Milner 2005-02-21, 2:47 am |
| Do the rule traces when you test the policy show the facts getting asserted
correctly and the rules firing? Also, can you debug the rules composer when
you test your policy and see your code getting executed?
It looks like you are on the right track, but take a look at those items
just to make sure things are working as you think they should.
Also, Scott Woodgate (http://blogs.msdn.com/scottwoo/) had some samples of
how to this type of thing on this blog. I think it was back between
Sept/Nov of last year, but I didn't try to go find the link again.
Matt
"Andre Afonso" <andre.afonso@tekever.com.no.spam> wrote in message
news:e2WtfL6FFHA.1476@TK2MSFTNGP09.phx.gbl...
> Hello,
>
> I wan't to create a policy that validates a message and appends a new
> child
> field element to the message for each error found. For simplicity I'm not
> presenting the message as is but a bogus one:
>
> <record>
> <field1>value1</field1>
> <field2>value2</field2>
> </record>
>
> After the rules are fired by the message and if erros are found I want it
> to
> look like this:
>
> <record>
> <field1>value1</field1>
> <field2>value2</field2>
> <error number="12" message="some error description" />
> <error number="41" message="another error description" />
> </record>
>
> Now, I'm very fresh at this so I might be getting it wrong. I think it
> would
> need a .NET class to create this new "error" field and append it to the
> message, so I've created the following method:
>
> public static void GetErrorMessage(TypedXmlDocument message, string
> errorNumber)
> {
> XmlDocument document = (XmlDocument) message.Document; //doe the sdk
> says that this returns a XmlDocument, it in in fact returns XmlNode so the
> type cast
> XmlElement newElement = document.CreateElement("error");
> XmlAttribute newAttribute = document.CreateAttribute("number");
> newAttribute.InnerText = errorNumber;
> newElement.Attributes.Append(newAttribute);
> newAttribute = document.CreateAttribute("message");
> newAttribute.InnerText = "some error description";
> newElement.Attributes.Append(newAttribute);
> document.DocumentElement.AppendChild(newElement);
> }
>
> Next I've added this method and the root element for the message as a fact
> in the Vocabulary of the Rule Composer, and called the method as an action
> of the rule passing it the root element of the message. But nothing
> happens,
> the rule fires fine but simply the message is not altered by the method.
> How
> can I return the message modified by the method back to the orchestration
> that calls the rule?
>
> Thank you,
>
> Andre
>
>
| |
| André Afonso 2005-02-21, 5:52 pm |
| Thank you Matt, it was indeed on Sept.
http://blogs.msdn.com/scottwoo/arch.../16/230472.aspx
This BizTalk sure has some tricks into it. For anyone facing the same
challenge, make sure you add a variable of the type that holds the helper
method using the ochestration view window, not to the orchestration
variables collection but to the collection that belongs to the scope of the
atomic trans where the rule is called, and pass the variable as a parameter
in the Call Rules shape configuration dialog box. This is necessary even if
you're calling a static method. If you fail to do so you should be getting a
"object reference not set to an instance", as a resulting exception or as an
error written by XLANG in the event viewer.
Best regards,
Andre Afonso
"Matt Milner" <matt.milner@m3technologypartners dot com> wrote in message
news:OUGEty8FFHA.560@TK2MSFTNGP15.phx.gbl...
> Do the rule traces when you test the policy show the facts getting
asserted
> correctly and the rules firing? Also, can you debug the rules composer
when
> you test your policy and see your code getting executed?
>
> It looks like you are on the right track, but take a look at those items
> just to make sure things are working as you think they should.
>
> Also, Scott Woodgate (http://blogs.msdn.com/scottwoo/) had some samples of
> how to this type of thing on this blog. I think it was back between
> Sept/Nov of last year, but I didn't try to go find the link again.
>
> Matt
>
>
> "Andre Afonso" <andre.afonso@tekever.com.no.spam> wrote in message
> news:e2WtfL6FFHA.1476@TK2MSFTNGP09.phx.gbl...
not[vbcol=seagreen]
it[vbcol=seagreen]
the[vbcol=seagreen]
fact[vbcol=seagreen]
action[vbcol=seagreen]
orchestration[vbcol=seagreen]
>
>
|
|
|
|
|