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

Thursday, July 17, 2014

SharePoint Organization Chart with Presence

Here's a little script that - depending on your setup - will enable you to get presence icons on your Org Chart looking like this:

The Org Chart links to the users SharePoint profile page with a url like the below:
http://company.com/Person.aspx?accountname=DOMAIN\Username

In our company we all have an email address that looks like this:
username@company.com (for internal use only)

Our usernames has a fixed length, so using the scripts substr function I grap the username from the end of the url and adds the company email trail to it. It's no magic and the script is small.

You can find the script here. You'll need to modify these two variables:
   // Please modify these two variables to fit your company settings
   var companyEmail = "@yourcompany.com";
   var lenghtOfUsername = 8;

You will then need to add the script to the HTML Source portion of a Content Editor web part. Please refer to sections 11 to 16 on this blog post to see how you do that. Also note that the script refers to jQuery and SPService using external CDN's and it is highly recommended that you download these scripts and refer to them locally.

Tuesday, May 20, 2014

Who created this list or library?


How do you find out who created a particular list or library in SharePoint? It doesn’t say anywhere! Only option is to use PowerShell and that requires that you have access to the SharePoint server.

So I baked together a little script that will give you the answer.

You can find the script here. You will need to add the script to the HTML Source portion of a Content Editor web part. Please refer to sections 11 to 16 on this blog post to see how you do that. Also note that the script refers to jQuery and SPService using external CDN's and it is highly recommended that you download these scripts and refer to them locally.

Once the script has been successfully added to your page it should look similar to this



Here’s how you use it:
  1. First you need to copy the url or address of the list or library. If you have the list open you can get it from the addressbar by pressing the F6 key followed by Ctrl + C. If you are looking at the All Site Content overview, you can simply right – click it and select Copy Shortcut.
  2. Next go back to your WhoCreatedThisList page.
  3. Paste the url into the textbox by pressing Ctrl+V and then click the Search button
  4. Allow the script to work for a few seconds
  5. A dialog box will appear with the owner information
  6. If you need to save the information you can copy it to the clipboard by pressing Ctrl+C while the dialog box is in focus.

Tuesday, January 5, 2010

SharePoint calculated columns and variations?

I had a very spooky issue today that took me a good deal of time to resolve.

On a list in an English variation I have a calculated column called CalculatedExpiry with a formula that looks like this:
=IF(Expires="",DATE(2099,1,1),Expires)
  and that works just fine, if the Expires field is empty, it set it to 1. January 2099

I then created the same calculated column on a Danish variation of the site, but when I wanted to save it I got the "The formula contains a syntax error or is not supported."
Even though they where identical...

After a lot of testing and googling I came accross this post, which suggested to replace the commas (,) in the formula with semicolons (;) and what do you know, it works!

So in the Danish variation the calculated columns formula now looks like this:
=IF(Expires="";DATE(2099;1;1);Expires)

Wednesday, March 11, 2009

Creating a document expiration view

It's a scenario we all know; documentation has to be kept updated, test reports has to be fresh and valid and so on. So how do you ensure that?

Here's a little hint on creating a view that will display items or document that hasn't been updated for a specific period of time.

Create a new view of your list or document library.

Give it a descriptive name and select the fields you want to display

If you got files in folders, select to 'Show all item without folders' under Folders, Folders or Flat

Under Filter select the options that form the criteria for the documents or items you want to look at. In the question about the date, you could use the built in Modified column or use one of your own custom columns, like I do below.
The trick is to use the built-in [Today] feature and the subtract to number of days you want to test for. So, in this case, I looking for documents that has the SKU Test Result set to 'Pass', but has a SKU Test Date that is more than 330 days old. Remember, no spaces in [Today]-330.
The resulting view shows all the documents that needs to be re-tested soon and the responsible person can take the needed actions.

Monday, March 9, 2009

To Dispose or not to Dispose - that's the question

It's a good coding practice to tidy up after yourself to not waste system resources and there's good resources out there to help you learn the techniques. One of my favorites is http://code.msdn.microsoft.com/SPDisposeCheck

But recently I had a workflow that started dying on me and throwing up in the eventviewer with a
.NET Runtime version 2.0.50727.3068 - Fatal Execution Engine Error. The error assumed problems with the dotnet framework, but repairing the framework and applying hot fixes didn't solve the issue. And the strange thing was that it was only when adding new item it happened, where as the workflow ran perfectly when updating items. The major difference was that the item adding was triggered from an eventhandler and therefore ran under the System account, but item updating occurred when a user changed the document. I also discovered that part of the workflow ran, before it died, so I put in excessive logging and ended up at a SPWeb.Dispose line. Once I commented out these lines the error disappeared.

