I wrote a code that reads that xml data and extracts all the values, separate the First Name from the Last Name and updates the DE, but I am still getting an error:
"Invalid index (parameter 2) passed to Row function. Index must be less than or equal to the row count.Index Value: 1 Row Count: 0 Function: Row(@customers,1)"
Can you please tell me what did I do wrong - I am struggling with this since yesterday.
%%[
var @xml
set @xml = ""
set @xml = concat(@xml, '<Customers>')
set @xml = concat(@xml, ' <Customer_CustomerID="1235">')
set @xml = concat(@xml, ' <CompanyName>AMO Food Market</CompanyName>')
set @xml = concat(@xml, ' <Industry>Retail</Industry>')
set @xml = concat(@xml, ' <ContactName>Anne Mollin</ContactName>')
set @xml = concat(@xml, ' <ContactTitle>Marketing Manager</ContactTitle>')
set @xml = concat(@xml, ' <Email>[email protected]</Email>')
set @xml = concat(@xml, ' <FullAddress>')
set @xml = concat(@xml, ' <Address>2732 Daver Str.</Address>')
set @xml = concat(@xml, ' <City>Bandie</City>')
set @xml = concat(@xml, ' <Region>OR</Region>')
set @xml = concat(@xml, ' <PostalCode>94215</PostalCode>')
set @xml = concat(@xml, ' </FullAddress>')
set @xml = concat(@xml, ' </Customer>')
set @xml = concat(@xml, ' <Customer CustomerID="1986">')
set @xml = concat(@xml, ' <CompanyName>Folimi Tires</CompanyName>')
set @xml = concat(@xml, ' <Industry>Cars</Industry>')
set @xml = concat(@xml, ' <ContactName>Adrian Moods</ContactName>')
set @xml = concat(@xml, ' <ContactTitle>Sales Representative</ContactTitle>')
set @xml = concat(@xml, ' <Email>[email protected]</Email>')
set @xml = concat(@xml, ' <FullAddress>')
set @xml = concat(@xml, ' <Address>City Mall 100 Main St.</Address>')
set @xml = concat(@xml, ' <City>Dondie</City>')
set @xml = concat(@xml, ' <Region>OR</Region>')
set @xml = concat(@xml, ' <PostalCode>93210</PostalCode>')
set @xml = concat(@xml, ' </FullAddress>')
set @xml = concat(@xml, ' </Customer>')
set @xml = concat(@xml, '</Customers>')
set @customers = BuildRowsetFromXml(@xml, "Customers", 1)
set @CustomerID = Field(Row(@customers,1),"CustomerID_att")
set @companyNames = BuildRowsetFromXml(@xml, "Customer/CompanyName", 1)
set @companyName = Field(Row(@companyNames,1),1)
set @industries = BuildRowsetFromXml(@xml, "Customer/Industry", 1)
set @industry = Field(Row(@industries,1),1)
set @contactNames = BuildRowsetFromXml(@xml, "Customer/ContactName", 1)
set @full_name = Field(Row(@contactNames,1),1)
set @emails = BuildRowsetFromXml(@xml, "Customer/Email", 1)
set @email = Field(Row(@emails,1),1)
set @addresses = BuildRowsetFromXml(@xml, "Customer/FullAddress/Address", 1)
set @address = Field(Row(@addresses,1),1)
set @cities = BuildRowsetFromXml(@xml, "Customer/FullAddress/City", 1)
set @city = Field(Row(@cities,1),1)
set @regions = BuildRowsetFromXml(@xml, "Customer/FullAddress/Region", 1)
set @region = Field(Row(@regions,1),1)
set @postalCodes = BuildRowsetFromXml(@xml, "Customer/FullAddress/PostalCode", 1)
set @postalCode = Field(Row(@postalCodes,1),1)
if indexOf(@full_name, " ") > 0 then
set @first_name = substring(@full_name,1,subtract(indexOf(@full_name," "),1))
set @last_name = substring(@full_name, add(indexOf(@full_name," "),1),length(@full_name))
endif
UpsertDE("AMPscript Functions 3 - v2",1,"xml",@xml,"email",@email,"firstname",@firstname,"lastname",@lastname)
UpsertDE("AMPscript Functions 3 - v2",1,"xml",@xml,"companyname",@companyName,"industry",@industry,"address",@address,"city",@city)
UpsertDE("AMPscript Functions 3 - v2",1,"xml",@xml,"region",@region,"postalcode",@postalCode, "customerID", @customerID)
]%%