Display Todays Date in a Calculated Column with Javascript

Here’s what I used to display Today date in a Calculated Column with nothing but JavaScript in SharePoint 2010.

After a lot of research and trial and error, I finally have it displaying:

To display a date like this: 17/5/2015

Use this code:

=CONCATENATE("<p id='mydate'><script>var currentDate = new Date();var day = currentDate.getDate();var month = currentDate.getMonth()+1;var year = currentDate.getFullYear();document.getElementById('mydate').innerHTML = ( day + '/' + month + '/' + year );</script></p>")

 

calcColumnTodaysDate

 

Don’t forget to use data type returned as Number(1, 1.0, 100) This will convert the code to HTML

For U.S. Date, just swap the day and month over like this:

( day + ‘/’ + month + ‘/’ + year )

( month + ‘/’ + day + ‘/’ + year )

 

Update: The above code will only work for the first entry as the id name, i.e. ‘mydate’, needs to be unique.

So all you need to do is use another column that has Unique values, like a counter, or you could even combine two columns as thus:

 =CONCATENATE("<p id='"&PosNum&""&[First Name]&"'><script>var currentDate = new Date();var day = currentDate.getDate();var month = ('0' + (currentDate.getMonth()+1)).slice(-2);var year = currentDate.getFullYear();document.getElementById('"&PosNum&""&[First Name]&"').innerHTML = ( day + '/' + month + '/' + year );</script></p>"

The above code works and displays todays date for every Item.

 Date will now show as 20/05/2015

Hope this saves you some time ūüėČ

Advertisements

SharePoint 2013 Composed Looks displays no items

I came across this while browsing my Azure SharePoint 2013 Site Collection.  Which I thought was strange considering my On-Prem SharePoint 2013 Site Collection displays the default templates.

Composed Looks - All Items

A quick Google Search, I came across this: http://social.technet.microsoft.com/Forums/sharepoint/en-US/16461c60-4831-44bd-af11-1f6d99e44ab6/composed-looks-change-the-look-themes-are-missing-when-creating-site-from-saved-template?forum=sharepointgeneral

So the quickest and easiest way to get the templates into Composed Looks, is to create a sub-site and take a loot at the Composed Looks from that Sub-site.

On a sub-site I created all of the default template settings are shown as thus:

Ashampoo_Snap_2014.09.10_21h48m19s_002_

 

Useful Tip: This must be done from Internet Explorer (I used IE10), this will not work from Chrome. ¬†I didn’t test it in Firefox.

 

 

Any questions or comments, post below.

Add a PDF Thumbnail Hover Preview Column to a Document Library

I got this request from Jewell from my previous post:

Display PDF Thumbnail Preview on Hover in Search Results Web Part

“Is there away to apply this to a document library?”

Here are the steps to add a pic of a magnifying glass to a column in a Document Library.

So that when your mouse hovers, it displays the first page of the PDF inside an iFrame window.

The only down-side to having this implemented, is that as the user hovers over each PDF, it needs to download the entire PDF file to display the first page.
 

* Document Library with the PDF Preview column added

pdfs - All Documents

* On Mouse-Over

pdfs preview

Step 1: First you’ll need to create a workflow that copies the Document Name to the Title column.

Follow this post to do exactly that: http://www.knowledgegroup.no/blogg/post/2012/05/13/Add-filename-in-title-field-using-workflow.aspx

Step 2: Go to http://cssglobe.com/easiest-tooltip-and-image-preview-using-jquery/ and download the Scripts Zip file.

You’ll need the 3rd Example files uploaded to a Document Library to hold your script files.

Step 3: Open up main.js and replace the text with this modified version: PDF thumbnail script .docx or the pastebin version: http://pastebin.com/Gb5mGw1c

Step 4:  Create a html file in the same folder as your scripts and paste the following:

Don’t forget to change the paths to your script files.

<script src="/server/site/scripts/jquery.js" type="text/javascript" ></script>
 <script src="/server/site/scripts/main.js" type="text/javascript"></script>
 <style>
 #screenshot{
 position:absolute;
 border:1px solid #ccc;
 background:#333;
 padding:5px;
 display:none;
 color:#fff;
 }
 </style>
Step 5:
Add the HTML file to the source of a Content Editor Web Part in the document library that holds the PDF files.
Step 6: Add a Calculated Column in the Document Library, call it Preview and select type returned as:
Number (1,2,3…).
Add the following from here:
or from here:
="<DIV><a href='..\"&Title&".pdf' class='screenshot' rel='..\"&Title&".pdf' ><img border='0' src='/_layouts/images/MAGNIFY.GIF' alt='' style='padding-right: 5px; padding-left: 5px; vertical-align:bottom'></a></DIV>"
That’s it! Now hover over the magnifying glass image and you should see the PDF thumbnail display.
Any questions or comments, post it below. Thanks for reading.

