Adding Two Sub-Items for an Argument
4 min
Overview
You can add multiple child values to a job argument by creating a list item with AddListValue() and then setting values on the returned XML element.
Use Case
Use this approach when an argument needs to contain multiple sub-items within a list entry.
Example
using System;
using Innovation.Activate;
using System.Xml;
class Script : ScriptBase
{
public void main()
{
Job j = new Job();
// Mark the argument as a list
j.Arguments.SetValue("badJobNumbers/@list", "1");
// Create a new list item
XmlElement n = j.Arguments.AddListValue("badJobNumbers/item", "");
// Add child values to the list item
XmlValue.Set(n, "badNumber", "123");
XmlValue.Set(n, "message", "Eat breakfast");
Trace.WriteLine(j.Arguments.FormattedXml);
}
}Resulting XML
<badJobNumbers list="1">
<item>
<badNumber>123</badNumber>
<message>Eat breakfast</message>
</item>
</badJobNumbers>Key Points
- AddListValue() creates a new item in a list argument and returns the corresponding XmlElement.
- XmlValue.Set() adds or updates child elements within the list item.
- Set the @list attribute to "1" to indicate that the argument contains a list.
- Use FormattedXml to inspect and verify the final argument structure.