Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts

Friday, January 22, 2016

PowerShell: Loop Through All Sub Sites in a Site Collection

So this post will be extremely short, but hopefully useful.  The below script is a good starting point if you have a repetitive task that you need to complete on all of your sub sites within a particular site collection.  This script will loop through all of the sub sites, including sub sites of sub sites and print out the site's title and URL.  To use the script you simply need to run the script and input the site’s root URL without quotes.  So if my site collection was http://danssandbox.com/sites/dansSand , I would simply need to input that URL when prompted by the script for the “Root Site Collection Path.”  

This script is meant as a starting point to include actual logic rather than the Write-Hosts, but it should get you on the right track!  Enjoy the loops!


Dan


param($url = $(Read-Host -prompt "Root Site Collection Path"))

#Get the PowerShell Snapin
Add-PSSnapin "Microsoft.SharePoint.PowerShell"

#Get Root Site
$root = Get-SPSite $url

#If site was found / valid
if($root -ne $null)
{

     foreach($subSite in $root.AllWebs)
      {
       $subSiteTitle = $subSite.Title
                Write-Host $subSiteTitle -ForegroundColor Magenta
                $subSiteURL = $subSite.Url
                Write-Host $subSiteURL -ForegroundColor Cyan
       $subSite.Dispose()
      }

        $root.Dispose()

}

Friday, January 2, 2015

How to Add Totals to Search Refiners in SharePoint 2013

So for every Search project I work on this requirement always surfaces, which is why I am confused to why Microsoft did not default the refiners to include the totals.  Including totals in your refiners is actually very easy and only requires a small modification to your Search Filter refiner.  Depending on whether you are utilizing a single option refiner or the multi value refiner will determine which filter refiner you will need to update.


Single Selection
              Filter_Default
Multiple Selections
             
Filter_MultiValue
The first step to modifying the refiner(s) is to locate them

How to Locate Your Filter Files:
(Note: We do not want to modify the JS Files, any updates we make to the HTML files will propagate to the linked JS files.)

  1.   Site Settings
  2.  Master pages and page layouts
  3.  Display Templates
  4.   Filters
  5. Save a copy of either the Filter_Default.html and/or Filter_MultiValue.html files to your desktop
How to Modify Your Filter Display Templates
Now that we have saved copies of the filter display templates, it is time to edit them in order to display totals.

  1. Open the files in a text editor i.e. Notepad++, Notepad, SharePoint Designer, Visual Studio, etc 
  2. Modify ShowCounts: to equal true
Original

<!--#_
 
    this.Options = {
        ShowClientPeoplePicker: false,
        ShowCounts: false
    };
Updated
<!--#_
 
    this.Options = {
        ShowClientPeoplePicker: false,
        ShowCounts: true
    };

After making the update from false to true you will need to upload the new file and publish the changes.  By using the exact same file name your changes should be saved as a new version to the file, if you were not modifying it directly.

Best Of Luck!
Dan

Tuesday, July 8, 2014

Form / Data Validation Using jQuery & Javascript

Hello Readers,

It has been a while since my last post and I apologize for the delay!  Today I wanted to talk about how to use jQuery and JavaScript to validate field values in SP forms.  This example will be extremely simple, but hopefully it will help cover the basics, as well as spark some ideas on how you might want to validate entries on your forms.  You will need to add this script to the new & display form.aspx pages with either with a content editor or script editor web part.

If you are just getting started with JavaScript and jQuery I would highly recommend reading through Mark  Rackley’s  A Dummies Guide to SharePoint and jQuery-Getting & Setting SharePoint Form Fields which is a fantastic blog series as well as Marc Anderson’s  Blog which is loaded with great content.  Both of their sites run through all of the selectors i.e. when to use select, input, etc. so I will not be covering that in this post.

For my example today I have a simple custom list with the following fields:
            Title: (single line of text) (input field)
            Candidate Hired: (combo box dropdown N/A, No, Yes) (select field)
            Candidate Start Date: (date & time control)

I want to an alert to pop up letting the user know that they accidentally left the Start Date blank when Candidate Hired = “Yes” & the Candidate Start Date was left blank.  If we were going to rely on this script for validation we would want to put in other conditions to handle scenarios such as having a start date without selecting yes, but for the sake of simplicity we will keep it very basic.

To Do This We Will Need:
·         A reference to the jQuery library
o   We can reference the library either with a CDN (content delivery network) or by downloading the library and storing it somewhere on our SharePoint site and linking to it there.
o   If you download the library I would recommend saving the file with a title of jQuery and adding an additional field to the library with the version number.  This is a good practice since if you have multiple scripts linked to the jQuery library, they won’t break when a new version is uploaded and the file name changes.
·         This Script
<script type="text/javascript" src="LINK TO jQuery Location"></script>
 <script type="text/javascript" language="javascript">
 function PreSaveAction() {
drop = $("select[title='Candidate Hired']").val();
date = $("input[title='Candidate Start Date']").val();
    if (drop ==="Yes" && date===""){
        alert("You Shall Not Pass, Fix The Date!");
        return false;
    }   
        return true;
}
 </script>

