Workflow and ServiceDesk Community

 View Only

Using Code Script Component with regex pattern (Workflow) 

Apr 21, 2016 12:45 PM

I had the challenge to group mobile devices into mobile phone or tablets. For example, for Apple devices this was quite easy because the model either contains iPhone or iPad. However, looking at the model of Samsung devices this looks different. Here some examples:  

samsung GT-P5210

samsung SM-G25F

samsung SM-G920F

samsung SM-G900F

samsung GT-I9506

I directly thought I can use Regex pattern to tackle the grouping however, I did not find a way to have the possibility of having a dynamic list of patterns in case new models are released and I do not want to open the workflow and republish it every time when an update comes out.

So I thought I might be able to use a list outside of workflow which I can go in and edit and this list I read within the workflow.

To read the list is one thing the other thing is to build the pattern from that list. Again this seems not something I could do with the built in “pattern” components. That is why I choose the Code Script component. The code script component now reads the list builds the pattern and does the matching.

Here the Workflow:

regex_1.png

Here the Script (Code) Component:

regex_2.png

Here the code:

regex_3.png

 

Here the input list:

regex_4.png

And here the result:

regex_5.png

 

And if I update the list:

regex_6.png

The result be like this:

regex_7.png

 

Find the demo attached.

Statistics
0 Favorited
2 Views
1 Files
0 Shares
1 Downloads
Attachment(s)
zip file
RegexPattern.zip   858 KB   1 version
Uploaded - Feb 25, 2020

Tags and Keywords

Related Entries and Links

No Related Resource entered.