Network Automation Software We are currently migrating this forum
over to our HelpSystems domain. Please
post all new threads in our new
HelpSystems Community Portal.
Post to the HelpSystems Forum
You are not currently logged on. You must be logged on in order to post. Log on
Or Create a new account
AutoMate Discussion
Decrease font size
Increase font size
Topic Title: Return a value based on the position of an another value in a string (array)
Topic Summary:
Created On: 10/16/2017 07:14 AM
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
View similar topics View similar topics
View topic in raw text format. Print this topic.
 10/16/2017 07:14 AM
User is offline View Users Profile Print this message

Author Icon
DorelPureca
Apprentice (20-49)

Posts: 31
Joined: 12/20/2016

Hi!

I am trying to return a value based on the position of an another value in a variable.
For example, let call this variable %Response%:

Response:
{"exports":[{"id":null,"createdAt":null,"company":{"id":"4188","corporationId":"1019","name":"Demo company"},"exportType":{"id":"8186","name":"Alser","source":"TDT","format":"HTXML","integration":false},"reportPeriod":{"id":"77775","begin":"2017-09-01","end":"2017-09-30"},"files":[]},{"id":null,"createdAt":null,"company":{"id":"488","corporationId":"109","name":"Demo company"},"exportType":{"id":"5164","name":"SH","source":"TiS","format":"HS","integration":false},"reportPeriod":{"id":"75","begin":"2017-09-01","end":"2017-09-30"},"files":[]}]}

 

So, if this variable contains "source":"TDT","format":"HTXML" I need to return the following two values:

- on the left side - return the 8186

- on the right side - return 77775

I cannot work with split, because this reponse is always different, but the order of the results is fixed. There must be something really easy to do this, but I can't find it now and I think it takes too much time.

Can anyone help? Much appreciated!!

<....>,<....>,<return this value from left>,<....>,<....>,<if this value is here>,<....>,<....>,<return this value from right>,<....>,<....>



 Category Survey
AutoMate 10 version: 10.7.0
Windows version: Windows Server 2012 R2


Edited: 10/16/2017 at 01:24 PM by DorelPureca
 10/17/2017 02:05 PM
User is offline View Users Profile Print this message

Author Icon
Alex Escalante
HelpSystems

Posts: 871
Joined: 02/26/2014

Hello Dorel,

Are you trying to replace, for example, "source" with "8186"? Or are you trying to grab the value of "source".

If you are trying to replace, you can use the replace action to look for the specific word ,"source", and replacement with any text of your choosing...

Here is more info on the replace action:

http://www.networkautomation.c...ext/Text_-_Replace.htm

 Category Survey


-------------------------

Alex Escalante | Support Analyst
AutoMate | Division of HelpSystems
HelpSystems, LLC | T: +1.213.738.1700 | F: +1.213.738.7665
 10/18/2017 12:46 AM
User is offline View Users Profile Print this message

Author Icon
DorelPureca
Apprentice (20-49)

Posts: 31
Joined: 12/20/2016

Hi,

I am not looking to replace any value.

I get this response from an API and store it in a value %varB%:

If %varB% contains "source":"TDT","format":"HTXML", then:

    Set %varA%= the text found 2 positions away on the left side of  "source":"TDT","format":"HTXML" (8186)

    Set %varC%= the text found 2 positions away on the right side of  "source":"TDT","format":"HTXML"(77775)

*the position of "source":"TDT","format":"HTXML" is not fixed, it's always different. Check the image attached, maybe is more explainatory



 Category Survey
AutoMate 10 version: 10.7.0
Windows version: Windows Server 2012 R2


Click for full image
Click for larger image



Edited: 10/18/2017 at 01:21 AM by DorelPureca
 10/19/2017 03:24 PM
User is offline View Users Profile Print this message

Author Icon
Devin Cannon
HelpSystems

Posts: 398
Joined: 03/17/2016

Hi Dorel,

This turned out to be more difficult than I thought it would be, but I created a task for you that parses these numbers.  I hope this works in every case for you.

 

Here's a summary of what the task does:

It finds text between { and }.  In this case it found 6 strings.

Loops through these strings and checks if any contain ""source":"TDT","format":"HTXML"".

If it does, then it gets the id for that string and then it gets the id of the following string as well.



 Category Survey





-------------------------

Devin Cannon | Support Analyst
AutoMate | Division of HelpSystems
HelpSystems, LLC | T: +1.213.738.1700 | F: +1.213.738.7665
 10/25/2017 10:49 AM
User is offline View Users Profile Print this message

Author Icon
DorelPureca
Apprentice (20-49)

Posts: 31
Joined: 12/20/2016

Hey Devin,

I managed to find only the number on the left, then I just put everything on pause, because finding the right one, was a bit tricky.

But now, I tested your script and fits like a glov. Much appreciated!



 Category Survey
AutoMate 10 version: 10.7.0
Windows version: Windows Server 2012 R2
Statistics
18258 users are registered to the AutoMate Discussion forum.
There are currently 0 users logged in.
The most users ever online was 5551 on 01/08/2018 at 11:11 AM.
There are currently 1815 guests browsing this forum, which makes a total of 1815 users using this forum.

FuseTalk Enterprise Edition v4.0 - © 1999-2020 FuseTalk Inc. All rights reserved.

Sitemap Network Automation Software Blog