Creating Service Applications through PowerShell – SP2013

This will be an ongoing post until all are completed. The below PowerShell will show you how to add a service application as well as delete.

For deleting a service application, run the ‘Get-‘ commands first which can all be found below before running the remove in order to find the ID or the name.

Managed Metadata Service Application

Create the App

#Creates a new Application Pool for Managed MetaData Service Application
New-SPServiceApplicationPool -Name “MetaData_AppPool” -Account “CHIN\sp2013farm”
#Creates new Managed MetaData Service Application
New-SPMetadataServiceApplication -Name “MetaDataServiceApp” -ApplicationPool “MetaData_AppPool” -DatabaseName “SP2013-MetaDataDB”
#Creates new Managed MetaData Proxy
New-SPMetadataServiceApplicationProxy -Name “MetaDataServiceProxy” -ServiceApplication “MetaDataServiceApp”

ManagedMetaData2

ManagedMetaData

Delete the App

#Get-SPServiceApplication
#Removes Service Application
Remove-SPServiceApplication “52845e68-e7e1-4a18-b223-b6ea246c302c”#Get-SPServiceApplicationPool
#Removes Service Application Pool
Remove-SPServiceApplicationPool “TestMetaData_AppPool1″#Get-SPServiceApplicationProxy
#Removes Service Application Proxy
Remove-SPServiceApplicationProxy “77b8604b-c465-46a3-95f8-de05a10fa8c7”

 

Excel Services Application

Create the App

#Creates new Excel App Pool
New-SPServiceApplicationPool -Name “Test-ExcelAppPool” -Account “CHIN\sp2013farm”
#Creates new Excel Services Application
New-SPExcelServiceApplication -Name “Test Excel Services Application” -ApplicationPool “Test-ExcelAppPool”

 

Delete the App

#Gets a list of all Service Applications
Get-SPServiceApplication
#Removes Service Application
Remove-SPServiceApplication “d356b611-40b9-4bcd-930b-36e2718675b9″#Gets a list of all Application Pools
Get-SPServiceApplicationPool
#Removes Service Application Pool
Remove-SPServiceApplicationPool “Test-ExcelAppPool”

ExcelServices1

ExcelServices2

ExcelServices3

 

Next App TBC

Create the App

 

Delete the App

 

Event ID 6398 – Unexpected exception in FeedCacheService.ISRepopulationNeeded

So I recently went crawling through some event logs while doing a health check on a SharePoint farm. I noticed this one in particular so I thought I’d investigate further.

DistributedCacheIssue3

The Feed cache service depends on the Distributed Cache Service, so checking if the distributed cache service is running in Central Administration (manage services on server section) is the first step. Tags and document activities are saved only to the Feed Cache, they are not persisted to content databases, so if the distributed cache service is stopped, the tags and document activities are lost. If the Distributed Cache service is started, repopulation occurs when the feed cache repopulation timer job runs every 5 minutes.

So with the information above, I checked the timer jobs that relate to this as well as the service in CA, both were setup correctly. The next step was to look into PowerShell to find out if the Cache host was working to which I found out it wasn’t.

DistributedCacheIssue1

Following the error shown above I thought I’d try and connect to the App Fabric Cluster Configuration and then restart it which thankfully worked.

DistributedCacheIssue2

Running Get-CacheHost again after the restart is complete will show you the Cache Host values.

Either run the timer job manually or wait 5 minutes for it to run then check the event viewer, hopefully the issue is gone!

There are other fixes out there for this however, this is the fix that seemed to work for my environment.

 

How to change SharePoint button display text

Changing the text for a button within SharePoint can be done through JQuery. Some of the requests I’ve had require this to say ‘Send’, ‘Submit’, ‘Cancel Request’ & ‘Back’.

To begin with, open the form you want this change made, for me, I’d like this on the NewForm. The below form is a copy of the new form that I’ve created in SharePoint Designer.

Buttontext

Edit the NewForm page and add a Script Editor Web Part. Copy the code below and paste in the script editor Web Part.  If you’d like the save value to be something other than save, make sure you change the part where I’ve written ‘Send’.

<script>
$(document).ready(function()
{
$(“input[value$=’Save’]”).attr(‘value’, “Send”);
});
</script>

Buttontext2

Save the changes and stop editing the page. Go back into the NewForm (New Item) page and check the changes.

Buttontext3

You can also edit the form in SharePoint Designer and place the code on the form that way.

Create a hyper-link to open in a new window

I get a fair amount of requests to open links in a new window, or just to create hyper-links on lists & libraries. Although this may become obvious for some people, it doesn’t for other newbies in SharePoint. I generally use the ‘Hyperlink with formatting and constraints for publishing’ column. Unfortunately this doesn’t show in the lists/libraries as an option when creating a column. This column has to be done at site level which can be found at Site Settings -> Site Columns (Under Web Designer Galleries).