// Disposing here will cause workflow to fail
// web.Dispose();
I'm not a 100% sure this is the right answer, but running in System account seems to prohibit the use of Dispose. Anyway, I left these SPWeb objects to be taking care of by the garbage collector, maybe it was afraid of being unemployed...

Friday, February 20, 2009

Cascading dropdown lists and error 401

Until recently we successfully used the tip from Ishai Sagi on cascading lists, but suddenly our users reported getting a error when trying to use the drill down Master-Detail dropdown lists.

Looking at the IIS log we discovered the call to owssrv.dll was done anonymous and resulted in an error 401. With good help from a consultant from Key2Know we found that the issue was related to a loopback check security update on Windows Server 2003 SP1. The solution was found on http://support.microsoft.com/kb/896861 where you can read more about this issue.

We implemented solution 1 on our Web Front Ends and this resolved the issue.

Wednesday, February 11, 2009

Creating logging for workflows and eventhandlers

When dealing with workflows you often have the abillity to do debugging in your DEV environment, but when it comes to eventhandlers things get a litle more grumsy. And fully testing every possible scenario and user inputs is impossible so one day your code is gonna break and if you haven't made a log, you don't know why...

I use the same logging feature and logging place for all of our workflows and our one and only Construction Kit Eventhandler (more on that another day). It's fairly simple, but functionally enough to keep me going.

So in the terms of C#:
  • Make two global variables

    public int i = 0;
    StringBuilder MyStringBuilder = new StringBuilder();

  • Create two functions

    public void AddToLog(string msg)
    {
    MyStringBuilder.AppendLine(DateTime.Now.ToLongTimeString() + ":" + i.ToString() + "=" + msg);
    }

    public void WriteLog()
    {
    try
    {
    AddToLog("Log ended at i = " + i.ToString());
    SPList SetupList = web2.Lists["Logs"]; //use global SPWeb here or hardcode
    SPListItem myItem = SetupList.Items.Add();
    myItem["Title"] = myContentType;
    myItem["Log"] = MyStringBuilder;
    myItem.Update();
    SetupList.Update();
    }
    catch (Exception Ex)
    {
    //Even logging can fail so you may want to take some action here
    }
    }

  • In your code place a code counter and code logging like this:

    AddToLog("ReadSettings started...");
    i = 1;
    myUrl = workflowProperties.WebUrl.ToString();
    i++;
    AddToLog(" Url: " + myUrl);
    i++;
    Etc...

    The code counter 'i' gives you the option of pin pointing exactly at which line of code the error occurred.

  • At the end of your code execution and at your global error handling code ensure to get the log written:

    WriteLog();

The Logs list should contain two columns, 'Title' as Single line of text and 'Log' as Multiple lines of text (plain text).

Now you can hardcode your logging destination into the WriteLog function or you can setup a global SPWeb object (remember to dispose it at the end of the code execution) like I do. My code look something like this:

string myUrl = workflowProperties.WebUrl.ToString();
i++;
int startcmd = myUrl.IndexOf("//");
i++;
int startval = myUrl.IndexOf("/", startcmd + 2);
if (startval == -1) startval = myUrl.Length;
i++;
SPSite objSite = new SPSite(myUrl.Substring(0, startval).ToLower().Replace("corporate", "collaboration") + "/SubFolder/Settings");
i++;
web2 = objSite.OpenWeb();
i++;

The .Replace("corporate", "collaboration") trick is about having two different webs served by the same code, but only having one place to host the logging, e.g. at http://collaboration/SubFolder/Settings/Logs

Obviously our logging code also deals with log archiving, success or failiure logging as well as notification of sys admins, but for the sake of simplicity this is the starting point.

InfoPath properties and SharePoint columns

I just hate it when there's no logic explanation!

Had an InfoPath form, published to SharePoint, needed to add some new fields, created the matching Site Columns, promoted the fields to the new columns, republished - everything looked good on our TEST server and then I did the same thing in our PROD environment: NoGo.

Yes, the form was published ok. The resulting xml documents had the changes, but the SharePoint Site Columns didn't reflect the changes. I searched logs, checked for misspells, googled for a day - nothing! It all looked correct, but it didn't work. (Actually not quite correct cause the columns where now properties of the ListItem and therefore didn't belong to the document).

Finally I found a fellow blogger that in turn had found some other bloggers and to make it short, here's the link: http://arichterwork.blogspot.com/2008/03/infopath-property-promotion-woes.html

All credit goes to these guys, but let me just sumerize the workaround (it's not a solution, nor an explanation):
  1. Using Central Admin, Applications, InfoPath, you need to deactivate the faulting form from all of the Site Collections it has been activated on.
  2. While deactivated, upload a new version of the form.
  3. Reactivate the form to the Site Collections where it is needed.

This made my InfoPath fields or properties work and I got the reflecting values on my SharePoint columns.

It looks like this bug occurs when you have republished your InfoPath form several time, but I really hope it will be fixed soon.