String Parsing Using a Filter Guide

Version 1
    Share This:

    This week's theme:  Cool Tech Tips
    This topic was recommended by a member of the AR System Developer Community.

     

    String Parsing Using a Filter Guide

    Recently, I encountered a situation where I needed to do some simple string tokenizing and parsing using filters. I knew I needed a solution where some kind of looping mechanism can be supported. Since I needed to do the same kind of string tokenizing repeatedly, I realized that nothing does that better than a filter guide. Here's how I accomplished my task using a simple filter guide.

     

    The Task

    I have a string that's separated by semicolons (;), and I would like to parse this string and tokenize it using the semicolon as the delimiter. For example, if I was given the string:

    xx;yy;zz;

    I'd like to be able to render them individually in separate rows and use them to my advantage. Example:

    xx 
    yy 
    zz 
     

    The Solution

    First, identify which steps are needed to parse the string and tokenize it. Then, identify which steps will be repeated. The repeatable steps can be addressed using a filter guide.

    1. Copy the given string to a temporary location.
    2. Using the semicolon (;) as the delimiter, note the position of the first semicolon.
    3. Retrieve the part of the string up to the semicolon identified in step 2.
    4. Repeat step 2 and 3 for the remainder of the string.

    These steps provide you with how the filter guide will flow. Next, create the fields and filters for the filter guide.

     

    Form Creation

    1. Create a basic form, called Parser.
    2. Add the following fields:
    • Position (Integer, Display Only) holds temporary data, can be hidden
    • Item (Character, Display Only, 255) holds temporary data, can be hidden
    • Temp data (Character, Display Only, 255) holds temporary data, can be hidden
    • Data (Character, 255)
     

    Filter Creation

    1. Parser:Copy Data
      Form: Parser
      Execute On: None
      Note: Filters that execute via a filter guide will not have any Execute On condition.
      Run If: None

      If Action: Set Fields
      Name: Temp data
      Value: $Data$
    1. Parser:Get Position
      Form: Parser
      Execute On: None
      Run If: None

      If Action:  Set Fields
      Name: Position
      Value: STRSTR($Temp data$, ";")
    1. Parser:Get Item
      Form: Parser
      Execute On: None
      Run If: 'Position' > ( - 1)

      If Action: Set Fields
      Name Item
      Value: LEFT($Temp data$, $Position$)

    If Action: Set Fields
    Name: Temp data
    Value: RIGHT($Temp data$, (LENGTH($Temp data$) - $Position$) - 1)
    Message: Text: $Item$
    Type: Note
    Number: 10000

    Go To Guide Label
    Guide Label: Start (this will make sense when we reach the Filter Guide creation)

     

    Filter Guide Creation

    Name: Parser
    Form Name: Parser

    Add the filters created in the previous step to the right pane in the following order:

    1. Add "Parser:Copy Data"
    2. Add Label "Start"
    3. Add "Parser:Get Position"
    4. Add "Parser:Get Item

    The final step is to create a filter that calls the filter guide.

     

    Entry Point Filter Creation

    Parser:Call Guide
    Form: Parser
    Execute On: Submit, Modify
    Run If: None
    If Action:
    Call Guide: Parser

     

    Result

    Submit an entry in the Parser form. Enter "xx;yy;zz;" in the Data field. You will receive a Message stating:

    zz (ARNOTE 10000)
    yy (ARNOTE 10000)
    xx (ARNOTE 10000)

    By creating a form, filters, a filter guide, and calling the guide, you can successfully parse a string and tokenize it via its delimiters.

    ~ Jiani C.
    Staff Product Developer, CMDB Team
    Joined Remedy in 1999