Duplicate urlname popup fix using custom script

I had a requirement recently to make a module in which the "Title" and "UrlName" were set based on a date field. This is done in the DynamicContent Updating event automatically. So if the user typed "Bob" in as the title of a new content item it would really be changed to "2018-03-01-05-10AM" on save... physically impossible for the user to make it anything but the date.

So from there the users were to Actions->Duplicate each item and change the dates for each new years content item.

So I encountered a problem in that on duplicate the title and urlname come down EXACTLY as they are on the old item, no appending a 1 or 2 or anything. So when the user changes their date and hits save, they get a nice popup saying "This content item already exists" (because the UrlName is already taken by the item it's copied from).

If telerik is reading this... maybe please fix this logic :)

The fix I came up with is this:

  • Add script to the Duplicate view for the content item
  • Script polls the urlname field until it sees a value (callback worked)
  • Script then uses the MSAjax (🤮) to find the control and invisibly change it's value

Here is the script

You link it to the specific view by going to /Sitefinity/Administration/Settings/Advanced/ContentView then drilling down to

  • TheContentType
  • Views
  • TheContentTypeBackendDuplicateView
  • Scripts

Then simply add a new script and tell it where it lives and the method name to call after its available (I love that feature, thx guys)

AddScriptToRun

So obviously this is just one use-case but fundamentally you can run anything you want in any view, Insert, Edit, etc.

Please note this will (afaik) only work in the CURRENT < v10.2 Sitefinity, obviously the MSAjax (🤮) $find will not work in the new angular 2 system; docs aren't out on that yet.

Ready to Start?

Let's Build Something Amazing Together

Ready to bring your vision to life? We specialize in creating stunning websites, mobile apps, and digital experiences that make an impact.

Accepting new clients
Free consultation
15+ years experience