Select to view content in your preferred language

Cloning portal webmaps

1255
3
06-25-2017 09:06 PM
JanRoggisch1
Emerging Contributor

I have used the "Clone Portal users, groups and content" example as a starting point for migrating content from one portal to another. As per the example, I start with users, then groups, and then items. Most items (layers, folders etc.) are copied fine, but there is a number of webmaps that throw an error:  Invalid JSON in 'text' parameter.
Inspecting the 'copy_item' method a bit more closely I noticed that the webmaps that fail all seem to have in common that some of their popups contain HTML elements, e.g. "description": "<div style=\"text-align: center;\"><b>{GS_NAME}</b><br... , whereas none of the webmaps that were successfully copied do.

When I run a string downloaded from the source portal using item.get_data(False) through JSLint it passes, but when I then attach this to the target item's text property and post to the target portal, I get the above error. Has anybody come across this and was able to come up with a fix? Trevor Hart‌ and Fraser Hand‌, I've been told you might be able to help with this?

0 Kudos
3 Replies
TrevorHart2
Deactivated User

Jan, its very likely that the sample is not encoding (ie escaping) the HTML for the popup.

What I would do is look at the ArcGIS Online Assistant  tool and see what it does to the JSON when it clones a web map.

You can escape text for JSON using this online tool Free Online JSON Escape / Unescape Tool - FreeFormatter.com 

When I looked at your small sample text the break element </br> should be <\/br>

0 Kudos
JanRoggisch1
Emerging Contributor

Thanks for the quick reply Trevor. I did try escaping the HTM both manually (string.replace()) and automatically using the json module,but to no avail. I'll give it another crack with a fresh mind tomorrow and then also try the ArcGIS Online Assistant again. This didn't work for me today (as in no items were displayed after logon/search), and it seemed to be to do with portal being locked down using Windows AD - even though this should work as far as I can tell. 

I'll post any updates as and when they happen.

0 Kudos
JanRoggisch1
Emerging Contributor

After trying various other things I still haven't got a solution, but a better idea of which bits of the webmap make things fail. The HTML inside a webmap's JSON file pulled from the 10.3 portal using the item.download() method is already properly escaped as far as I can tell, but the way it is escaped is different to how this works in 10.5. Example:

10.3: color=\"#0000ff\"

10.5 : color='#0000ff'

This could of course easily be dealt with using find/replace on the way, but the real issue seems to be with popups that have URI links in them (href), especially if these are using a protocol other than http. The way we found out about this was by opening the same popup for editing in both portals, and then doing a copy/paste of the popup config from the old portal to the new one. When comparing both webmaps' JSON in ArcGIS Online assistant afterwards, we find the following:

10.3: href=\"myapp://path/action=....

10.5: href='#path/action=...

This has be scratching my head as there is no pointer to what '#' resolves to in the webmap (but the links are resolved correctly when clicking on them in the popup!). I'm not JavaScript expert so may be missing a trick here, but to me it looks a lot as though the webmap JSON doesn't store all the information used by portal to make sense of the URI. 

What it means for us is that we'll have to strip out all links from our popups during the scripted part of the migration, and then manually fix them later using the process described above. Not ideal, but I can't see any other way.

Any thoughts and comments on this would be much appreciated, ideally something that tells me I'm simply doing it wrong so that I can learn how to do it right 🙂 

0 Kudos