2

We are upgrading from an older SXA for Sitecore 8.2.7 to SXA 9.3. We would like to keep the Latitude and Longitude values intact but we have hundreds of items with this data.

How can I migrate these values over using SPE to get our search working again?

1 Answer 1

2

You may notice on the IPoi items that they now inherit from the template /sitecore/templates/System/Geospatial/Coordinate. If you created custom items which inherit from this template or perhaps you used the OOTB template you should see multiple latitude/longitude fields.

Use the following script as an example on how to migrate the field data.

Example: The following finds descendant items at a specific root and then copies the field data. Here we are dealing with items representing jobs on our Career site.

# Change to the root ID for items which use the IPoi template
# Careers
#$rootId = "{B8208D4B-C25E-4381-A183-4177E47A9310}"
# POIs
$rootId = "{60365D59-F2F2-4C49-91DA-9C7B046178CF}"

# Change to the template ID of the items inheriting from IPoi
# Job
#$filterId = "{0CB1F725-2A60-49D9-8BC4-867F5FDF73FA}"
$filterId = "{6EBB38CE-04FC-425C-895B-3C81FA4A7B5C}"
$items = Get-ChildItem -Path "master:" -ID $rootId -Recurse |
    Where-Object { $_.TemplateId -eq $filterId }
    
foreach($item in $items) {
    $item.Editing.BeginEdit()
    # SXA does not have a constant available for the Latitude/Longitude fields so we use the hardcoded ID.
    $item.Fields[[Sitecore.ContentSearch.Utilities.Constants]::Latitude].Value = $item.Fields["{94969C59-C4B8-43ED-9C92-3FBF930C0ACF}"].Value
    $item.Fields[[Sitecore.ContentSearch.Utilities.Constants]::Longitude].Value = $item.Fields["{8C1AEA63-2E5E-4FEE-B413-D3B1E050DD26}"].Value
    $item.Editing.EndEdit() > $null
}

Note: Be sure to crawl all the content again now that the new fields contain data.

Bonus

Example: The following snippet shows a scriban template for the Place object using schema.org.

{{ poi = sc_follow i_page "POI" }}
<div itemscope="" itemtype="http://schema.org/Place">
  <div itemprop="geo" itemscope="" itemtype="http://schema.org/GeoCoordinates">
    <meta itemprop="latitude" content="{{ poi | sc_field "Latitude" }}">
    <meta itemprop="longitude" content="{{ poi | sc_field "Longitude" }}">
  </div>
</div>
1
  • 1
    You need it only if you have custom template for your POIs. By default there is an upgrade script which will copy field values automatically: /sitecore/system/Modules/PowerShell/Script Library/SXA/SXA - Upgrade/Functions/Upgrade Scripts/Migrate POI coordinates Jan 2 at 20:35

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.