Skip to main content
Question

Workflow Automation - Converting string to number to perform logical operations

  • February 21, 2025
  • 6 replies
  • 60 views

Forum|alt.badge.img

Hello,

I am attempting to setup an automation in the asset module that updates the current location of a unit based off the IP address reported by the asset agent.

The IP address field is parsed as a string initially, and I am performing an operation to extract the third octet. In my environment, every 10 digits in the third octet is a different location, so if I can determine the third octet is within the range of a site, I can assign the current location of the device. 

How can I convert a string type to a number type, for the purposes of performing logical operations within the workflow orchestrator?

With the current logic I have built out, I am extracting the third octet of the IP address which gives me a 1-3 digit string, I need to be able to perform less-than operations on that string to determine the location to update the asset. How can I do that? Currently, the program rejects that as the result of that expression builder block is a string. 

 

Thank you

Did this topic help you find an answer to your question?

6 replies

RobCrossHM
Skilled Expert
Forum|alt.badge.img+8
  • Skilled Expert
  • 98 replies
  • February 24, 2025

@DDave - you’ve posted in the FreshDesk group - you’ll have more joy in the relevant FreshService group.


Daniel Söderlund
Skilled Expert
Forum|alt.badge.img+14
DDave wrote:

Hello,

I am attempting to setup an automation in the asset module that updates the current location of a unit based off the IP address reported by the asset agent.

The IP address field is parsed as a string initially, and I am performing an operation to extract the third octet. In my environment, every 10 digits in the third octet is a different location, so if I can determine the third octet is within the range of a site, I can assign the current location of the device. 

How can I convert a string type to a number type, for the purposes of performing logical operations within the workflow orchestrator?

With the current logic I have built out, I am extracting the third octet of the IP address which gives me a 1-3 digit string, I need to be able to perform less-than operations on that string to determine the location to update the asset. How can I do that? Currently, the program rejects that as the result of that expression builder block is a string. 

 

Thank you

if you get a number value you should be able just select the output as number in the expression. 

Else you could try to add another expression add just the placeholder from the first and use the output number. no operation needed. then in the third you you create create number expression. 

 

@Kamakshi V please move this post 


Forum|alt.badge.img
  • Author
  • Apprentice
  • 2 replies
  • February 25, 2025

Thanks for the help. I am still having difficulties. Here is my logic-

  1. Trigger- asset updated
  2. Asset field.asset type is computer
  3. R1 - Retrieve extended asset details
  4. P3 - Computer Asset JSON fields
  5. E11 - String output (IP fields from JSON is string)
    substring(replace({{P3.root.computer_ip_address_32000239849}},'192.168.',''),0,indexOf(replace({{P3.root.computer_ip_address_32000239849}},'192.168.',''),'.',0))
  6. E13 - Convert to number, number output:  {{E11.result}}
  7. E12 - String output: if({{E13.result}} <= 10, '01_Center_Services', 'error')

    Step 7 seems to be giving me an operand error even with E13 as numerical output and a numerical placeholder value. If I remove {{E13.result}} and use a digit, it works as expected. 

Daniel Söderlund
Skilled Expert
Forum|alt.badge.img+14

it’s xx in 192.168.xx.yy you like to verify if it’s equal or lower then 10 ? 

Try this 

if ({{placeholder | remove: ‘192.168.’ | split: ‘.’ | first }} <= 10,’01_Center_Services’,’error’)

 


Forum|alt.badge.img
  • Author
  • Apprentice
  • 2 replies
  • February 25, 2025

Still reports an invalid operand when using your logic. I am pretty sure that because the IP address field is returning as a string (and we’re performing operations on it as a string), it isn’t directly comparing in mathematical operations.

I have sites going up to x.x.200.x.  My plan is to build out the IF logic such as 

IF(y<= 20, ‘Site 1’, if(y<= 30, ‘Site 2’, if(y<=40, ‘Site 3’, (and so on)))) 

(I don’t have a 0-10 site so 10-19 is our primary site. The leading digit of the third octet is effectively our site location code)


Daniel Söderlund
Skilled Expert
Forum|alt.badge.img+14
DDave wrote:

Still reports an invalid operand when using your logic. I am pretty sure that because the IP address field is returning as a string (and we’re performing operations on it as a string), it isn’t directly comparing in mathematical operations.

I have sites going up to x.x.200.x.  My plan is to build out the IF logic such as 

IF(y<= 20, ‘Site 1’, if(y<= 30, ‘Site 2’, if(y<=40, ‘Site 3’, (and so on)))) 

(I don’t have a 0-10 site so 10-19 is our primary site. The leading digit of the third octet is effectively our site location code)

if (substring('{{placeholder | remove: '192.168.' | split: '.' | first }}',0,1) <= '1','01_Center_Services','error')

I’m using Introduction – Liquid template language and expression in one go but I would use a custom object. So get the digit output in a expression and the filter that in the custom object. 

substring('{{placeholder | remove: '192.168.' | split: '.' | first }}',0,1)

The in the custom object you have one field for the digit and another with site name. In that way you make it more dynamik.  

I think you need to do some counting as well. How many digits it’s in the octet. If you need more then 
Something like this. 

if(length('{{placeholder | remove: '192.168.' | split: '.' | first }}') == 2,substring('{{placeholder | remove: '192.168.' | split: '.' | first }}',0,1),substring('{{placeholder | remove: '192.168.' | split: '.' | first }}',0,2))

 


Reply