Question

Another Expression node issue


Userlevel 7
Badge +13

Hello everyone 

 

I have this expression and I can’t get it to work 

if(regexMatch('{{ticket.description_text}}','Bifoga') && regexMatch('{{ticket.description_text}}','Övrig'),
substring('{{ticket.description_text}}', indexOf('{{ticket.description_text}}', 'Välj klockslag:',0)+length('Välj klockslag:'), indexOf('{{ticket.description_text}}', 'Bifoga',0)),
if(regexMatch('{{ticket.description_text}}','Övrig'),
substring('{{ticket.description_text}}', indexOf('{{ticket.description_text}}', 'Välj klockslag:',0)+length('Välj klockslag:'), indexOf('{{ticket.description_text}}', 'Övrig',0)),
if(regexMatch('{{ticket.description_text}}','Bifoga'),
substring('{{ticket.description_text}}', indexOf('{{ticket.description_text}}', 'Välj klockslag:',0)+length('Välj klockslag:'), indexOf('{{ticket.description_text}}', 'Bifoga',0)),
substring('{{ticket.description_text}}', indexOf('{{ticket.description_text}}', 'Välj klockslag:',0)+length('Välj klockslag:'), indexOf('{{ticket.description_text}}', 'Behandling',0))
)
)
)

I have this different test texts I like to match

Välj klockslag: 10:00-12:00 Behandling
Välj klockslag: 10:00-12:00 Övrig
Välj klockslag: 12:00-14:00 Bifoga Övrig
Välj klockslag: 12:00-14:00 Bifoga

If I test the IF expression by them they work.
If I test the substring by them self they work as well. 

Anyone have any idea why it’s not working? 


10 replies

Userlevel 6
Badge +11

Hi @daniel.soderlund --  couple of quick thoughts (a) is the simple text in the description coming in with the umlauts?

(b) I think you need to remove those highlighted , 0)) because wouldn’t that mark the end of the IF?

Whereas you need the IF to continue as nested IFs.

IF(a>b,”greater”, IF(a=b,”equal”,  IF(a<b,”less”,”end”)))

 

if(regexMatch('{{ticket.description_text}}','Bifoga') && regexMatch('{{ticket.description_text}}','Övrig'), substring('{{ticket.description_text}}', indexOf('{{ticket.description_text}}', 'Välj klockslag:',0)+length('Välj klockslag:'), indexOf('{{ticket.description_text}}', 'Bifoga', 0)),

if(regexMatch('{{ticket.description_text}}','Övrig'), substring('{{ticket.description_text}}', indexOf('{{ticket.description_text}}', 'Välj klockslag:',0)+length('Välj klockslag:'), indexOf('{{ticket.description_text}}', 'Övrig', 0)),

if(regexMatch('{{ticket.description_text}}','Bifoga'), substring('{{ticket.description_text}}', indexOf('{{ticket.description_text}}', 'Välj klockslag:',0)+length('Välj klockslag:'), indexOf('{{ticket.description_text}}', 'Bifoga',0)), substring('{{ticket.description_text}}', indexOf('{{ticket.description_text}}', 'Välj klockslag:',0)+length('Välj klockslag:'), indexOf('{{ticket.description_text}}', 'Behandling',0))

)

)

)

 

Userlevel 6
Badge +11

Actually I just noticed that maybe it’s just the {{ticket.description_text}} should be {{ticket.description}} ?

Userlevel 6
Badge +11

It sort of worked for me when I changed the order of the input values as here so they match the way the IF is running.

Välj klockslag: 12:00-14:00 Bifoga Övrig
Välj klockslag: 10:00-12:00 Övrig
Välj klockslag: 12:00-14:00 Bifoga
Välj klockslag: 10:00-12:00 Behandling

Then the output was 12:00-14:00 (pls see screenshot) but that is presumably bc that was the first matching value it came to.

Does the {{ticket.description}} come in with all this text?  Or just one of the lines above mixed in with other text?

When I replaced the other Valj lines with other text, however, the IF failed bc it’s looking for the next iteration of “Valj klockslag” to terminate the substring extract.

 

Are you trying to output the time range?

 

You could replace that length(‘Valj klockslag: ‘) with a simple numeric value i.e. +16 as here followed by the 2nd indexOf +27 so you will get the 11 chars in between.

if(regexMatch('{{ticket.description}}','Bifoga') && regexMatch('{{ticket.description}}','Övrig'), substring('{{ticket.description}}', indexOf('{{ticket.description}}', 'Välj klockslag: ',0)+16,indexOf('{{ticket.description}}', 'Välj klockslag: ',0)+27),'term not found')

 

 

Userlevel 7
Badge +13

It sort of worked for me when I changed the order of the input values as here so they match the way the IF is running.

