OIS - Link Properties, Published Data with Newline Characters, and Regular Expressions
Hello readers/viewers! No video today, but I will be covering a fairly interesting topic. I realize that this may be an edge case, but I thought it would good to have something on the blog to reference for related topics.
SCENARIO:
- You have Published Data output which may contain newline characters ( \n).
- NOTES:
- In this case, the Published Data is not separated into multiple output data items.
- You may experience this if you have flattened the Published Data with the Separate with line breaks option, or if you are referencing output from some objects where this data format is common (e.g. “Query WMI” object).
- NOTES:
- You want to filter this Published Data by the existence of the newline character ( \n).
- You use the available Link Properties for string filtering, taking advantage of the matches pattern option.
- REFERENCES:
- Link Properties: https://technet.microsoft.com/en-us/library/gg440712.aspx
- Regular Expressions: https://technet.microsoft.com/en-us/library/gg440701.aspx
- REFERENCES:
- You notice that filtering the Published Data by matches pattern \n does not work as you expect.
- NOTE: There is a “workaround” as well as a “working with /n character published data” section below.
EXAMPLE SCENARIO CONFIGURATION:
If we take something like the “Query WMI” object, which produces output with the new line character, and attempt to filter the “WMI Query Result as a string” by “Matches Pattern” \n in the link, it does not work:
EXAMPLE SCENARIO RESULTS:
During execution, this link filter configuration results in no data progressing past the link, even though the results look like this (where matching pattern would normally contain the \n):
POSSIBLE CAUSE:
I do not know the root cause for this behavior, but it may be that the Regular Expression implementation for Link Properties in OIS does not support “multiline mode” (search on this page for “multiline”).
MATCHES PATTERN DOES WORK:
I do know that “Match Pattern” in Link Properties Filtering does work, as I use it frequently to filter out “null” values from Published Data fields:
Usage for field “Is Not Null”:
ALTERNATE REGEX TOOL RESULTS:
Now, if we take a portion of that same output and put it in an online .NET RegEx tester, you can see that the highlighted areas are where the \n character exists in the output sample (first 5 lines of the output from the Query WMI object).
NOTE: Lines copied from “Query WMI” object:
Caption=System Idle Process
Caption=System
Caption=smss.exe
Caption=csrss.exe
Caption=csrss.exe
WORKAROUND:
This does not mean that you are left with no ability filter based on the \n character; you simply have to use a workaround. The good news is, the workaround is pretty simple.
For those of you who do not yet know, there are a couple CodePlex releases which allow you to work with RegEx as a workaround:
If you would like to use Foundation Objects for the workaround, see the following steps:
Workaround Steps:
- Remove the link filter from the “Query WMI” object to the “Send Platform Event” object
- Insert a “Run .Net Script” object between those two objects (you will be doing the match in this object using PowerShell)
- In the “Run .Net Script” object:
- Now add link filtering to the link after the “Run .Net Script” object:
NOTE: PowerShell from the Details tab in this example (where $hasnewline will return “True” or “False”):
$inputdata = " {PUBLISHED DATA HERE} "
$hasnewline = $inputdata -match "\n"
$hasnewline
WORKING WITH \n CHARACTER IN PUBLISHED DATA:
Now that you can filter based on the \n character, you may want to know how to work with it.
Examples:
The following C# usage with the “Run .Net Script” object examples (OIS_EXPORT attached) parse the following output (from an example query WMI object):
Option 1: Just Parsing the “blob” of text into an array (where each new line is a new array element) – If you want to parse the “Name=” portion of the string in each array item, it will have to be parsed later in another object:
string res = @"PUBLISHED DATA HERE"; string[] results = res.Split(new string[] {"\n", "\r\n"}, StringSplitOptions.RemoveEmptyEntries); foreach (string r in results) { lstResults.Add(r); }
This results in multiple line output that still needs to be parsed (based on the desire to remove “Name=” from each array item):
Option 2: Parse the “blob” of text into an array, then parse for specific data and output only what you want (no other objects required):
string res = @"PUBLISHED DATA HERE"; string[] results = res.Split(new string[] {"\n", "\r\n"}, StringSplitOptions.RemoveEmptyEntries); foreach (string r in results) { string[] parsedResults = r.Split('='); lstResults.Add(parsedResults[1]); }
This results in multiple line output that has already been parsed:
NOTE: For a more detailed video example of C# usage with the “Run .Net Script” object, please refer to the following post: https://blogs.technet.com/b/charlesjoy/archive/2010/07/14/8-minute-demo-net-scripting-object-c.aspx
enJOY!
Run_dotNet_Script_cSharp_Parse_Data_Examples.zip
Comments
- Anonymous
January 01, 2003
- There is currently no Integration Pack for FTP, its release currently targeted with the SC Orchestrator 2012 release later this year. This does not mean you cannot use the OIS extensibility objects to integrate to software with SFTP capabilities.
- Legacy objects are to be used exclusively with the Legacy Workflow Engine. They exist strictly for backwards compatibility for customers running workflows in Legacy mode. All new workflows are created and configured for Pipeline Mode and no Legacy Objects should be used. These objects are already obsolete and I would bet they would not be a part of the SC Orchestrator 2012 release. Alternate functionality is available for each of these Legacy Objects (by either an existing OIS object or extensibility object potential).
Anonymous
January 01, 2003
Thanks for the reminder Jeff. I have updated the post (workaround section). :)Anonymous
January 01, 2003
You can also use objects from the Integration Pack for Data Manipulation (opalis.codeplex.com/.../46827) to work with strings that include characters such as new lines (n) - no scripting required! :)Anonymous
April 13, 2011
Charles, I have two questions, the first is that I see there is an SSH object, is there any kind of SFTP object or any way for Opalis to pull a file? The second is that I was wondering what the differences were with the Legacy objects from the newer objects with the same names? Thanks