Buttons, Buttons, Buttons.How to create a Sp 2013 Javascript button to create a new doc

6 04 2016

You know what’s not so easy in Sp2013? Newform.aspx urls. Sure they live in the document library ribbon.
Sure you can also just drag stuff in, but what if you want to create a custom page and make it even easier for your users to create a new document?
That’s not so easy. So i set about figuring out the best way to do this.
Javascript buttons look cool and professional, so I thought, hey why not.
So I scoured the interwebs for some code. I came across this Gem by Ahmed Farag:
https://blogs.msdn.microsoft.com/how24/2014/09/23/create-a-link-to-display-edit-and-create-new-items-from-a-dialog-layover-in-sharepoint/
Thanks Ahmed you got me started!
This is an elegant solution if your library is out of the box. But what if you have custom content types?
That is not so easy to figure out. Once i did figure it out it was easy but not at first. You see, if you add a custom content type to a document library, the content type lives in _layouts, not in list/library name.
So how do you link that?
Well my friends, I am glad you asked.
First things first, like Ahmed says, grab yourself a content editor webpart (not script editor, that one has issues) and add it to a page.

Open your fav notepad editor
Copy Mr. Farag’s elegant code into it and click save.

 

(script type="text/javascript")
 function displayLayover(url) { 
 var options = SP.UI.$create_DialogOptions(); 
 options.url = url; 
 options.dialogReturnValueCallback = Function.createDelegate( 
 null, null); 
 SP.UI.ModalDialog.showModalDialog(options); 
 } 
 (/script)
Upload to your site asset library and link it via web part editor propeties
Now you have a pretty nifty button, but it doesn't do anything.
According to Ahmed, you should add the HREF key after your code for newitem.aspx.
However, as I alluded to early, that's not going to fly if you have a custom content type.
So here is his code:
<a href='javascript:displayLayover("/Lists/Contacts/NewForm.aspx?IsDlg=1")'>Display Item </a>
As you will figure out, content types do not live in /list/, they live in _layouts. So, how do i get that darn URL?

Its actually stupid simple. 
Basically, all you have to do navigate to your library settings, advanced settings, and find the open forms in dialogue, and click no.
Go back to your library and click new document and select your custom content type.

That will open your new item in a page, where, gasp, you can copy the url and past it into Ahmed code.

<a href='javascript:displayLayover("http://mysharepoint.domain.com/_layouts/15/NewDocSet.aspx?List=bc691a02%2D6335%2D4aee%2Da0e8%2D70185ab0491e&Source=http%3A%2F%2site%2Edomain%2Edomain%2Ecom%2F15%2Fnewlibrary%2FForms%2FAllItems%2Easpx&ContentTypeId=0x0120D520006B5814CAEDD0FD4C8F8F5C6B8AD7978C00F45CB6B8B2D5A74C8046CA70881BB0F7&RootFolder=%2F15%2Fputthisinyournewlibrary")'>New Content Type </a>

That's it. Now you have a new button that creates your new content type.

Tips: Make sure when you use content editor you upload your code to the asset library and link the file inside the content editor, so you can edit it easier.

TIP: Turn on versioning in your asset library so you can version your code out.

 

You are welcome world!

Nando

Advertisements




View HTML pages in SharePoint Online.

23 07 2014

Did someone in your organization save an entire website in a document library?
Did they complain they couldn’t open the start.html page?
Do you have users that want to view html pages inside SharePoint online?
If you answered yes to any of these questions (i am aware of the irony of this post), then I have a solution for you!
Simply open your html files in your library using explorer view and change the extension from HTML to ASPX. It even works with Flash content.
Yup, its that easy (and confusing at the same time, but for other reasons).

Enjoy
Nando





CSGPRO Guest Blogging

11 06 2014

As a new member of the CSGPRO team, I have committed to posting more Office 365 blogs.
Here is a dandy one for anyone about to migrate to the cloud.
Enjoy the goodness.
http://www.csgpro.com/post/110085

Nando
ps, yes thats me.





Document Center and Content Organizer

17 02 2012

One of SharePoint 2010’s hidden gems is the combo document center and content organizer.
By default the Document Center has a nifty Upload Document Button, but it goes to the standard document library. You can change that and point it to the Drop Off LIbrary that is produced when you enable the Content Organizer.

All you have to do is change some javascript. Here is how:

Edit the welcome page from Site Actions, and then click on the “Upload a Document” button. You will see this is actually just a content editor web part, so from the ribbon, under “Editing Tools” / “Format Text” click the HTML drop-down and then “Edit HTML Source”.

Replace the reference to the “Documents” library with “DropOffLibrary” i.e.:

<div><button onclick=”javascript:OpenNewFormUrl(‘DropOffLibrary/Forms/upload.aspx’);return false;” type=”submit”><nobr><img alt=”Upload a Document” src=”/_layouts/Images/uploaddoc.png”/> <span>Upload a Document</span></nobr></button> </div>

Save or stop editing the page and your done! The “Upload a Document” button will now default to uploading document to the Drop Off Library!





Turn Folders into Document Sets. YUP!

2 11 2011

Is this possible? Can sharepoint be this Awesome?
Yes it can. All you need is this:

This handy codeplex WSP that fixes the annoying bug in sharepoint that doesn’t totally convert folders
to document sets all the way:
http://foldertodocsetfix.codeplex.com/

2. You need to create a workflow in sharepoint designer.
Choose List Item and choose the Document library/Library you want to associate the WF with.
What we wan to do now is set a condition that says, “if the content type id=Folder, set contentId to Document Set.
You must set the workflow to start when a new item is created.
Once you have all these configured, the magic happens. Your Folder is now a document set. You can create different document set content type. Very very handy.

If you need more help, just leave a comment. I will get back to you asap.

 

Nando





More sharepoint alert wierdness! Alert links don’t work after url change.

5 05 2009

If you have been following sharepointdojo, you no doubt now the alert nightmares I have experienced. Here is another one:

Upon migrating my farm to new location and hardware, it was noted that alerts where still pointing to the old farm. How do iyou fix this?

Well the good people over at the msdn forums pointed me in the direction of the sql table that all alert subscriptions are housed: immedSubscriptions.

Below is linkage that shows you how to change the alerts to point to the new farm.

On a side note, always use the alternate access map name and not the server name. Trust me it will save you a huge headache later.

 

http://trycatch.be/blogs/tom/archive/2008/05/12/alerts-don-t-work-after-url-change.aspx