How to set a default value to an destination schema element in BizTalk Map - biztalk

I have a requirement in BizTalk map, where
I will map some elements from source schema to destination schema,where the values will be assigned to destination schema elements based on some condition.
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.
Please see the Map below for a good understanding
alt text http://www.biztalkgurus.com/cfs-filesystemfile.ashx/__key/CommunityServer.Discussions.Components.Files/13/0131.problem.JPG
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.
When the element "TypeAddressNumber" within the F4706 is "1", then I am mapping the remaining fields of that F4706 instance to "ship to" details in my destination schema
When the element "TypeAddressNumber" within the F4706 is "2",then I am mapping the remaining fields of that F4706 instance to "Reseller" details in my destination schema
When the element "TypeAddressNumber" within the F4706 is "3",then I am 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
alt text http://www.biztalkgurus.com/cfs-filesystemfile.ashx/__key/CommunityServer.Discussions.Components.Files/13/5430.ip.JPG
The output I'm expecting and getting is :
alt text http://www.biztalkgurus.com/cfs-filesystemfile.ashx/__key/CommunityServer.Discussions.Components.Files/13/0724.curOP.JPG
Now if the Input file is like below :
alt text http://www.biztalkgurus.com/cfs-filesystemfile.ashx/__key/CommunityServer.Discussions.Components.Files/13/6403.otherIP.JPG
That is when I don't 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 :
alt text http://www.biztalkgurus.com/cfs-filesystemfile.ashx/__key/CommunityServer.Discussions.Components.Files/13/0435.nextOP.JPG
If you go and check the XLST which is getting generated, it is writing a xsl:foreach so if you use xsl:choose/otherwise conditions gets checked multiple times and my output nodes gets duplicated.
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.

Put two "Value mapping" (Label them "Incoming" and "Default") on the map and drag the output from both to your destination (you will get a warning at compile time).
Put a "Logical NOT" on the map (Label it "NoValue").
Put a logical evaluation (Existence, IsNil, Length) that suits your need, to evaluate if you have an incoming value, and drag your source field to it. (Label it "HasValue")
Drag the result to the "Incoming" and the "Logical NOT".
Drag your source field to the "Incoming".
Drag the output from "NoValue" to "Default".
Add a constant parameter to "Default", by double clicking and insert new parameter, that is your default value.
Hope you understand this mess :)

I believe you are essentially trying to control the creation of an output node based on some condition.
I have tried this for records (you are trying to do this for elements, so I believe this should work for that as well).
I had connected the output of the Logical functoid to the record and the record was created only if the logical functoid returned true.
For default values, you are doing it the right way by putting the default value in the property grid for Schema element. So if nothing is mapped to this element, you will see in the xsl file that the element with the default value is generated.

Related

AQL include for multi value property returns only first value

What's the right AQL format to include all values for a multi value property field. Neither #<prop name> nor properties.* seem to work.
When running an AQL query and including a property field which contains multiple values the result contains the first value and not a list containing all values
items.find(...).include("*","#distro")
At present, I run one query to generate a list of artifacts and then iterate through the list running a query for each artifacts properties
f'/api/storage/{artifact.repo}/{artifact.path}/{artifact.name}?properties'
Result
...properties {'key': 'distro', 'value': 'Ubuntu'}
Desired Result
...properties {'key': 'distro', 'value': ['Ubuntu', 'CentOS',...]}
I heard back from jfrog support and the problem seems to be that the use of '#propertyname' allows for the collapse of a potentially multi value property into a single value and this blocks the gathering of all properties.
A more efficient approach would be
items.find(...).include("property")
This results in all properties returned in the json payload as it includes the property domain which includes all the properties.
Additionally, by not using # the query doesn't collapse the properties from lists of values to a single value. So, if build_number is a property it becomes ['25'] instead of 25.
When requesting the property domain, be sure to treat each property as a list.

Using A4SWIFT to generate SWIFT FIN MT103 results in empty multi-option SWIFT field tokens