Hide Ribbon from Users with Read Permissions

Hiding the ribbon depending on users permissions.

Read access will hide the ribbon so it will behave like an anonymous user navigating to the site.

Open up your custom master Page in SP Designer 2010.

1. Add a display:none style to the s4-ribbonrow element so it looks like the below code

<div id=”s4-ribbonrow” class=”s4-pr s4-ribbonrowhidetitle” style=”display:none”>

2. add the below snippet inbetween the s4-ribboncont and the s4-ribbonrow Div

<Sharepoint:SPSecurityTrimmedControl runat=”server” Permissions=”ManageLists”>
<script type=”text/javascript”> document.getElementById(“s4-ribbonrow”).style.display = “block”;</script>

3. Close the control by adding the below snippet just above the the s4-ribboncont and the s4-ribbonrow Div

</Sharepoint:SPSecurityTrimmedControl>

Your code should look like this:


<div id="s4-ribbonrow" style="display: none">

<Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="ManageLists">

<script type="text/javascript"> document.getElementById("s4-ribbonrow").style.display = "block";</script>

</Sharepoint:SPSecurityTrimmedControl>

Notes:

I have only tested this in SharePoint 2010 as I do not use SharePoint 2013.

I copied this from s SharePoint Design course I participated in with www.synergyonline.com

For other useful tips, check out their Blog Posts: http://www.synergyonline.com/blog

Record Search Results Queries to a List using a Hit Counter

This is how I am using a Search Results page to record individual Users Search Queries in a list.  Each Search Query is displayed as how the user typed them in.

What I’ll explain is how we can grab the URL from the Search Results and strip out the unnecessary code to display only the User’s Search Query.

For Example

This Search Result URL:

?k=pdf&cs=This%20Site&u=https%3A%2F%2Fwww%2Enothingbutsharepoint%2Ecom&r=fileextension%3D"ascx"%20fileextension%3D"asp"%20fileextension%3D"aspx"%20fileextension%3D"htm"%20fileextension%3D"html"%20fileextension%3D"jhtml"%20fileextension%3D"js"%20fileextension%3D"mht"%20fileextension%3D"mhtml"%20fileextension%3D"mspx"%20fileextension%3D"php"

Will be converted to display only what the user has typed in the Search Box, which in this example, is: “pdf“.

Each time a user types in a Search, their query is recorded with their name, date and keywords typed.

Firstly, you need to install and configure the “Hit-Counter and Star-rating for SharePoint” from Alexander’s¬†SharePoint JavaScripts¬†site.

Once you have this configured it and you can see the users data added to the  HitCounter List , we can now modify the HitCounterAndStarRatingForSharePoint.js file to include the Users keywords entered.

1: First create a new column within the HitCounter list call it UserKeywords.  Add this column to your default view.

2: Edit the HitCounterAndStarRatingForSharePoint.js  and scroll down to about line 218:  //Add item.  Within that block of code you will see the column variables, make a new line under ReferringURL:refURL, and type in the new column name which is attached to the variable as such:

UserKeywords:searchQuery,

3:  Then under the following code at about Line: 152

// Get url and referrer
refURL = document.referrer;

Add the following lines of code:

searchURL = window.location.search;                               //returns string ?k=Users%20Search%20String
  modURL = searchURL.substring(3);                                   //removes characters ?k= from string
  decodedURL = decodeURIComponent(modURL);       //decode URL to translate encoded characters from string
  searchQuery = decodedURL.split('&')[0];                         //removes characters all after &

Each line I’ve added a comment that describes what each line does. ¬†I don’t know how to write code in Javascript, so I had to¬†Google Search each line to work out how to accomplish each Javascript function.

4:  Now you can test the Search Results page by entering in a Search Query and then checking the HitCounter List.

The UserKeywords column will now display the Search Keywords exactly how they are typed by the user.

Any questions, please comment below, thanks for reading.

Open all PDF files in Maximum Dialog Box

This code grabs any PDF file on the page and rather have them opening in the same window or a new window, they open conveniently in a SharePoint modal pop up dialog window.

All you need to do is:

1: Place the code below into a TXT or HTML file,

2: Upload it to a Document Library

3: Your could edit the file and change the path of JQuery to a local copy of JQuery1.9.1.min.js if required.

4: You could either reference the file path in a Content Editor Web Part.  eg: \sharepointserver\sites\sitecollection\subsite\scripts\pdfmaxdialogcode.html

