Updating the global environment by using a .NETCompute node

Change the global environment by using code in your .NETCompute node.

About this task

The global environment tree is always created when the logical tree is created for an input message. However, a message flow does not populate it or use its contents. You can use this tree for your own purposes, for example to pass information from one node to another. You can use the whole tree as a scratchpad or working area.
The Global Environment can be altered at any point during the message flow; therefore you do not make a copy of it to alter. The following C# code shows how to change the global environment in a .NETCompute node:
        public override void Evaluate(NBMessageAssembly inputAssembly)
        {
            NBOutputTerminal outTerminal = OutputTerminal("Out");
            NBMessage inputMessage = inputAssembly.Message;
            // Create a new empty message, ensuring it is disposed after use
            using (NBMessage outputMessage = new NBMessage())
            {
                NBMessageAssembly outAssembly = new NBMessageAssembly(inputAssembly, outputMessage);
                NBElement inputRoot = inputMessage.RootElement;
                NBElement outputRoot = outputMessage.RootElement;

                // Optionally copy message headers, remove if not needed
                CopyMessageHeaders(inputRoot, outputRoot);

                #region UserCode
                // Add user code in this region to create a new output message
                NBMessage env = outAssembly.Environment;
                env.RootElement.CreateFirstChild(null, "Status", "Success");                               
                #endregion UserCode

                // Change the following if not propagating message to the 'Out' terminal
                outTerminal.Propagate(outAssembly);
            }
        }

For information about the .NET classes and methods that are supported in IBM® App Connect Enterprise, see the .NET API documentation.