• DOCUMENTATION
  • WORKATO BLOG
  • PRODUCT BLOG
  • Return to Workato
  • Log in
  • ☰
  • Community/Discussions
New Topic
Discussions Enhancement Requests Application Enhancements
H

Himanshu Sharma

started a topic 24 days ago

Appending in a String variable

Hello,

I feel Workato variable's usability will extend greatly if there is an ability to

do the following:

      STRING XYZ //initialized with value or blank.
      
      LOOP OVER SOME ARRAY/OBJECT
              {
                  Append Values From ARRAY/OBJECT to the VARIABLE STRING
              }
      
      //Variable XYZ has the values appended to it

e.g

      STRING XYZ;
      ARRAY ABC = [1,'a','6',24,'pqr'];
      
      LOOP OVER ARRAY ABC
          {
              XYZ.append(ABC[i]); //i is the index of loop, will range from 0 upto the length of array(5)
              
                      OR
                      
              XYZ = XYZ + ABC[i]; //i is the index of loop, will range from 0 upto the length of array(5) 
          }
         
      //Variable XYZ becomes = '1a624pqr';

 ;

This use case is quite common & is supported in various platforms/prog languages.

Suggestions/Discussions please?

Thank you.   

 

 

 

 

 

m

mitchel

said 18 days ago

You can already do this if you initialise the string variable before your loop, see https://app.workato.com/recipes/2436692?st=7cce2c for example


1 person likes this
H

Himanshu Sharma

said 18 days ago

That is a good solution, Thank you. 

But it may not work for a nested data structures?

 

{

	"response": {
		"sOverviews": {
			"count": 18,
			"ErList": [
                {
					"Id": '111-SDF-XCD',
					"Overview": {
						"UpdateTime": "2022-05-03",
						"ThisTimeData": {
							"energy": 58
						},
						"YearData": {
							"energy": 255
						},
						"MonthData": {
							"energy": 48
						},
						"DayData": {
							"energy": 0
						},
						"currentPower": {
							"power": 0
						},
						"measuredBy": "Decoy"
					}
				},{
					"Id": '111-SDF-XCD',
					"Overview": {
						"UpdateTime": "2022-05-03",
						"ThisTimeData": {
							"energy": 58
						},
						"YearData": {
							"energy": 255
						},
						"MonthData": {
							"energy": 48
						},
						"DayData": {
							"energy": 0
						},
						"currentPower": {
							"power": 0
						},
						"measuredBy": "Decoy"
					}
				},{
					"Id": '111-SDF-XCD',
					"Overview": {
						"UpdateTime": "2022-05-03",
						"ThisTimeData": {
							"energy": 58
						},
						"YearData": {
							"energy": 255
						},
						"MonthData": {
							"energy": 48
						},
						"DayData": {
							"energy": 0
						},
						"currentPower": {
							"power": 0
						},
						"measuredBy": "Decoy"
					}
				}
.... so on 
]
}
}
}

 
This is a JSON response of a HTTP connector, "ErList" is a nested array of objects. Each object has index "Overview" which is an object containing various objects. 

I am trying to loop over "ErList" & create a string like:

 

ErList[1][Id] + ErList[1][Overview][ThisTimeData][energy] + ErList[1][Overview][currentPower][power]+'\n' 

ErList[2][Id] + ErList[1][Overview][ThisTimeData][energy] + ErList[2][Overview][currentPower][power]+'\n' 

ErList[3][Id] + ErList[1][Overview][ThisTimeData][energy] + ErList[3][Overview][currentPower][power]+'\n' 

... so on for all the contents of the array

 
attached is the file containing the entire result of HTTP connector.


txt
nestedjson.txt
(6.31 KB)
m

mitchel

said 17 days ago

See the recipe again for updates demoing how to use a for loop selecting the ErList as your input list to loop over (in your case I believe steps 2/3 would be replaced by the htttp connector (so long as you've specified the output schema.

Login to post a comment

Still can't find your solution?

Send us a ticket, we will try our best to assist you with your problem

Documentation
Developer's Library
Tutorials
eBooks
Product Hour
Product Blog
Workato Blog
Product updates
Customer Stories
© Workato 2020   Privacy   Terms   +1 (844) 469-6752
  • Documentation
  • Workato Blog
  • Product Blog
  • Solutions
  • Forums
  • Tickets
  • Log in
  • Return to Workato