Get the Case ID From the body of an email using substring

Hi,

I am after a bit of assistance, please. I am trying to create a decision in a flow to grab a case ID which is always 15 characters long.

The email will contain something like this Case ID: xxxxxxxxxxxxxxx

Currently In my decisions expression, I have got the following but I do not know how to add the substring function to the below to capture the case ID.

If(IsSet(Email.Message.body), Contains(Email.Message.body, "Case ID"), false)

Are you able to assist me, please. Does the above work or should I be using findString instead?

If(IsSet(Email.Message.body) AND Contains(Email.Message.body, "Case ID: "),
Trim(Substring(Email.Message.body, FindString(Email.Message.body, "Case ID: "), 24)),
"no id")

Notice this returns a string value instead of a boolean.
Decide what you want to do if the body doesn't include the case id; in this example I set it to "no id". You could also set it to NOT_SET or some dummy value.

Hello @Chris_Carr,

I tried to implement one way of grabbing a Case ID from the body of an inbound email and below how I imagined it :blush:

I used a simple email including a Case ID in the body as the following:

image

Below, the Inbound Email Flow I used with the explanations:

The first step is to extract or select the keyword Case ID out of the body.
To do so, you can use the combination of 2 built-in functions in Architect:

FindString : returns the location of a specified occurrence of a String within a String.
Substring : gets part of a String that starts at a specified position and has the specified length.

In your example, you need to search for the keyword "Case ID: ".
At the beginnig of the flow, I created a variable called Flow.keyword that has a value of "Case ID: "

FindString(Email.Message.body,Flow.keyword)

where :
Email.Message.body is the Email body as plain text.
Returned Value is an Integer (zero-based index)

image

Once you have the index of the Case ID string, you can use it inside the Substring function as the following to extract only the ID :

Substring(Email.Message.body,Flow.keywordPosition+Length(Flow.keyword), 15)

This function takes 3 parameters :

String text : The source String from which the substring will be taken (Email.Message.body)

Integer start : The starting position of the String in the text parameter. The first position is 0.

Integer length : The length of the desired substring.

In our example, the Integer Start will be Flow.keywordPosition+Length(Flow.keyword)

Where :
Flow.keywordPosition : the position of the Case ID string inside the email body, then we add the length of the keyword (Case ID: ) to not include it when we grab the ID

Since you mentioned that the length of the Case ID will be always set to 15, then we put this value to make sure we cover the entire ID and not miss any digit :blush:

That’s it !

I added a decision block to check whether the keyword Case ID is included in the body or not.

So, if the body doesn’t contain any ID, I just set the Case ID to N/A, maybe you can display it later on a script for agents.

Results:
Case ID included in the email body:

Case ID not included in the email body:

I hope that answers your question :slight_smile:

Kind Regards,

Charaf

3 Likes

Hello,

Thank you very much for this. This is exactly what I required and will implement it today and test.

I appreciate the explanation to each step of the process :slight_smile: This was amazing.

Thank you.

Kind Regards,

1 Like

Hi,

I am receiving an invalid value for the expression below, is there something I have missed?

image

image

Thank you.

I have changed Flow.keywordPosition to an integer value, however, I could not name it Flow.keywordPosition and named it State.keywordPosition

Hello Chris,

The issue is related to the type of the variable Flow.keywordPosition. I believe it was declared as string.
In your decision block you are trying to compare a string against an Integer.

You can either :

  • Convert the string variable using ToInt(Flow.keywordPosition) == -1
    or
  • Delete the variable and recreate a new one with type of Integer.

Kind Regards,

Charaf

The issue you are running into is because the variable is referenced in other places in your Email Flow.

Try first to delete it from all the tasks, functions... Then recreate a new one with type of Integer.

You can check this info in Data section under Ressources to find where the Flow.keywordPosition is referenced

I hope that helps :slight_smile:

Charaf

1 Like

Thank you very much :slight_smile: will confirm how I get on.

My pleasure ^^

Let me know if you have any questions :slight_smile:

Charaf

Just to confirm as promised. I managed to get it working with your help, thanks again! Much appreciated :slight_smile:

Awesome :slightly_smiling_face:

I’m glad it’s working as you expected !

Kind regards,

Charaf

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.