How Does The Script Work?
Essentially what this script does is to check to make sure that the Candidate Start Date is not left blank if the user indicated they were hired before they can save the form.  We are obtaining the values based on the form’s display names **Not Internal Names!!** and then checking those values before the form can be saved.  If the form matches our criteria of Hired = yes & Start Date = “”, then our script will pull a Galdalf when the user tries to submit the item with a “YOU SHALL NOT PASS” until the form has been fixed.  

In order to repurpose the script you could swap out the display names and use it as is or you could use it as a template to start writing your own validation scripts.  Although some validation can be done via the column validation and list validation in SharePoint, I always run into scenarios where a simple script enhances the user’s experience as well as ensures the inputted data is correct.  An example of this would be to use JavaScript to create an input mask for form fields or to ensure that an email address field actually contains @ & .com.

Well again this script is super basic, but I hope that this sparks some thoughts on where your forms could be enhanced and how you can use jQuery and JavaScript to get it done!


Best Regards,
Dan

Monday, November 18, 2013

How to Modify the Text Filter Web Part to Allow Partial Searches (SharePoint 2010)

Hello!  If you are reading this, I am assuming that you were dramatically let down by the Text Filter Web Part as well (shakes fist at the sky).  I have no idea why Microsoft thought that only allowing exact string / text matches was a great idea for the text filter web part, but the reality is that the web part needs the flexibility to handle begins with clauses, contains, etc., and the good news is this article is how to do exactly that!

Materials Needed:

SP Designer 2010

A Web Page containing:

            The Text Filter Web Part

            Data View Web Part

By searching for this article, I am assuming that you already have a web page set up which has the text filter web part on it, so we will start the tutorial on this premise.


Starting Point:
1. Open designer

2. Open your page in advanced edit more

a. Right click and select edit in advanced mode

3. Select the split view

 
4. In the desired zone, select the data view of the list you are trying to filter off of the insert tab

a.  



 
b.  
 
 
5. Select the list you added to the page

6. Select Options

7. Select Filter

8. You will be presented with the following dialog box (select your field that you would like to filter and set your comparison to Contains or Begins With depending on your needs)

a.  



9. Select Create a new parameter

a. Rename Param1 to a name of your choosing, I will be using “FilterExample”

b. Select Query String under Parameter Source

c. Select Ok


10.Right Click Text Filter Web Part In Designer

a. Select Add Connection

b. Select Send Filter Values To

c. Select Next

d. Select Connect to a web part on this page

e. Select Next

f. Select the list you put on the page as your Target Web Part

g. Select Get Parameter From as the Target Action

h.  



i.    



j. Select Next

k. Select Finish

11.Save The Page

12.Select Yes to the dialog box

Now that you have completed the steps, the Text Filter web part should now allow partial searches of the desired field.  For this example I set my Text Filter to use contains on the Title field.  Since I defaulted my variable to not contain anything, the page should be blank to start.


After I put in the letter T and hit enter, it will filter my list and find any items containing the letter.


Cheers!
Dan

Friday, November 15, 2013

Corrupt / Broken Web Part No Worries! How to Access the Web Part Maintenance Page


I haven't had to use this trick in a while, but I ended up having to remember it today, so I figured I would write quick blog post on it.

From time to time a web part can become corrupt or broken making it impossible to delete, edit, remove, etc from the page.  This can be an enormous headache and a very annoying scenario when you first encounter it.  The easiest way to remove the broken web part is by utilizing the web part maintenance page.  To access the page, simply put “?contents=1” at the end of your URL.  For example if my page was:

us/sitename/pages/ExamplePage.aspx

I would use us/sitename/pages/ExamplePage.aspx?contents=1 to access the web part maintenance page.  From this page you can easily see which web parts are being used on the page and easily delete the one(s) that are corrupt or broken.

Cheers!

Dan

Thursday, October 17, 2013

How to Create an Export to Excel Button for Any List & View (Including Surveys)


This tutorial will cover how to create a simple HTML button which will export a particular list & list view to Excel.


Materials Needed:

<input type="button" style="width:180px; height: 75px; 30px;background:gray; color:white;font-size:larger; font-weight:bold;"onclick="window.location.href='SITEURL/_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List={YOUR LIST ID}&View={YOUR VIEW ID}&CacheControl=1';" value ="YOUR BUTTON TEXT"/>


The code above is essentially everything that you will need for a simple Excel Export button.  In order to get the code to work, you will need to update the SITEURL, YOUR LIST ID, YOUR VIEW ID, & YOUR BUTTON TEXT.


The hardest part of this exercise is to determine what your list & view ID are, but even that is simple!


To Obtain Your List & View ID:


1.    Navigate To Your List

2.    Select List Settings

3.    Under Views

a.    Edit the view you would like to create an export button for

4.    Copy The URL from your browser

