How to add an integer to GetIndexOf operation in Define Varibale action

Is it possible to add an integer value to GetIndexOf in Define Variable action step in a workflow? The issue is I’m trying to get an index position of starting number i.e. ‘1’(this can vary). I’m able to get the index of ‘-’, to this I need to add +2. For example, the index of ‘-’ is 4 now I need to add +2 which will become 6. If adding a value is not possible, is there any other way directly to get the index of ‘1’?

ABC - 123456789

@JackSparrow

I am not sure what we are trying to achieve here . Could you help me understand it more clearly .

Hi Theja,

I don’t think numeric math is possible, but there is another way to work your problem. You can use regular expressions with the “Get Index” transform in the Define Variable Operator.

Assuming the pattern you have given as an example is ALWAYS followed, the simplest way to do this is to look for the position of the first digit ‘\d’ character class:

Code for the “Advanced” view:

{
  "name": "StringPos",
  "description": "",
  "transforms": [
    {
      "id": "sp:transform:getIndex:int",
      "input": {
        "pattern": "\\d"
      }
    }
  ],
  "variableA": "ABC - 123456789"
}

If you can’t guarantee the pattern:
<All_alphabetic> - <Numeric>
Then you may need to do more complicated things (Unfortunately, AFAICT from my testing, more complicated regular expressions like those using lookbehind don’t work) but let me know if this solves your issue.

@vsandhu1 , sorry for the confusion. Need to get the index of first character after ‘-’ for below examples.

3Series M - c85b3a2d7e5d46adb794b65437e14837
4Series C - f85b3a2d7e5ru466adb794b65437e1nf8

I have tried \d , but it’s giving me the index of starting number. Also, I have tried, -\s*, but this is giving me the index of ‘-’

@colin_mckibben @tyler_mairose Is this something you can help me with?

@sidharth_tarlapally I want to get the index of first character after ‘-’ for below examples. We are trying this in define variable action step in workflow.

3Series M - c85b3a2d7e5d46adb794b65437e14837
4Series C - f85b3a2d7e5ru466adb794b65437e1nf8

@JackSparrow

If my understanding is correct ,

We are getting index value using Get Index in Define Variable , Lets Say
Value is ABC-123 , and current Get Index Gives 3

The requirement is that we want the index number of character which is next to the specified pattern character , i.e index of value 1 for the given example ABC-123 , which should be 4

So now , we either should able to add the integer with 1 or get directly the index value . but we cannot do it with available operators

Workaround

As we need the right next character index what we can do Is :

  • Define Variable A - Your Original Value ABC-123
  • Define Variable B - A static Text Value “Z” Z
  • Define Variable FinalString - Contact Variable A and Variable B gives ZABC-123

Now that we have an extra character preceding to original string , when we call :
getIndex of - for FinalString ZABC-123 it would give 4, which is our desired output .

Hope this helps .

Thanks
Sid

Thanks @sidharth_tarlapally . I know this helps for ABC-123 example. But in my case the text which is before " -" will not always be constant.

Example:
Sometimes it will be, 3Series M - c85b3a2d7e5d46adb794b65437e14837
Sometimes it will be, 4Series CAM - f85b3a2d7e5ru466adb794b65437e1nf8

In this case it will fail

Hello @JackSparrow

Let’s consider your example:

3Series M - c85b3a2d7e5d46adb794b65437e14837
getIndex('-') = 10, but the expected value is 11.
Now, by prefixing the string with 'A':

A3Series M - c85b3a2d7e5d46adb794b65437e14837

getIndex('-') becomes 11, which matches the expected value.

Similarly, for:

4Series CAM - f85b3a2d7e5ru466adb794b65437e1nf8
getIndex('-') = 12, but the expected is 13.
After adding 'A' at the beginning:

A4Series CAM - f85b3a2d7e5ru466adb794b65437e1nf8

getIndex('-') becomes 13, as expected.

Unless I’ve misunderstood the requirement, this method isn’t dependent on the total number of characters in the string. Since the goal is always to find the index immediately after the hyphen (-), and indexing starts at 0, we’re simply shifting the position by prepending a character before the hyphen.

1 Like

It really helped. Thanks a lot @sidharth_tarlapally . It would be good if SailPoint support complex regex pattern in workflows particularly for “GetIndexOf” operation in Define Variable step.

Agreed. I opened an idea for that after I saw your question. Please vote on it:
Add support for Regular expression lookahead | SailPoint Ideas Portal

1 Like

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