Workflow Automation - Converting string to number to perform logical operations
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
Page 1 / 1
@DDave - you’ve posted in the FreshDesk group - you’ll have more joy in the relevant FreshService group.
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
Thanks for the help. I am still having difficulties. Here is my logic-
Trigger- asset updated
Asset field.asset type is computer
R1 - Retrieve extended asset details
P3 - Computer Asset JSON fields
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))
E13 - Convert to number, number output: {{E11.result}}
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.
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’)
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
(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)
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
(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))