a.    It should resemble: SitePath/_layouts/ViewEdit.aspx?List=%7B58B38FF2%2D9F99%2D4279%2DA22C%2DA2CCA95F4D7E%7D&View=%7B5781F798%2DD539%2D4015%2D87FB%2DA4A32925AACC%7D&Source=%252Fsites%252Fustsm%252F%255Flayouts%252Flistedit%252Easpx%253FList%253D%25257B58B38FF2%25252D9F99%25252D4279%25252DA22C%25252DA2CCA95F4D7E%25257D

b.    You can manually break out the View= & List=, but I personally just use this free translator that is embedded in the page which does it for you.


 

To Implement The Button:


1.    Swap out the necessary snippets in order to update the HTML code (YOUR BUTTON TEXT, YOUR URL, YOUR LIST ID, and YOUR VIEW ID) with the information you obtained in “To Obtain Your List & View ID.”

2.    Place the updated code into a text file and save it out on your site

3.    On a webpage that you would like the button, create a content editor web part and link that web part to the URL of your text file, I would recommend using the relative path (/local/fakesite/library/filename.etc).
 

That’s It Folks!


Dan

 

Friday, September 27, 2013

InfoPath Tutorial Cascading Dropdown (Does not have the 20 item limit)

I had read a number of tutorials on how to create a cascading dropdown using InfoPath 2010, but there was a 20 item limit (which is not very useful).  The lists I implemented this for actually have just under 5,000 items in order to not breach the threshold limit.  If you do have a list with over 5,000 items, the lookup column will not work until you raise the threshold limit to be above 5,000 items in Central Admin.

This post will explain how to create a cascading dropdown within InfoPath 2010 for a list content type.

Example Situation:  I am going to create a contact form which will filter the territories based upon the region of the form and then when I select the territory it will filter my store numbers to only show that territory’s stores.

My Hierarchy:

            Region
                       →Territories
                               → Store Numbers
Materials Needed:
SharePoint 2010 List Which Utilizes a Two Lookups
A SharePoint 2010 Content Type
InfoPath 2010
 
First we will need to navigate to the list:

1.    Open Your List

2.    Select List Tools

a.    Select List

3.    Select List Settings

4.    Select Form Settings Under General

5.    Select Your Content Type

6.    Select “Customize the current form using Microsoft Infopath”

This will open InfoPath with that content type’s fields.  We are modifying the form for this specific content type; we are not modifying the list form.

The next step is to create and style the form to meet your needs, for this example I created this from.





My form currently is displaying all of Mountain Store ID’s when in reality I only want the ID’s shown for that specific territory.

To create the cascading dropdown:

1.    Right click your child lookup field and select “Dropdown List box Properties…”

a.    

2.    The next step is to select Add…  We will be creating a new data source in order to implement our cascading dropdown

3.   


4.    


5.      


6.    Your URL for the site should be selected in the next screen

7.    Select the child list which your lookup pulls from.  In my example, my Mountain Store ID comes from my Mountain Region list.

8.    Step 9 is really what makes this entire thing work.  The default data connection only pulls the Mountain Store ID (aka Title) in the source list.  The new data connection will allow us to query the list to obtain additional data.  For our example I will be selecting Title & Territory since I will want to filter my ID’s down by the Territory.
       9.
10. Select Next

11. Select Next

12.   In step 13, make sure to DESELECT Automatically retrieve data when the form is opened.

13.
      14. Select Finish

15. Now that we have created the new data source, we need to switch the value to ID otherwise we will run into validation errors later.

16. 

17. Select OK

Now that the new data source has been created, we can use it to create our cascading dropdown!

1.    Select your parent field, in my case this field is territories.  (All of my store ID’s are tagged with the Territory they correspond with in the Mountain Region List)

2.    Select the Home Tab

3.    Select manage rules

4.    Select add rule

5.    Select New

6.    Select Action

7.    Within your rule, select Add “Set a fields value”

a.    We are going to set our Mountain Store ID to default to blank

b.     

8.    Create another Set Field Value Action.  In this action we will be setting our form to filter our Mountain Store ID’s based upon the territory.

9.    We are going to set this action to set our Territory to our newly created Data Sources Territory.

10. Select the fields icon next to the Field: dialog box 
 
11. A similar menu should appear like the one below:

12. 

13. Select the dropdown arrow and select the data source you just created.  In my example, it

14. is Mountain Region1

a.     

b.    Open Query Fields

c.     Open q:SharePointListItem_RW

d.    Select the field which corresponds with your parent field.  In my example, it is Territory

e.     Select OK

15.   We now need to set the value for the second parameter of the Rule Details.  Select the fx button and select your parent field from the main data source.

16.


17.


18. Select OK for all of the dialog boxes after you have selected your parent field from the main data source for the Value: input.

The last step to make this work is to query for data within the rule.  So once again, lets select Add Action, just like we did to set the ID initially to blank and to set the Territory = Territory.

1.    Select Add next to Run these actions

2.    Select Query for Data

3.    Select the Data source you created earlier from the dropdown box.

a.     


4.    Select OK

5.    Your final rule should have the 3 actions and resemble the below

a.     





Well that’s it Folks!  If you have followed the above steps correctly, you should now have a cascading lookup field!

Example For When I Select Denver

 
Example for When I Select Salt Lake
 
Cheers!
Dan