Home Page › Forums › BizTalk 2004 – BizTalk 2010 › How to set a default value to an destination schema element in BizTalk Map
- This topic has 9 replies, 1 voice, and was last updated 9 years, 1 month ago by
community-content.
-
AuthorPosts
-
-
May 15, 2009 at 2:31 AM #22377
HI All,
I have a requirement in BizTalk map, where
1.I will map some elements from source schema to destination
schema, where the values will be assigned to destination schema’s different elements
from the same elements in source schema based on some condition. That means my Source element loops, based on some id i have fetch the data and fill it to the flat structure in the destination schema.2.If those values are not assigned, i need to send some default value (N/A).
- My map is not One-to-One so that i can use a scripting functoid and
send a default value, on top of that the destination schema is a flat
file and in source schema i have to loop a lot.
so can any body give me some suggestion about “How to set a Default
value to a Element in Destination schema if nothing is mapped” using
BizTalk Map/some setting in schema.What i have already tried is, I Opened the destination schema for
all the elements i have set the value ‘N/A’ to a property ->
“DefaultValue” which was there in the property tab but when nothing is
mapped the default value is not coming. Instead the node itself is not
created in the Output file.Pls see the Map below for a good understanding
Source Schema is a XML schema.
Destination Schema is a Flat file schema.
Now in the above map, in my source schema i am having a node called F4706 which will loop.
1) when the element “TypeAddressNumber” within the F4706 is “1“,then i am the mapping the remaining fields of that F4706 instance to “ship to” details in my destination schema
2) when the element “TypeAddressNumber” within the F4706 is “2“,then i am the mapping the remaining fields of that F4706 instance to “Reseller” details in my destination schema
3) when the element “TypeAddressNumber” within the F4706 is “3“,then i am the mapping the remaining fields of that F4706 instance to “EndUser” details in my destination schema
Now if i connect a Logical NOT functoid to the Logical Equal functoid and assign some default value, then the my destination node occurs Three times as one time the “=” functiod returns true one time and false other two times. but what i want is, if anything is there to map then map from “F4706” instance or assign the default value.
Find the INPUT File below
the ouput i m expecting and getting is :
Now if the Input file is like below :
that is when i dont have a “F4706” node with TypeAddressNumber=2, i need to fill “N/A” in Reseller related nodes in my destination schema. which should look like below :
If you go and check the XLST which is getting generated,(i have pasted for the first node “Reseller Name”)
<xsl:variable name=”var:v1“ select=”TypeAddressNumber“
/><xsl:variable name=”var:v2“ select=”userCSharp:LogicalEq(string($var:v1) , “2”)“ /><xsl:variable name=”var:v3“ select=”Name“ /><xsl:value-of select=”$var:v3“ /></ResellerName></xsl:if></xsl:for-each>it was like this, even if i modify this like the below it will create the node “Thrice” or how many time it loops that much time.[Because it is a Foreach, and i dont have any break or return in XLST i am unable to do it]
<xsl:for-each select=”F4706″>
<xsl:variable name=”var:v1″ select=”TypeAddressNumber” />
<xsl:variable name=”var:v2″ select=”userCSharp:LogicalEq(string($var:v1) , "2")” />
<xsl:choose>
<xsl:when test=”string($var:v2)=’true'”>
<xsl:variable name=”vartan1″ select=”100″ />
<ResName>
<xsl:value-of select=”Name” />
</ResName>
</xsl:when>
<xsl:otherwise>
<ResName>
<xsl:value-of select=”N/A” />
</ResName>
/xsl:otherwise>
</xsl:choose>
</xsl:for-each>I also tried to use some global variable in XLST in First Loop and and second loop to access that and write the default value, unfortunately it doesn’t work too. Because a VARIABLE in XLST is not a TRUE variable. I think its a CONSTANT.
How to accomplish this ANY help is highly appreciated.
Advanced Thx
–santhosh(http://aledaata.blogspot.com)
- My map is not One-to-One so that i can use a scripting functoid and
-
May 19, 2009 at 11:07 AM #22406
What a coincidence i am facing the same problem
are you same santosh who sites behind me ?
-
May 19, 2009 at 11:05 PM #22415
Hi, you can try this:
In this case, the clientCode from source schema is feed into an IsNil logical functoid, a “Logical Existence” logical functoid and a scripting functoid (S1). S1 is an Inline C# script type with this code:
public System.Boolean MyConcat(string param1)
{
return System.String.IsNullOrEmpty(param1);
}Then the result of IsNil function, “Logical Existence” and S1 functoids are feeded into a logical OR functoid. Then the result of the logica OR functoid is feeded into a logical NOT function, which in turn feeds into a ValueMapping functoid (VM1) as first input. And the ClientCode of the source schema is also feeded into the the same value mapping functoid (VM1) as the second input. The result of of VM1 is then feeded to the ClientCode in the destination schema.
The result of the logical OR functoid also feeds into ValueMapping functoid (VM2) as the first input, the 2nd input parameter is configured to “N/A”. then the result of VM2 is feeded to the ClientCode in the destination schema.
This way, DestinationSchema.ClientCode=SourceSchema.Client if SourceSchema.Client exist, not null, and not empty, otherwise, DestinationSchema.ClientCode=”N/A”.
Hope this helps.
-
May 19, 2009 at 11:55 PM #22417
Hey Guo,
Thanks for your reply. it works in case of ONE-TO-ONE Mapping.
In my case i am looping the source schema, and based on some conditions i am filling the same fields from the source elements to different elements in destination schema.
Hope you got my problem.
-
May 20, 2009 at 6:24 AM #22427
Hi shadakshari85, I am more of a visual person, it would be helpful if you can provide the source the destination schema.
Another approach you can try is to use XSLT template inside a scripting functoid, where it enables you setup global variable that you can use in the map.
-
July 3, 2009 at 1:36 AM #22784
Hi
I had the same problem.. okay here is my solution
- Logical Existence : Returns true if the input record or field exists in the source document.
- Equal : First Value Logical Existence; Second Value : true … This will trueReturns true if the first parameter is equal to the second parameter. i.e if the logical existence retruns true.
- Scripting Functoid : With the following code.. ::-) First parameter Equal functoid; Second Parameter source element
public int uCheckAvailableOrNot(bool param1,string sourceElementVariable)
{
bool valueMissing = true;
//In my case I need to retrun something for the my destination element
int defaultNummer = 200;
//If my source schema have a value
if (param1 == valueMissing )
{
return Int32.Parse(sourceElementVariable);
}
//if there is no value return the default
else
{
return defaultNummer;
}}
Hope it helps
Akabuilo
-
July 13, 2009 at 6:00 PM #22844
Thanks Akabuilo. I’ve been looking for this solution in the past couple of days. Your suggestion worked for me too.
Spike
-
June 21, 2013 at 6:32 PM #26080
Yep!!! Awesome! Solved my problem too 🙂 Thanks Akabuilo!
-
June 21, 2013 at 6:53 PM #26081
public string myScriptMethod(bool equalFunctoidValue, string sourceSchemaString)
{
if(equalFunctoidValue)
return sourceSchemaString;
else
return string.Empty;
}
-
-
-
-
-
August 3, 2009 at 2:24 AM #22943
hi,
u can also try to set the “Value” property of the node element which is a Property filed of the nodes. You can set default value there.
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.