To create a new column click ‘Create’ and fill in the name of the field and remember to select the correct type of column, screenshot below.

Hyperlink1

Save the column and return to your list.

Within your list go to List settings, towards the bottom of the page select ‘Add from existing site columns’ and you will be presented with the below. Find the column you’ve just created and click add, then click OK.

Hyperlink2

In your list create a new item and click ‘click to add a new hyperlink’, you will then see the fields that require filling out.

Hyperlink3

And lastly, the end result…

Hyperlink4

Reasons for Workflows failing

As I work with workflows I’ll be updating this post as I come across reasons as to why workflows fail to run.


1. Workflow History List Permissions

I’ve recently completed a lengthy approval workflow to which kept failing if an end user created the item, any user in the owners group worked correctly. The users had edit access on the list as well as the tasks list.

I noticed it kept failing at the start of the workflow as I have ‘log to history list’ to help understand where in the workflow I am in case of errors like this, as well as having statuses. I knew for sure users had full edit permissions on the two lists I created however, I didn’t think to check the Workflow History list permissions.

When having ‘log to history list’, users need to be able to edit that list in order for the workflow to log the item to the list which was my issue. I wasn’t using the default members group to group these users, I created my own groups which is why they never had access to that list, giving users access to that list made the approval work as expected.

As the history list is hidden, the easiest way to find this is to type in your SharePoint URL and add /lists/workflow%20history to the end.

https://sharepoint.com/tst/training/lists/workflow%20history

An alternative is to look in SharePoint Designer.
2. TBC

Hide Edit form & Display form columns based on another column

Over the past few months I’ve been asked whether it’s possible to hide columns based on the value of another column and whether it’s a fast and easy change, the answer is basically yes.

If you have a custom Display or Edit Form, you can manipulate the columns slightly to hide an irrelevant column. Take a look at the screenshots below of my SharePoint list and SharePoint Designer Form.

To begin with I have a list with just 4 columns. As you will notice two of the columns only relate to iPhone and therefore are useless if the phone is a Samsung.

HideColumnsInForm1

The way to hide the columns is through SharePoint Designer, edit the form in advanced mode and scroll down to your columns. The only modification that is required is to add <xsl:if test=”<COLUMN-NAME> = ‘COLUMN-RESULT'”> before the <tr> as well as after the </tr> as shown below.
HideColumnsInForm2(code isn’t lined up, sorry about that!)

The end results when I click on each item from my list are below.

 

 

HideColumnsInForm3 HideColumnsInForm4

Unfortunately this isn’t possible on the New Form as this would require it to be dynamic to which mine isn’t.

 

An alternative way of doing this is to use to code here: https://github.com/kitmenke/sputility, copy the jquery & sputility to a SharePoint Library and reference as below. This is ideal as the form is dynamic and to me, easier to work with. Credit goes to kitmenke!

***edit the form from within SharePoint (edit page) & insert a script editor webpart to paste the below in***

<script src=”https://sharepoint.com/tst/training/SiteAssets/jquery.js”></script>
<script src=”https://sharepoint.com/tst/training/SiteAssets/sputility.min.js”></script>

<script>
$(document).ready(function () {

var cityField = SPUtility.GetSPField(‘City’);

var showOrHideField = function() {
var cityFieldValue = cityField.GetValue();

if(cityFieldValue === ‘London’) {
SPUtility.HideSPField(‘PostCode’);
}
else {
SPUtility.ShowSPField(‘PostCode’);
}
};

showOrHideField();

$(cityField.Dropdown).on(‘change’, showOrHideField);
});
</script>

Workflow Approval Process

In recent months I’ve created many approval workflows for many different scenarios. In this post I will provide a step by step guide of how to create a basic approval workflow.

To start with I have a simple list, which has 3 approvers.
ApprovalWorkflow1
Stage 1

To start this workflow, open SharePoint designer, navigate to your list and create a new 2013 workflow. As per the screenshot below, in the ribbon select ‘local variables’, click add & input the name of the approver, I’ve done this three times due to three approvers (one for each approver).
ApprovalWorkflow2
Within the first stage of your workflow, click Actions in the ribbon and select ‘Set Workflow Variable’.

ApprovalWorkflow3

Fill out the details as follows:

In the top section:

Data Source: Select your list
Field from source: Select the column in your list
Return field as: Display Name

 

In the bottom section:

Field: Select the column in your list (same as Field from source)
Value: Press the fx and set the data source, field from source & return field as the above

Your variable should look something similar to the below.

ApprovalWorkflow4
When you click OK to close the ‘Lookup for String’ window, you will be greeted by the message below, just press Yes to this.
ApprovalWorkflow5

The last part for the first stage is to set the name of the stage, log to history list & then Transition to stage. To log what we’ve done to the history list, click ‘Action’ and select ‘Log to History List’. The reason this is done is for finding where in the workflow it gets to if any errors appear when ran. In order to transition to another stage, you will need to create another stage. This can be achieved by clicking the stage button in the ribbon (next to action).