Välj klockslag: 12:00-14:00 Bifoga Övrig
Välj klockslag: 10:00-12:00 Övrig
Välj klockslag: 12:00-14:00 Bifoga
Välj klockslag: 10:00-12:00 Behandling

Then the output was 12:00-14:00 (pls see screenshot) but that is presumably bc that was the first matching value it came to.

Does the {{ticket.description}} come in with all this text?  Or just one of the lines above mixed in with other text?

When I replaced the other Valj lines with other text, however, the IF failed bc it’s looking for the next iteration of “Valj klockslag” to terminate the substring extract.

 

Are you trying to output the time range?

 

You could replace that length(‘Valj klockslag: ‘) with a simple numeric value i.e. +16 as here followed by the 2nd indexOf +27 so you will get the 11 chars in between.

if(regexMatch('{{ticket.description}}','Bifoga') && regexMatch('{{ticket.description}}','Övrig'), substring('{{ticket.description}}', indexOf('{{ticket.description}}', 'Välj klockslag: ',0)+16,indexOf('{{ticket.description}}', 'Välj klockslag: ',0)+27),'term not found')

 

 

It’s part of a larger text so it’s one matching of many but it’s dynamic form that changes depending on the customers input.So I can’t use fixed positions.

Sorry couldn’t add more due to it’s internal for the customer. 

I’m trying to extrakt the time range yes. 

I’m using the {{ticket.description_text}} to remove all the HTML data. 
I guess {{ticket.description}} would work as well. 

 

0)), the first ) closes the second indexof function and the last one is for the substring. 

 

Userlevel 6
Badge +11

I see ty.  What I’m finding is that there is no unique terminating character or phrase that your expression can use to pull out the time range from the text.

Unless there is just a single instance of these rows in the inbound ticket?

The IF is satisfied by the first occurrence of “Bifoga Ovrig” and sends out all text between Valj klockslag:” and the next occurrence of “Bifoga” - which is Bifoga by itself.

But in that case, using the relative positions of the info between the end of “Valj klockslag:” and the start of Bifoga pulls out too much info.

Userlevel 6
Badge +11

@daniel.soderlund  - please confirm my findings - the biggest issue is that there is a bug in Expression builder@support @rashmi.nag 

Nested IF is not reading the statement correctly, it cannot find the output for the FALSE condition.  It will fail on 2 situations (1) when none of the conditions resolve to TRUE and (2) if the TRUE condition is not the last condition in the statement.

Seen here - very simple statement - IF(1<2,’true’,’false’) output = ‘true’ but when we make a nested IF the output for FALSE comes from further down the line as you can see in the example below.

 

if(1>2,'first', if(2>3,'second', if(4>3,'third','last')))

resolves correctly bc the TRUE condition is the last one

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~

if(1>2,'first', if(2<3,'second', if(4=3,'third','last')))

Throws an error bc it cannot see the FALSE output that resides in the last condition - which is the normal way to build nested IFs.

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~

if(1>2,'first', if(2=3,'second', if(4=3,'third','last')))

And when no conditions are TRUE - it throws a new error although it’s the same reason as above, the expression cannot find the output for FALSE.  The new error made it hard to figure out what was happening.

 

 

Userlevel 7
Badge +9

@prats / @Ammar KB - Could you look into this query from @daniel.soderlund and @BrynCYDEF?

Userlevel 7
Badge +13

I see ty.  What I’m finding is that there is no unique terminating character or phrase that your expression can use to pull out the time range from the text.

Unless there is just a single instance of these rows in the inbound ticket?

The IF is satisfied by the first occurrence of “Bifoga Ovrig” and sends out all text between Valj klockslag:” and the next occurrence of “Bifoga” - which is Bifoga by itself.

But in that case, using the relative positions of the info between the end of “Valj klockslag:” and the start of Bifoga pulls out too much info.

You are on it, There are 3 different scenarios and end of the matching text differ. I could do several expression nodes. I already have 20 nodes, what would another 3 do :) 

Userlevel 5
Badge +5

@daniel.soderlund I beileve you’ve raised it with our Support Team, Our best minds are working on it,

The issue looks more into the substring, I’m validating this with our Developers. I apologize for the delay, Will keep you updated in the Ticket as well as our Community Page. Thanks a lot for your patience.

Userlevel 7
Badge +13

@daniel.soderlund I beileve you’ve raised it with our Support Team, Our best minds are working on it,

The issue looks more into the substring, I’m validating this with our Developers. I apologize for the delay, Will keep you updated in the Ticket as well as our Community Page. Thanks a lot for your patience.

Ya I have ticket in the support, it’s something with the if statement and subring. 
Posted here if anyone else seen the issue as well :) 

 

//Daniel

Reply