Friday, May 3, 2013

SharePoint 2010 Server rename - Cannot connect to configuration database error

Assumptions (not best practice): You have a standalone SharePoint 2010 farm installation.

Problem: Oh dear, you ran the stsadm renameserver command after you renamed the actual server name.  Now you getting the dreaded Cannot connect to the configuration database error.

Never fear, there is a solution to this and its relatively easy, its worked for me.

1. Create an alias from oldservername, to newservername in mssql configuration manager.  If you are using named instances for your SharePoint farm databases, setting up an alias for a named instance can be a bit tricky, but here is how its done http://bigjimindc.blogspot.com/2009/08/ms-sql-server-named-instances-and.html

2. Once the alias is done and is working, you will now be able to access the central administration.  Once in, go an update the alternate access mappings in central administration , then simply run the stsadm renameserver command again.  


stsadm -o renameserver -oldservername "oldserver" -newservername "newserver"

3. Now, remove the aliases (delete them)

4. Reboot server (if you can, else restart mssql and iis).

5. You should now have a working SharePoint farm again.


I believe you HAVE to run the stsadm renameserver command before you rename a actual servers name.  But sometimes you cannot do this and therefore my steps above should help you fix a "broken" SharePoint farm.  Well it did at least for me :-)


Thursday, April 25, 2013

SharePoint Designer 2013 - SharePoint 2013 Workflow

Enabling SharePoint 2013 Workflow in SharePoint Designer 2013.

By Default, SharePoint 2013 Workflow is not available in SharePoint Designer 2013, you need to install workflow manager first, then configure it.



Steps to follow:


  1. Install Workflow Manager Client http://go.microsoft.com/fwlink/p/?LinkID=268376
  2. After installation, if you are communicating with Workflow manager via http or https you may need to change the powershell cmdlet to suite.  In my case I was using it over HTTP, so the following cmdlet worked for me.  You can have a look for "Workflow Management Site" in IIS, to get the workflowhosturi.
Register-SPWorkflowService –SPSite "http://myserver/mysitecollection" –WorkflowHostUri "http://myserver:12291" –AllowOAuthHttp

After those steps, you should now have the SharePoint 2013 Workflow enabled.

To see more detail, have a look at this technet article. http://technet.microsoft.com/en-us/library/jj658588.aspx#section4

Wednesday, April 3, 2013

Get fields using Javascript Client Object Model


Using the Javascript Client Object Model, you can get values from a listitem. 

How to use the JSOM is described here Code Project

Title – SP.ListItem.get_item(‘Title‘);

ID – SP.ListItem.get_id();

Url -SP.ListItem.get_item(‘urlfieldname‘).get_url()

Description – SP.ListItem.get_item(‘descriptionfieldname‘).get_description();

Current Version – SP.ListItem.get_item(“_UIVersionString“);

Lookup field – SP.ListItem.get_item(‘LookupFieldName’).get_lookupValue(); // or get_lookupID();

Created By – SP.ListItem.get_item(“Author“).get_lookupValue();

Modified by – SP.ListItem.get_item(“Editor“).get_lookupValue();

Choice Field – SP.ListItem.get_item(‘ChoiceFieldName‘);

Created Date – SP.ListItem.get_item(“Created“);

Modified Date – SP.ListItem.get_item(“Modified“); -> case sensitive does not work with ‘modified’

File  – SP.ListItem.get_file();

File Versions -  File.get_versions();.

Content Type – SP.ListItem.get_contentType();

Parent List – SP.ListItem.get_parentList();

Note:  (‘LookupFieldName’).get_lookupValue() sometimes returns an array of data, especially when your lookup allows multiple values.
In that case you will need to iterate the array and get each value individually.

 SP.ListItem.get_item(‘LookupFieldName’)[0].get_lookupValue(); - this will get the first item in the array.