If the above has been followed correctly, your workflow will look similar to the below.
ApprovalWorkflow6

 

Stage 2

I tend to keep the approval stage separate from everything else, which is the reason behind stages.

The first part of this stage is to create the task process.

  1. Select ‘Action’ in the ribbon, then ‘Start a task process’.
    ApprovalWorkflow7
  2. Click the ‘these users’ hyperlink for the window to open.
  3. Click the ellipses for Participants.
  4. Double click ‘Workflow Lookup for a User’
  5. Data Source: Workflow Variables and Parameters
    Field from source: Variable: Approval 1
    Return field as: Email Address
  6. Repeat steps 4 & 5 for the Approval 2 & Approval 3 Variable.
    ApprovalWorkflow8

Once complete, click OK and close the task process windows. Now create two more stages, name these ‘Approved’ & ‘Rejected’. Within the approval process stage, right click the Transition to stage area and choose ‘If any value equals value’. Click the fx for the first value and put

Data Source: Workflow Variables and Parameters
Field from source: Variable: Outcome
Return field as: ***Blank***

Now click the second value and choose approved. Within the IF statement, right click and choose go to stage, choose Approved, below the Else, do the same and choose rejected.

The end result will look like the below.
ApprovalWorkflow9

Stage 3 & 4

Stage 3 & 4 are similar to each other. The only real difference would be one is rejected and one is approved. Usually, once an item is approved or rejected, an email is sent out to the user who created the item to let them know it’s been approved however I shan’t go into detail on that. To finish the workflow, add an action of ‘Log to History List’ in both Approved & Rejected stages. On the Transition to stage, right click and choose go to stage, click the drop down and choose End of Workflow, this is for both the stages.

The end result is below. If you’d like to keep the user updated as to where in the approval this is, it may be ideal to use the ‘Set Workflow Status’ within the Actions in the ribbon. Alternatively, the workflow uses the Stage name for a status.

ApprovalWorkflow10

SharePoint 2013 Branding

Below are a few useful tips to hide items within SharePoint.

Remove quick launch

Before:
BrandingBefore
After:
BrandingRemoveQuickLaunch

Code:

<script type=”text/javascript”>
function pageLoad()
{
$(document).ready(function(){
$(“body”).addClass(“ms-fullscreenmode”);
$(“#fullscreenmode”).css(“display”, “none”);
$(“#exitfullscreenmode”).css(“display”, “”);
});
}
</script>

 

Hide Site Logo (top left of site)

Before:
BrandingBefore

After:
HideSiteIcon

Code:

<style>
div#siteIcon
{
display:none;
}
</style>

 

Hide Site Title

Before:
BrandingBefore

After:
HideTitle

Code:

<style>
.ms-core-pageTitle {
display:none;
}
</style>
Hide New Item & Quick Edit link

Before:
HideNewItemLinkBefore

After:
HideNewItemLinkAfter

Code:

<style>
.ms-list-addnew {
display: none;
}
</style>

 

Hide Column names

Before:
HideColumnName1

After:
HideColumnName2

Code:

 

<style>
.ms-viewheadertr {
display: none;
}
</style>

 

Hide Top Navigation

Before:
TopNav1

After:
TopNav2

Code:

<style>
.ms-breadcrumb-top {
display: none;
}
</style>

You can find all the data by using developer tools in your browser (f12 for IE & Chrome).

Set Focus on Content on a SharePoint page

Within SharePoint there is a small button in the top right which focuses on the content. Basically it hides the top navigation and quick launch.

For my own purposes I required this to be the default as I was creating a display page. The following code below helped achieve this, it’s also worth noting that the Focus button can still be pressed if the user would like to view the navigation/quick launch.

The code below is not my own, this was through Technet forum replies.

<script type=”text/javascript”>
function pageLoad()
{
$(document).ready(function(){
$(“body”).addClass(“ms-fullscreenmode”);
$(“#fullscreenmode”).css(“display”, “none”);
$(“#exitfullscreenmode”).css(“display”, “”);
});
}
</script>

Another way…

<script>
_spBodyOnLoadFunctionNames.push(“HideBrandingsuite”);
function HideBrandingsuite()
{
SetFullScreenMode(true);
}

</script>

 

Duplicate emails on SharePoint workflow

Recently I’ve had the issue of having duplicate emails on SharePoint 2013 workflows, specifically approval workflows. There are no errors within the workflow however, when I looked at the workflow status I noticed that it had looped the stages, although this wasn’t the plan of course.

I had tried many a time to insert pauses to let the workflow jobs catch up but this never worked until I then inserted a 2 minute pause right at the start of the workflow, luckily enough this stopped sending duplicates.

Note: I did have to recreate the workflow and add the pause, the pause is vital as without, the issue still happened when recreating a new workflow.