Bug Scenario: You are using C# variable in Mapping Functoids.
You run a map through “Test Map” and it works fine each time.
You run a file through a receive location, running the same map. Works great first time, but second time it maps nothing (or behaves differently). When you restart BizTalk Host Instance, it works fine first time, but not second time.
Why are we using a variable in the first place? The ideas was to map a field just one time (in a loop). So once the field is mapped, we need to set a flag not to map it again.
What is the bug in the following code?
{!{code}!}czozMjU6XCIKcHVibGljIHN0YXRpYyBib29sIGdvdENvYm9ycm93ZXJMYXN0bmFtZSA9IGZhbHNlOwoKcHVibGljIHN0YXRpYyBzdHJ7WyYqJl19aW5nIENvYm9ycm93ZXJMYXN0bmFtZSAoc3RyaW5nIHBhcmFtMSkKewogICAgIHN0cmluZyByZXN1bHQgPSBcImZhbHNlXCI7CiAgICAge1smKiZdfWlmIChwYXJhbTEuVG9VcHBlcigpID09IFwiVFJVRVwiICYmICFnb3RDb2JvcnJvd2VyTGFzdG5hbWUpCiAgICAgICAgIHsKICAgICAgIHtbJiomXX0gICAgICAgICBnb3RDb2JvcnJvd2VyTGFzdG5hbWUgPSB0cnVlOwogICAgICAgICAgICAJcmVzdWx0ID0gXCJ0cnVlXCI7CiAgICAgICB7WyYqJl19ICB9CgogICAgICByZXR1cm4gcmVzdWx0Owp9ClwiO3tbJiomXX0={!{/code}!}
The “static” keyword must be removed from the global variable. By making it static, only one copy of the variable is held in memory. Thus, the variable stays set to the last value, even when you run a new map. The variable does not get reset until you restart the BizTalk Host instance.
{!{code}!}czo0NDpcIgpwdWJsaWMgYm9vbCBnb3RDb2JvcnJvd2VyTGFzdG5hbWUgPSBmYWxzZTsKXCI7e1smKiZdfQ=={!{/code}!}