or add the code to your Master Page in a .JS file . (Need help with this, post a comment below)

5: Open up a page where PDF files are located and test it out.

Fullscreen SharePoint Dialog

To see a preview of the result, refer to my previous post: https://sharepoint2020.wordpress.com/2013/02/15/how-to-open-a-pop-up-dialog-maximized-fullscreen/

This script was created by Alexander Bautz from http://spjsblog.com/

His post is located here: http://spjsblog.com/2013/05/31/open-pdf-files-in-a-maximized-dialog/

For redundancy, I’ll post the code here as well.

* After you Paste the code, you will need to remove the < code > < / code > tags from the script below, it’s the only way I can paste the code in WordPress without the Object tags being stripped out.
<!-- Put this code below the list view web part -->
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$("a[href$='.pdf']").each(function(){
$(this).removeAttr("onclick").attr("href","javascript:openPDFinDlg(\""+this.href+"\")");
});
function openPDFinDlg(href){
var o;
$("body").append("<div id='pdfTemp' style='min-height:600px;min-width:800px;height:100%;overflow:hidden'><<code>object</code> data='"+href+"' width='100%' height='100%' type='application/pdf' ></<code>object</code>></div>");
o = {};
o.html = $("#pdfTemp")[0];
o.showMaximized = true;
o.title = href.substring(href.lastIndexOf("/")+1);
o.dialogReturnValueCallback = openPDFinDlgCallback;
SP.UI.ModalDialog.showModalDialog(o);
}

function openPDFinDlgCallback(){
// do something here when the dialog closes
}
// ]]></script>

To enhance the display of PDF files to your site vistors

When dealing with PDF files, you can also add parameters from Adobe’s PDF Open Parameters documentation to the +href+ variable to present the PDF to your users.

Some examples of Adobe PDF Open Parameters:

The following table lists and describes the available PDF open parameters. Italics indicate user-specified variables.

page=pagenum
Specifies a numbered page in the document, using an integer value. The document’s first page has a pagenum value of 1.
zoom=scale
zoom=scale,left,top
view=Fit
view=FitH
view=FitH,top
view=FitV
view=FitV,left
view=FitB
view=FitBH
view=FitBH,top
view=FitBV
view=FitBV,left

Use the page command before this command.
pagemode=bookmarks
pagemode=thumbs
pagemode=none (default)
Displays bookmarks or thumbnails.
scrollbar=1|0
Turns scrollbars on or off.
toolbar=1|0
Turns the toolbar on or off.
statusbar=1|0
Turns the status bar on or off.
messages=1|0
Turns the document message bar on or off.
navpanes=1|0
Turns the navigation panes and tabs on or off.

for example: Within line 11, you can change this portion:

 data='"+href+"' width='100%' height='100%' type='application/pdf' 

to this

 data='"+href+"#page=1&view=fitV&pagemode=thumbs' width='100%' height='100%' type='application/pdf' 

For further documentation on Adobe Open Parameters see this link:

http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf

* Possible issues: If the PDF link is located outside of your SharePoint server, the dialog window will display but the PDF may not.

Hope the code is useful for your site, thanks for reading.

Reply to Discussion: Send Email to Item Owner using Workflow

After a few Google Searches, I finally found how to Send an Email, using SharePoint 2010 Designer Workflow, to the Original Creator of a Discussion Item when someone posts a reply to the discussion item.

Here is the original URL I used for the instructions: http://answers.flyppdevportal.com/categories/sharepoint2010/sharepoint2010customization.aspx?ID=03d57a50-17d6-4013-bb58-b816d97f63ec

“I learned that discussions have two different content types, Discussion for a new topic posted and Message for a reply to that topic.

The ID for the original discussion (topic) post is the column “ID” on that item. But the reply messages store this same number in the “Parent Folder ID” column.

So, I created a workflow with one condition, that the content type is Message. When the condition is met (only by replies), I send an email with the To field populated by: “Workflow Lookup for a User”, with the data source as the Current List, the Field from source as Created by and the Return field as Email Address.

Under Find the List Item, the column is ID and the Value is Current Item:Parent Folder ID. Then fill in the body of the email with whatever data you need.”

SP2010WorkflowDiscussionReply

Note: ¬†Condition – “Current Item Content Type equals Message ¬†(You’ll have to type in the word “Message”)

For the Action, just follow the picture that shows the correct way of determining the Originator of the Discussion Item.

For the Body, you could add a direct URL to the Discussion List Item from the following Blog Page: http://geekswithblogs.net/bjackett/archive/2011/02/18/sharepoint-designer-2010-email-link-to-item.aspx

Ask if anything is unclear. Thanks for reading.