You are viewing limited content. For full access, please sign in.

Question

Question

How can I get pattern match to treat special characters within a token as normal characters?

asked on October 24, 2017

I am trying to do some pattern matching and my pattern contains a token (based on Miruna's suggestion on how to count occurrences of a value in a multi value field). 

I'm having some issues trying to successfully pattern match from the below token values, most likely caused by the use of special characters ()+[]:

  • Apple Banana (AB) Company
  • Fruit+Nut Company
  • Chocolate Coffee Company [CCC]

 

Any suggestions how I can get pattern match to treat special characters within a token as normal characters?

Thanks!! smiley

 

0 0

Answer

SELECTED ANSWER
replied on October 24, 2017

Expanding on what Miruna said you can enclose the substitutions within each other, otherwise you can end up with a lot of token copying and conditional checks.    We have had to use this approach a few times.

Might try this in your expression:
SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(%(ForEachValue_Current Value),"(","\("),")","\)"),"[","\["),"]","\]"),"+","\+")

 

2 0

Replies

replied on October 24, 2017

You could run the current value token through a Token Calculator activity to replace each one of those reserved characters with their escaped values ("\(", "\[", etc).

2 0
replied on October 24, 2017

Hey,

Figured id throw in my 2 cents as well.

You should be able to achieve the results you are looking for using the SDK script. See below:

namespace WorkflowActivity.Scripting.SDKScript
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using Laserfiche.RepositoryAccess;
    using System.Linq;

    /// <summary>
    /// Provides one or more methods that can be run when the workflow scripting activity is performed.
    /// </summary>
    public class Script1 : RAScriptClass100
    {
        /// <summary>
        /// This method is run when the activity is performed.
        /// </summary>
        protected override void Execute()
        {
            List<object> values = this.WorkflowApi.GetTokenAsMultiValue("Values");
            string CountVal = this.WorkflowApi.GetTokenValueFromNameAsString("CountVal",0);
            Dictionary<string, int> dictionary = new Dictionary<string, int>();
            dictionary.Add(CountVal,0);
            foreach (string val in values)
            {
                if (dictionary.ContainsKey(val))
                {
                    dictionary[val] += 1;
                }
                else
                {
                    dictionary.Add(val,1);
                }
            }

            this.WorkflowApi.SetTokenValue("Count",dictionary[CountVal]);
            // Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session
        }
    }
}

Using this code is easy. Change ("Values"); to whatever the name of the multivalued token with the values is. Then create 2 new tokens one named "Count" and one named "CountVal". Basically assign "CountVal" the value you want counted and then call the SDK script, the script will count the values and assign the result to the "Count" token.

Just another option for you :)

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.