For Arrays:


       for(var i = 0; i < oListItem.get_item("LookupFieldName").length; i++)
{
     alert(oListItem.get_item("LookupFieldName")[i].get_lookupId()); // or get_lookupValue()






Friday, February 8, 2013

Calculated Column - Add x days to created date, excluding weekends.


Overview

Say a user creates a item in a list and they have 3 (working days) to to mark it as completed, how do we do this?

1. Create a new field in the list (calculated field of type date and time), lets call it "escalate date", then using this formula.

=IF(Weekday([Modified])>3, [Modified]+5, IF(Weekday([Modified])>1,[Modified]+3, [Modified]+4))

2. Create a workflow that starts on item created and changed, that pauses until the "escalate date", once that date is reached, workflow checks if item was marked as completed or not.


Explanation of Weekday.

Using Weekday, we can determine which day of the week the share point list item was created and add 3 working days to a calculated column.


WeekdayReturnsDays to addEscalate Date
Sunday1+4Thursday
Monday2+3Thursday
Tuesday3+3Friday
Wednesday4+5Monday
Thursday5+5Tuesday
Friday6+5Wednesday
Saturday7+5Thursday

Friday, July 27, 2012

SP2010 - Dynamic List filtering - without code, using just the URL

You have a list and you want to filter the list using a URL.

Normally you would do it like this:

http://myurl/sitename/listname/Forms/AllItems.aspx?FilterField1=Country&FilterValue1=America

This is great and you can extend it to include other columns by using FilterField2,FilterValue2,FilterField3,FilterValue3    and so on.

But what if you want to filter the same column with more than one value, using FilterField options will only allow one filter per column.  So in comes "FilterName and FilterMultiValue"

To use, its simple

http://myurl/sitename/listname/Forms/AllItems.aspx?FilterName=Country&FilterMultiValue=America;South Africa

BAM! you now have a filter on the same field, its an OR filter, but its still great :)

Friday, April 20, 2012

Sharepoint 2010 Event Receiver - Deploy and Remove manually

So you want to deploy an event receiver created in Visual Studio 2010 and cant!!!

Well its easy when you right-click the event receiver in VS2010 and click DEPLOY, oh how easy that makes things, butt what if you need to deploy that event receiver on another server.  Good luck with that.

Anyway, along the way, I eventually managed to do it, not without some pitfalls.  Here I describe a method that worked for me.

1. Create event receiver in VS2010

2. Right-click event receiver and click PACKAGE, the WSP file will be created in either your debug/release folder in your bin directory.

3. Copy WSP file to new server.

4. Open SharePoint Powershell

5. Run the following commands

6. Add-SPSolution -LiteralPath "path to wsp file\EventReceiverProject.wsp", you can check if it was installed using: Get-SPSolution "EventReceiverProject.wsp"

7. Install-SPSolution -Identity "EventReceiverProject.wsp"  -GACDeployment -CASPolicies

8. You will likely get an message saying admin service needs to run to Install, then just run this command: "stsadm.exe -o execadmsvcjobs"

9. Now to activate the feature, use the following command: stsadm -o activatefeature -n "EventReceiverProject2_Feature1" -url http://win-dtze75zqh6a

I discovered this at the following link http://social.technet.microsoft.com/Forums/en-AU/sharepoint2010programming/thread/5b8d6a87-1722-4dd3-af8e-767859291db9


You are done.  You can use SharePoint manager to check if you event receiver was correctly attached to your list.


To undeploy, its basically the above steps in reverse :-)


stsadm -o deactivatefeature -n "EventReceiverProject_Feature1" -url http://win-dtze75zqh6a/

Uninstall-SPSolution -Identity "EventReceiverProject.wsp"

Remove-SPSolution -Identity "EventReceiverProject.wsp"







Thursday, March 8, 2012

Sharepoint foundation 2010 - Item level permissions - filer lists in outlook

For this to work, you create the tasks list


Then open SharePoint Designer, open the list, create new workflow.


Create an impersonation step (Note: this step will run using the credentials you opened the SharePoint site with)


The following workflow is an example from some work I did, where we assign full control to only the assigned to person (or group).  I had to also add an additional step to also assign full control to another group (ADMIN), as the workflow would crash if I allowed multiple selection of groups/users for my assigned to column.




Let’s go through each step.

Set a variable equal to the Assigned to field for the current task list item


REPLACE the current task list item rights to Full Control for current Assigned To user/group.  Notice we used replace, this is important.



Then add same rights(as in B) for the ADMIN group, this is to ensure that we also have a group that we can put users into that can see everyone’s tasks.

Save the workflow, publish. Make sure you’ve set the start workflow on item create and change.  So when task is created, rights are assigned, also when task is changed, as assigned to may be changed, so we need to update the task.