35
Views
9
Comments
Solved
How to break a variable into multiple new variables (Street Address, City, State)
Question
Application Type
Reactive
Service Studio Version
11.53.41 (Build 62020)

How can I take a LOCAL VAR (GoogleAddress) and break it into three new SUB VARs (STREET, CITY, STATE) so that I can execute a CRUD from a GOOGLE PLACES result. 

My current screens local VARs are:

  • GoogleAddress = Full Address
  • Address = house# and street
  • City = City
  • State = State

I am using google places to lookup and identify an address and storing the result in a local var "GoogleAddress" I want to take the data from GoogleAddress VAR and use the comma "," as a delimiter to take a full address such as (123 Main Street, Brooklyn, New York, USA) and assign the respective data to each of the following SubVAR...

  • (VarADDRESS= 123 Main Street )
  • (varCity= Brooklyn)
  • (varState=New York)

I have tried java but cannot not assign the JS output to my local vars (Address,City,State) based on the debugger monitoring the local vars values :(


Here is the JS that ChatGPT gave me:

  1. // Declare and initialize the local text variableGoogleAddress = "1600 Amphitheatre Parkway, Mountain View, CA";
  2. // Split the GoogleAddress string based on the comma deliminator
  3. var addressParts = GoogleAddress.split(',');
  4. // Assign the subparts to their respective variables 
  5. var Address = Address;
  6. var City = City;
  7. var State = State;
  8. // Output the results
  9. console.log(Address);
  10. console.log(City);
  11. console.log(State);

Thank you for any support on this one!

2024-11-25 22-05-29
Sergio Aznar Guallar
Solution

To get more specific, also you have the option to use String_split function that splits text by a delimiter that you choose. So in your case, a delimiter could be a comma, that i see what is delimiting your googleaddress variable.


Kind regards,

Sergio

2024-11-25 22-05-29
Sergio Aznar Guallar

Hi Josep,

you can achieve it just by using the substring function, in an assign node of a client action assign the new variables to a substing of the googleaddres variable. 

For more information check its documentation:

https://success.outsystems.com/documentation/11/reference/outsystems_language/logic/built_in_functions/text/#Substr

hope it helps


Kind regards,

Sergio

2024-11-25 22-05-29
Sergio Aznar Guallar
Solution

To get more specific, also you have the option to use String_split function that splits text by a delimiter that you choose. So in your case, a delimiter could be a comma, that i see what is delimiting your googleaddress variable.


Kind regards,

Sergio

2023-07-13 14-19-38
Joseph Funaro

Thank you for  your suggestions - much appreciated. I have made progress. 

Follow up question - How do ASSIGN the resulting TEXT values returned from the splitting action to my local variables [ADDRESS, CITY, STATE]. I am new to OS and not sure where exactly I can consume the resulting data. In the expression builder I do not see the resulting list or structure to use in a assign. Am I over complicating it?

My DEBUG results: 

I am not seeing how I can make use of the values in the resulting structure list? My SPLIT action should consistently result in 4 list items = Address, City, State, ZIP, Country.


Thank you again for your quick reply!


2024-11-25 22-05-29
Sergio Aznar Guallar

you can select the text postion of the list instead of current, check image:


Kind regards,

Sergio

2023-07-13 14-19-38
Joseph Funaro

I tried that and this was the result... Do I have the wrong data type on my var?

2024-11-25 22-05-29
Sergio Aznar Guallar

just remove ".current" from the assigns, check closely my images :D

2023-07-13 14-19-38
Joseph Funaro

Thank you very much - I caught my mistake. The results are now as expected!

The Message below is a result of SplitString: 

"Address: "+String_Split.List[0].Text.Value+" City:"+String_Split.List[1].Text.Value+" State:"+String_Split.List[2].Text.Value+" Country:"+String_Split.List[3].Text.Value

This is what I needed - thank you for your assistance that was VERY helpful for me today. 

Have a great weekend! 

- Joe

2024-11-25 22-05-29
Sergio Aznar Guallar

Great, glad to help you...and dont worry about the mistake I went through the same thing with this when I first used it xd

Have a nice weekend :)

2023-07-13 14-19-38
Joseph Funaro

The documentation online for SplitStr and SubStr are not great for amateurs like me. 

Thanks!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.