0

I am trying to combine 6 address fields from a custom object to create one variable for one Main Address. Is it possible to combine these fields if I create one address field? New to AMPscript so trying to figure out if this is the easiest way to do this.

%%[
VAR @MainAddress, @Street,@Street2,@City,@State,@Zip,@Country
Set @MainAddress = "Main Address"
Set @Street = 'Street_1__c'
Set @Street2 = 'Street_2__c'
Set @City = 'City__c'
Set @State = 'State__c'
Set @Zip = 'Zip__c'
Set @Country = 'Country__c'

Main Address:%%=v(@MainAddress)=%%
endif
]%%
2

Looking at the fact, that you are fetching the data using RetrieveSalesforceObjects, puts everything in a different light. This function returns a rowset, meaning you have to use Row and Field functions, to get the single fields. I also assume, that you DO have the AccountID as a field in your sendable Data Extension:

%%[ 
VAR @SFRecords, @ID, @MainAddress, @Street,@Street2,@City,@State,@Zip,@Country
SET @ID = AttributeValue('AccountID') 
SET @SFRecords = RetrieveSalesforceObjects('Reservation__c','Street_1__c','Street_2__c','City__c','State__c','Zip__c','Country__c','Check_in_Address__c','Household__c','=', @ID) 
SET @SFRow = Row(@SFRecords,1)
SET @Street = field(@SFRow,'Street_1__c') 
SET @Street2 = field(@SFRow,'Street_2__c')
SET @City = field(@SFRow,'City__c')
SET @State = field(@SFRow,'State__c') 
SET @Zip = field(@SFRow,'Zip__c')
SET @Country = field(@SFRow,'Country__c')
SET @MainAddress = Concat(@Street," ",@Street2," ",@City," ",@State," ",@Zip," ",@Country)
]%%

Going beyond above explanation is not within the scope of this site, as it expects a basic understanding of programming, and helps you when you are stuck. For more details on Ampscript, I will suggest looking at Trailhead and Ampscript.guide

| improve this answer | |
  • Hi Lukas, I appreciate your quick response, I am not getting an error when I am using your formula, but I am not getting any data to populate either. I think it has to do in bringing in the data from the Custom Object, I am missing something when trying to combine them with Retrieve command. I am trying the following to get the data. The field I set up in SF is Check_in_Address__c%%[ Set @ID = AccountID ]%% %%[ RetrieveSalesforceObjects('Reservation__c','Check_in_Address__c,', 'Household__c','=', @ID) endif %%=v(@Mainaddress)=%% ]%% . Where would I incorporate your code? – Dalbanes May 28 at 20:01
  • @Dalbanes - I have updated my answer accordingly – Lukas Lunow May 28 at 20:14
  • 1
    Thanks Lukas, worked great! – Dalbanes May 28 at 21:12
0

You can make use of Concat Function in ampscript. Use it like in the below code:

%%[ 
VAR @MainAddress, @Street,@Street2,@City,@State,@Zip,@Country 

Set @Street = 'Street_1__c' 
Set @Street2 = 'Street_2__c' 
Set @City = 'City__c' 
Set @State = 'State__c' 
Set @Zip = 'Zip__c' 
Set @Country = 'Country__c'

Set @MainAddress = Concat(@Street," ",@Street2," ",@City," ",@State," ",@Zip," ",@Country)

]%%

Let me know if this helps.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.