We're using BizTalk and A4SWIFT to generate SWIFT FIN MT 103 messages.
When we're outputting to fields that have multiple options (eg. 57a, 57b, 57c, 57d) we should only have a single output (I'm calling this a field token). However, all available options are output, regardless of whether they should be.
Consider field 57, which can have options 57a, 57b, 57c and 57d.
In our testing, we're limiting to 57a and 57d for now.
We have a map from our source XML document/schema, which selects which fields to use and populates the A4SWIFT schema accordingly.
(I've blanked out irrelevant detail in the image)
In the example, we're looking for a string for the BIC ("ABCDEFGHXXX") and populating the A4SWIFT-side for field 57A IF that is true.
For the Name Address (57d), we check the NameAddress/Line1 field for an arbitrary string which we know will evaluate to false.
(The BIC is fictitious)
This works fine, except we also get an empty result for 57D, even though this should have evaluated to false.
:57A:/
ABCDEFGHXXX
:57D:/
We need 57D to not be there. If the condition Functoid returns False, the Value Mapping Functoid still seems to cause a result.
So we're thinking out Functoid selection isn't right. We've tried with Logical Existence, Logical String and String Equal.
How can we suppress unselected fields from appearing in our output SWIFT?
Try linking through a Equal or Not Equal Functoid directly to 57D and/or 57A. That will suppress the entire loop.

Accessing distinguished fileds in assign shape (Biztalk)

I am constructing a multipart message in construct shape. That message has a body part with distinguished field, which i want to assign in assignment shape:
As you can see, intellisense is suggesting me to select a node with my distinguished field. But when i select it, i get an error!
I've faced this before, and restarting VS always helped. But not this time :(
Message is a reserved word in XLang. Can you change the name of the element/attribute that backs this distinguished field to something else? If that does not work, you could always XPath to the element to read it and use it. Last if those two don't work, you could make this a promoted property where you are able to specify the name yourself.
Here is the list of reserved words.
http://msdn.microsoft.com/en-us/library/aa547020.aspx

dynamodb creating a string set

I have a lot of objects with unique IDs. Every object can have several labels associated to it, like this:
123: ['a', 'hello']
456: ['dsajdaskldjs']
789: (no labels associated yet)
I'm not planning to store all objects in DynamoDB, only these sets of labels. So it would make sense to add labels like that:
find a record with (id = needed_id)
if there is one, and it has a set named label_set, add a label to this set
if there is no record with such id, or the existing record doesn't have an attribute named label_set, create a record and an attribute, and initialize the attribute with a set consisting of the label
if I used sets of numbers, I could use just ADD operation of UPDATE command. This command does exactly what I described. However, this does not work with sets of strings:
If no item matches the specified primary key:
ADD— Creates an item with supplied primary key and number (or set of numbers) for the attribute value. Not valid for a string type.
so I have to use a PUT operation with Expected set to {"label_set":{"Exists":false}}, followed (in case it fails) by an ADD operation. These are two operations, and it kinda sucks (since you pay per operation, the costs of this will be 2 times more than they could be).
This limitations seems really weird to me. Why are something what works with numbers sets would not work with string sets? Maybe I'm doing something wrong.
Using many records like (123, 'a'), (123, 'hello') instead of one record per object with a set is not a solutions: I want to get all the values from the set at once, without any scans.
I use string sets from the Java SDK the way you describe all the time and it works for me. Perhaps it has changed? I basically follow the pattern in this doc:
http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/API_UpdateItem.html
ADD— Only use the add action for numbers or if the target attribute is
a set (including string sets). ADD does not work if the target
attribute is a single string value or a scalar binary value. The
specified value is added to a numeric value (incrementing or
decrementing the existing numeric value) or added as an additional
value in a string set. If a set of values is specified, the values are
added to the existing set. For example if the original set is [1,2]
and supplied value is [3], then after the add operation the set is
[1,2,3], not [4,5]. An error occurs if an Add action is specified for
a set attribute and the attribute type specified does not match the
existing set type.
If you use ADD for an attribute that does not exist, the attribute and
its values are added to the item.
When your set is empty, it means the attribute isn't present. You can still ADD to it. In fact, a pattern that I've found useful is to simply ADD without even checking for the item. If it doesn't exist, it will create a new item using the specified key and create the attribute set with the value(s) I am adding. If the item exists but the attribute doesn't, it creates the attribute set and adds the value(s). If they both exist, it just adds the value(s).
The only piece that caught me up at first was that the value I had to add was a SS (String set) even if it was only one string value. From DynamoDB's perspective, you are always merging sets, even if the existing set is an empty set (missing) or the new set only contains one value.
IMO, from the way you've described your intent, you would be better off not specifying an existing condition at all. You are having to do two steps because you are enforcing two different situations but you are trying to perform the same action in both. So might as well just blindly add the label and let DynamoDB handle the rest.
Maybe you could: (pseudo code)
try:
add_with_update_item(hash_key=42, "label")
except:
element = new Element(hash_key=42, labels=["label"])
element.save()
With this graceful recovery approach, you need 1 call in the general case, 2 otherwise.
You are unable to use sets to do what you want because Dynamo Db doesn't support empty sets. I would suggest just using a string with a custom schema and building the set from that yourself.
To avoid two operations, you can add a "ConditionExpression" to your item.
For example, add this field/value to your item:
"ConditionExpression": "attribute_not_exists(RecordID) and attribute_not_exists(label_set)"
Source documentation.
Edit: I found a really good guide about how to use the conditional statements

Make a scripting functoid in a BizTalk map skip the output element

I'm using a scripting functoid in a BizTalk map. In a certain case, I want the destination element to be skipped (rather than empty).
I'm using inline C#. When I return null, the destination element is empty. Is there a way to make it skipped altogether?
Use a LogicalEquals functoid to determine if your input matches your case. Then map that output to a LogicalNot. Send the output of the LogicalEquals to one Mapping functoid (second input for Mapping will be the value of your field) and the output of your LogicalNot to another (same second input). Then map both of the value mapping functoids to your destination node.
Then, when your value equals your case, you'll send FALSE to the destination (instead of Null or Empty) and the node won't be output. Any other time, the LogicalNot will fire its Mapping Functoid and you should get your desired output.
Here's how I resolved it: (Please post an answer if you have a better way.)
Split the scripting functoid into two. The first one determines whether the destination element should exist at all and returns a boolean. The second one determines what value should be set in the destination (if any). Use these two scripting functoids as the inputs to a value mapping functoid.
Update: I didn't see Allen's similar answer when I posted this. I'll leave my alternative approach here in case it helps someone.

Resources