Trigger a SP workflow on a timer basis: Information management policies


How to trigger a workflow on a timer basis: Information management policies

Steps:

Configure settings on Document Library:

  1. Open SharePoint Site and go to Library Settings of document library where you want to configure Information Management Policies.
  2. On Library Settings Page click on the Content Type for which you want to configure Information Management Policies. E.g.:
  3. On Content type settings page click on “Information management policy settings”
  4. On Edit Policy Page, click on “Enable Retention” checkbox so the Add a retention stage link will be visible. Click on Add a retention stage link.
  5. On Stage properties dialog specify following input for time period:
    1. Select “Created” field in the columns dropdown.
    2. And specify 0 in the textbox and select days in the dropdown.
  6. On Stage properties dialog select “Start a workflow” in the action dropdown and in start this workflow dropdown select the workflow that you want to start and click on OK button in the dialog.
  7. Click on OK button on Edit Policy Page.

Change the schedule of Information management policies timer jobs

  1. Open SharePoint Central Administration Site and go to Monitoring -> Review job definitions.
  2. On Job Definitions Page, look for the “Information management policy” timer job for the web application where you have configured Information management policy on document library.
  3. On Edit Timer Job Page change the schedule to run every 1 min as follows:
    • Select Minutes radio button.
    • And specify 1 in the textbox.
    • Click on OK button.
  4. Again go to Job Definitions Page, look for the “Expiration policy” timer job for the web application where you have configured Information management policy on document library.
    • Select Minutes radio button.
    • And specify 2 in the textbox.
    • Click on OK button.
  5. Now workflow will be triggered approximately 3-5 minutes after a new document or form is created in your library using the content type for which you configured Information management policy.

Notes:

If you do any changes in workflow publish the workflow after configuring the information management policies then you will need to update the workflow in Information management policies settings as follows:

  1. Go to Information management policies settings of content type as mentioned in above steps(1 to 3)
    1. Click on “Edit” option for the retention policy.
    2. If you see the workflow then it must be showing Previous version in the Start this workflow dropdown as shown in the below screen shot.
    3. So change the workflow in the Start this workflow dropdown to the actual workflow that you want to run and click on OK button.
    4. Click on OK button on Edit Policy page.

Happy SharePointing !!

Get Yammer Group Details using PowerShell


Hello Guys,

While working with cloud platform you might face any random requirement from your clients. I was asked if it is possible to work with yammer using Powershell commands. My first thought was it should not be easy to do but with very first internet search, I found REST APIs which are exposed by yammer and can be utilized anywhere with developer token. I am sharing my first very basic yammer powershell command in this blog, I will explain how to get all of the Yammer groups using PowerShell.

Step 1: Register an app

Navigate to https://www.yammer.com/client_applications and register an app. Fill out mandatory details on the form and click on submit.


Once the app is registered, you can view details of newly created app under list of applications.

Step 2: Grab developer access token

Once the app is registered, navigate to Basic information tab and find out a link “Generate a developer token for this application” to generate a developer token.


Step 3: Create PS script file with commands

Copy the below script and paste it in a notepad. Save the file as AllGroups.ps1.

# Input Parameters  
$developerToken = "12240-*****PR2NWpZVtnbXYw"  
$uri="https://www.yammer.com/api/v1/groups.json"  
$headers = @{ Authorization=("Bearer " + $developerToken) }  
  
# Invoke Web Request  
$webRequest = Invoke-WebRequest –Uri $uri –Method Get -Headers $headers  
  
# Check whether the status code is 200  
if ($webRequest.StatusCode -eq 200) {  
  
    # Converts a JSON-formatted string to a custom object or a hash table.   
    $results = $webRequest.Content | ConvertFrom-Json  
  
    write-host -ForegroundColor Magenta "Groups Count: " $results.length  
  
    # Loop through all the groups  
    $results | ForEach-Object {  
        $group = $_   
        # Display the group name and members count  
        Write-Host -ForegroundColor Green "Group Name: " $group.full_name " - Members: " $group.stats.members  
    }  
}  
else {  
    Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status  
}  

Open PowerShell window and run the following command.

  1. >cd “<folderlocation>”  

folderlocation – YammerGroups.ps1 file location.

Run the following command.

  1. >.\YammerGroups.ps1  

So here is the list of groups that it returns:


Hope this blog helped you ! Do not forget to like and comment. Happy SharePointing !

Search Display Template: Show manager display name


In this post, I will explain how you can display the any user manager’s information in search display template. I assume here that you already have search configured on your SharePoint environment and basic knowledge of managed properties and search display template.

SharePoint introduced a technique for presenting search results: Display Templates during its 2013 release. If you have worked in previous versions of SharePoint and had to modify the look and feel of Search Results you know how cumbersome it is. After SP 2013 this rendering techniques have several distinct advantages.

  • Display templates are HTML and JavaScript rather than XSL
  • Display templates are configured for the Site and Site Collection rather than for a Web part
  • Display templates are applied with rules and logic
  • Display templates are applied to individual result items, not the entire result set
  • Display Templates are used for Results of all kinds, search results, content by search results, and refiners

If we talk about out-of-box template, it display search results like this:

Requirement:

Till this point all looks fine but what if you don’t like this version of format to show user details or may be your end user asked you to add some more information in this details like manger name or more. Definitely you require to do some custom code here. But question come where can we make change to make this happen.

Solution:

SharePoint display template by default gives you manager’s account name. I can easily be find out by debugging under developer’s tools(F12 of browser). Here are the steps:

  1. Navigate to Search result page where page is returning any results in terms of people.(/Pages/peopleresults.aspx?k=)
  2. Now press F12 of the browser, i recommend to use chrome for this purpose since it is very easy to locate resources in chrome.
  3. Under developer tools screen click on Sources tab. This will list down folders on left. Under _catalog folder expand /masterpage/display%20templates/search click on file “item_person.js”
  4. Now this is the key file which is used by sharepoint search page to render details of any person.
  5. Place a debugger and check out all the values that are out-of-box available. Here you will notice that for manager there is account name present. “ctx.CurrentItem.Manager
  6. It is very easy to locate what we are looking for. But friend no, life is not so easy in SP world, real challenge begins when you came to know that this field does not have name of manager. It have account name.

So Looks like you are on the right track by getting the manager accountID which isn’t useful to users in a display template. You can use this to get the rest of the profile information. The follow steps should get you going:

  1. Create a new “var” at the top of the template: var currentManager = ctx.CurrentItem.Manager so that you can call the variable later.
  2. At the bottom of the template add the function in this article. https://msdn.microsoft.com/en-us/library/office/jj920104.aspx where you can call multiple profile properties (its the second last JavaScript code example in the article)
  3. Update targetUser to targetUser = currentManager so we can get their profile info.
  4. The script will give you the PreferredName and Department, add any additional info that you need.
  5. Depending where exactly you want this information display, go to the area in the template that you want to show the manager’s name and put the following <div id=”ManagerValue”></div>
  6. go back to the onRequestSuccess fuction that is called if the call is successful and get rid of everything inside the function and enter the follow. $get(“ManagerValue”).innerHTML = personProperties.get_displayName(); you can also add addition <div> tags with additional information about the manager and add additional steps to the success function to show additional profile data about the manager. keep in mind you read the array from 0 up.. in the article the second profile data was the department, so you would add a div tag like <div id=”managerDept”></div> and add a success function step of document.getElementById(‘managerDept’) = userProfileProperties[1];
  7. Now save that and that will update the div to show the manager’s friendly name.

Let me share complete code for your reference so that it will be easier to just copy and paste without making any further efforts:

var has_mgr = !$isEmptyString(ctx.CurrentItem.Manager);
if(has_mgr == true) {
ms_outHtml.push(''
,'                                            <div id="ManagerField">'
); 
                                                var encodedMgr = $htmlEncode(ctx.CurrentItem.Manager);
                                                var displayMgr = Srch.U.getSingleHHXMLNodeValue(hhProps, "manager");
                                                if ($isEmptyString(displayMgr)) { displayMgr = encodedMgr }
												SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getUserProperties);
function getUserProperties() {

SP.SOD.executeFunc('userprofile', 'SP.UserProfiles.PeopleManager', function() {
      // Replace the placeholder value with the target user's credentials.
    var targetUser = $get("ManagerValue").innerHTML.trim();

    // Get the current client context and PeopleManager instance.
    var clientContext = new SP.ClientContext.get_current();
    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

    // Get user properties for the target user.
    // To get the PersonProperties object for the current user, use the
    // getMyProperties method.
    personProperties = peopleManager.getPropertiesFor(targetUser);

    // Load the PersonProperties object and send the request.
    clientContext.load(personProperties);
    clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
   });
 }
// This function runs if the executeQueryAsync call succeeds.
function onRequestSuccess() {
	$get("ManagerValue").innerHTML = personProperties.get_displayName();
}

// This function runs if the executeQueryAsync call fails.
function onRequestFail(sender, args) {
    console.log("Error: " + args.get_message());
}	
	
ms_outHtml.push(' '
,'                                                <span class="label">Manager :</span><div id="ManagerValue" class="ms-srch-ellipsis" title="', encodedOff ,'"> ', displayMgr ,' </div>'
,'                                            </div>'
); 
                                        }

Bingo !! This code does magic for us and get manager’s display name on basis of manager’s account name. Here is the screen shot what I got after running this code:

Hope my blog saved your time or guided you towards in direction of your goals.

Don’t forget to comment and like !

Happy SharePointing !!

Access SharePoint Online using Postman


There are number of ways to access the SharePoint API to fetch or update its resources. In all the ways, the authentication plays the important role in authorizing the access to get the information. As a developer, you may very much interested in using the PostMan tool for accessing the REST APIs.

Postman Chrome Extension
This is a developer friendly tool for handling the REST APIs from any platform. By using this tool we’ll fetch or update any information from SharePoint using REST API endpoints. We can get this utility from chrome extension and you can get that from this link PostMan Chrome Extension.

Postman & SharePoint Rest endpoints
If you are new to SharePoint REST API or you want to know more about REST endpoints in SharePoint; visit the link Get to know the SharePoint 2013 REST service.

Now we have some understanding about PostMan tool & SharePoint Rest API endpoints. Now we’ll start testing the SharePoint REST API with this tool.

Example

Let’s take a simple example like, getting the web title from the current site context. The equivalent syntax for retrieving the website’s title is

https://<SiteName&gt;.sharepoint.com/_api/web?$select=Title

After entering the above URL in the text-box in the URL text-box. We will get the Unauthorized exception on accessing the information. Because SharePoint Online is very much secured and that doesn’t allow anonymous users to access the information for their site. The below is the error message response, after sending the request.

.

UnAuthorized from Postman
Fig 1: UnAuthorized from Postman

To avoid the Unauthorized exception, we have to add some request header values to the API request. Authentication and Authorization of SharePoint Add-Ins gives the overview of authorizing the Add-ins to access SharePoint resources by the APIs.

Authentication Policies:

SharePoint online considers any one of the below three type of polices to authenticate the Add-In.

  • User Policy
  • Add-In Policy – We are using this policy to authenticate the external system to access SharePoint
  • User +Add-In Policy

Request Headers:

And, we require the following information in various requests to authenticate with SharePoint online site.

  • Client Id
  • Client Secret
  • Realm (Tenant Id)
  • Access Token

Authorize Postman to access SharePoint

To get authorized from external system, we should pass access-token value as a request header along with the REST API URL. Before that we have to get the access-token, for that we should generate Client Id and Secret information from the site by registering as an App only Add-In in SharePoint site. This is same as like registering add-in for Provider Hosted Add-In.

I have provided the steps below to get the Tenant Id, Access Token and data from SharePoint using PostMan utility.

Register Add-In

On initial stage, we have to register the Add-In in SharePoint, where we want to access the information. Follow the steps below to register the Add-In in SharePoint site.

  • Navigate and login to SharePoint online site.
  • Then navigate to the Register Add-In page by entering the url as

https://<sitename&gt;.SharePoint.com/_layouts/15/appregnew.aspx

  • On App Information section, click Generate button next to the Client Id and Client Secret textboxes to generate the respective values.
  • Enter Add-In Title in Title textbox
  • Enter AppDomian as a loclhost
  • Enter RedirectUri as a https://localhost
Register an Add-In
Fig 2: Register an Add-In
  • Click Create button, which registers the add-in and returns the success message with created information.
 Add-In Registration Successfull
Fig 3: Add-In Registration Successful

Grant Permissions to Add-In

Once the Add-In is registered, we have to set the permissions for that add-in to access the SharePoint data. We will set the Read permission level to the web scope, so that we will be able to read the web information.

  • Navigate to the SharePoint site
  • Then enter the URL https://<sitename&gt;.sharepoint.com/_layouts/15/appinv.aspx in the browser. This will redirect to Grant permission page.
  • Enter the Client ID(which we have generated earlier), in AppId textbox and click Lookup button. That will populate the value to other textboxes in Title, App Domain and Redirect Url
Fig 4: Set Permissions to Add-In
Fig 4: Set Permissions to Add-In
  • Now enter the below permission request in XML format.
    <AppPermissionRequests AllowAppOnlyPolicy="true">
        <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Read" />
    </AppPermissionRequests>
  • Then click Create button. This will redirect to you page, where we have to trust the add-in to read items from website.
Fig 5: Trust Add-In
Fig 5: Trust Add-In

Note: If we want to access site collection or tenant level, we have add the xml accordingly

Retrieve the Tenant ID

Once we registered the Client Id and Secret with the permissions, we are ready to access the SharePoint information from external system or tools.

At first, we have to know the Tenant ID. Follow the below steps to obtain that information from postman. Postman helps to get the tenant Id by requesting the below url with Authorization header.

  • Launch Postman chrome extension.
  • Select Get Method
  • Enter the below URL in the “Request URL” textbox
    https://<sitename>/sharepoint.com/_vti_bin/client.svc/
  • Configure the below information in the header section to send along with the url requestMethod = Get
    Headers

    KEY SYNTAX VALUE
    Authorization Bearer Bearer
  • After applied the configuration, click Send button. The response returns lot of headers but ends with unauthorized access.
    Fig 6: Get Tenant ID from SharePoint Online
    Fig 6: Get Tenant ID from SharePoint Online

Generate the Access Token

In response header, we will get WWW-Authenticate as one of the header and that contains the necessary information required for next step. The realm value contains the tenant id for the SharePoint Online site and clientid value contains the resource information (we’ll use it later).

KEY SYNTAX VALUE
Content-Type application/x-www-form-urlencoded application/x-www-form-urlencoded

Body

KEY SYNTAX VALUE
grant_type client_credentials client_credentials
client_id ClientID@TenantID 4b4276d0-74cd-4476-b66f-e7e326e2cb93@10267809-adcb-42b6-b103-c7c8190b3fed
client_secret ClientSecret nuC+ygmhpadH93TqJdte++C37SUchZVK4a5xT9XtVBU=
resource resource/SiteDomain@TenantID 00000003-0000-0ff1-ce00-000000000000/spsnips.sharepoint.com@10267809-adcb-42b6-b103-c7c8190b3fed
  • After applying the configuration, click Send button. That will returns the response with the Access Token.
Fig 7: Postman response contains Access Token
Fig 7: Postman response contains Access Token

Once we are received the access token, its like we got the authorization to access the SharePoint data based on the permission applied in Grant Permission as Add-In section.

We have to pass the access token as “token_type access_token

Access the SharePoint resource

Now we have the access token, So we can now pass this token in Authorization header with the SharePoint REST API to get the information.

  • In Postman tool, add the below URL to retrieve the web title

https://<sitename&gt;.sharepoint.com/_api/web?$select=Title

  • Apply configurations in header
  • Method = POST
    Headers

    KEY SYNTAX VALUE
    Accept application/json;odata=verbose application/json;odata=verbose
    Authorization <token_type> <access_token> Bearer eyJ0eX….JQWQ
  • After applying the configuration, click Send button.
  • We will get the response successful as below if the permission xml applied correctly in appinv page. Otherwise we will get the access denied error message.
Retrieve the web tile from postman
Fig 8: Postman returns the web title in response

Happy SharePointing !

Hide All Day Event and Recurrence field from SharePoint Calendar in SharePoint


A very basic requirement under the SharePoint Calendar list is to hide All Day Event column from all the forms and libraries. It looks very easy but unfortunately there is not direct way of implementing this change. One have to install SharePoint designer in order to achieve this requirement. Let explain in this blog how this requirement will be materialized.

Problem:

Hide “All Day Event” column from the new form of the calendar list. This is the requirement in my case, may be you want to hide “Recurrence” column. Steps should be same in case of any out-of-box column.

You must have tried to find out the ways to hide this column from List settings > columns details. Firstly, this column is part of “Event” content type and will only be find under content type settings. Ok, seems easy, just visit CT settings and mark it hide.

Well, life is not so easy in this arena. These three columns are not allowed to update as these are handled by SharePoint itself.

Solution:

  1. Install SharePoint Designer on your machine. It works for all version of sharepoint so SPD is the best option to make changes.
  2. Open the SharePoint site where Calendar list resides.
  3. Click on the List and Libraries sections.
  4. Find out where the Calendar list of present and click to open this list.
  5. While you are under List details screen on right portion of the screen, find out Content types section.
  6. There must be “Event” content type visible under the list content types. Click on the content type “Event” to open its details.
  7. Now under customization section, click “Edit content type columns” option. This will navigate you to a columns details page.
  8. On this screen, select “All Day Event”.
  9. Under Property column you can see three options. From the drop down select Hidden(Will not appear in forms)
  10. Or, When you have selected “All Day Event” column, navigate to top ribbon and select “Administrative Web Page”
  11. It will navigate you on a browser and open a page where you can easily select option: Hidden(Will not appear in forms)

I hope this information will be helpful and save lot of time. Do not forget to like this article if it was valuable information for you.

Thanks for your valuable time !

Happy SharePointing :).

Blog post filtering based on category not working


Hello,

Recently, I faced an issue while working with SP Online blog site. This issue applies to other versions of SharePoint as well.

If you are working on blogs on SharePoint platforms, you might have faced an issue when trying to filter blog posts based on category by hitting the category link shown on the Quick Launch or the category associated to the post. Doing so returns ALL posts what ever the category you asked to display (as shown below).

Steps To Reproduce:

There could be multiple reasons of this issue. Mainly, “Category.aspx” page is responsible for rendering this kind of display. You must be very cautious when doing any changes on this page. This page does not have any check-in/check-out or publishing feature so you can not revert to previous version of this page. In case you broke the linking between blog tools and other web parts it is very hard to restore it in working stage. Most of the blog sites recommend you to recreate blog site again(you will loose all blogs).

In my case, I landed up to this issues by following below two steps:

  • Go to the Posts list settings to enable Content Approval
  • Then disable the Content Approval

This has been confirmed and escalated for resolution. It appears this is because the XML query is being modified by removing the category filtering.

However, in the mean time, here is a workaround.

WORKAROUND

  • Create a blog site and do not enable the Content Approval(This step is only for getting unmodified code for reference)
  • Using SharePoint Designer open the new blog site and browse to All files\Lists\Categories and edit the category.aspx page

 

  • Open your faulty blog site and do the same (edit the category.aspx page)
  • Locate the following code (NOTE: the GUID is the specific one to your environment)

<View Name=”{F28F9AA8-7F35-4912-BAF5-1A225F33B484}” Type=”HTML” Hidden=”TRUE” ReadOnly=”TRUE” FreeForm=”TRUE” ModerationType=”HideUnapproved” DisplayName=”” Url=”/Lists/Categories/Category.aspx” Level=”1″ BaseViewID=”8″ ContentTypeID=”0x” ><Query><OrderBy><FieldRef Name=”PublishedDate” Ascending=”FALSE”/><FieldRef Name=”ID” Ascending=”FALSE”/></OrderBy></Query><ViewFields><FieldRef Name=”Title”/><FieldRef Name=”Body”/><FieldRef Name=”Author”/><FieldRef Name=”PostedByWithDate”/><FieldRef Name=”CategoryWithLink”/><FieldRef Name=”Permalink”/><FieldRef Name=”EmailPostLink”/><FieldRef Name=”NumCommentsWithLink”/><FieldRef Name=”PublishedDate”/><FieldRef Name=”PostCategory”/><FieldRef Name=”AverageRating”/><FieldRef Name=”RatedBy” Explicit=”TRUE”/><FieldRef Name=”Ratings” Explicit=”TRUE”/></ViewFields><RowLimit Paged=”TRUE”>10</RowLimit><JSLink>sp.ui.blogs.js</JSLink><XslLink>blog.xsl</XslLink><Toolbar Type=”None”/></View>

  • Add the following code after the </OrderBy> and before the </Query> tags

<Where><And><And><In><FieldRef Name=”PostCategory” LookupId=”TRUE”/><Values><Value Type=”Integer”><IfEqual><Expr1><GetVar Scope=”Request” Name=”CategoryId”/></Expr1><Expr2/><Then>-1</Then><Else><GetVar Scope=”Request” Name=”CategoryId”/></Else></IfEqual></Value></Values></In><Leq><FieldRef Name=”PublishedDate”/><Value Type=”DateTime”><Today/></Value></Leq></And><Eq><FieldRef Name=”_ModerationStatus”/><Value Type=”ModStat”>0</Value></Eq></And></Where>

  • which then looks like

<View Name=”{F28F9AA8-7F35-4912-BAF5-1A225F33B484}” Type=”HTML” Hidden=”TRUE” ReadOnly=”TRUE” FreeForm=”TRUE” ModerationType=”HideUnapproved” DisplayName=”” Url=”/Lists/Categories/Category.aspx” Level=”1″ BaseViewID=”8″ ContentTypeID=”0x” ><Query><OrderBy><FieldRef Name=”PublishedDate” Ascending=”FALSE”/><FieldRef Name=”ID” Ascending=”FALSE”/></OrderBy><Where><And><And><In><FieldRef Name=”PostCategory” LookupId=”TRUE”/><Values><Value Type=”Integer”><IfEqual><Expr1><GetVar Scope=”Request” Name=”CategoryId”/></Expr1><Expr2/><Then>-1</Then><Else><GetVar Scope=”Request” Name=”CategoryId”/></Else></IfEqual></Value></Values></In><Leq><FieldRef Name=”PublishedDate”/><Value Type=”DateTime”><Today/></Value></Leq></And><Eq><FieldRef Name=”_ModerationStatus”/><Value Type=”ModStat”>0</Value></Eq></And></Where></Query><ViewFields><FieldRef Name=”Title”/><FieldRef Name=”Body”/><FieldRef Name=”Author”/><FieldRef Name=”PostedByWithDate”/><FieldRef Name=”CategoryWithLink”/><FieldRef Name=”Permalink”/><FieldRef Name=”EmailPostLink”/><FieldRef Name=”NumCommentsWithLink”/><FieldRef Name=”PublishedDate”/><FieldRef Name=”PostCategory”/><FieldRef Name=”AverageRating”/><FieldRef Name=”RatedBy” Explicit=”TRUE”/><FieldRef Name=”Ratings” Explicit=”TRUE”/></ViewFields><RowLimit Paged=”TRUE”>10</RowLimit><JSLink>sp.ui.blogs.js</JSLink><XslLink>blog.xsl</XslLink><Toolbar Type=”None”/></View>

  • Save the page, the category filtering is working again

To finalize the operation, open the category.aspx page with your web browser to remove the Blog Tools webpart which will be in error and add it again.

Happy SharePointing !!!

Create a workflow with elevated permissions by using the SharePoint Workflow platform


Hello,

There are various reasons that one requires elevated privileges to list/site workflow. Most common use case is, if workflow need to fetch data from some other list/library at site collection/sub site level.

SharePoint App-Only is the older, but still very relevant, model of setting up app-principals. This model works for both SharePoint Online and SharePoint 2013/2016 on-premises and is ideal to prepare your applications for migration from SharePoint on-premises to SharePoint Online. Below steps show how to setup an app principal with tenant full control permissions, but obviously you could also grant just read permissions using this approach.

Applies To
  • SharePoint 2013/2016
  • SharePoint Online

This blog is also targets resolution of following error:

The Workflow was Suspended with Unauthorized HTTP

OR

Unauthorized HTTP to /_vti_bin/client.svc/web/lists

Issue:

By default, the SharePoint workflow doesn’t have sufficient permission to access the SharePoint lists, and this process requires a full control permission level.

Some important point before enabling App Step:

  • To allow the workflow to use APP permissions, you must be a Site Owner or Site Collection Administrator.
  • App Step can be activated at Tenant/Site Collection/Web.
  • The Workflow Manager platform must be configured properly to be able to activate “Workflows can use app permissions” feature.
  • The App Management Service must be configured to be able to grant a full control permission to a workflow.
  • App step provides the workflow authorization for its Identity as a Full Control and ignores the current user permission.
  • The SharePoint 2010 workflow is not supported in App Step,
  • If you don’t elevate the permissions for the SharePoint Workflow, The App Step will be disabled in the SharePoint Designer.

Solution:

To begin the elevation process, follow below steps:

  1. Allow workflow to use app permissions
  2. Grant full control permission to a workflow
  3. Develop the workflow actions inside an App Step using SharePoint Designer

Lets deep dive in details of all three steps mentioned above.

I. Allow workflow to use app permissions: 

The Workflow Manager platform must be configured properly to be able to activate “Workflows can use app permissions” feature. This feature is scoped to the web level feature so in case of site collection or web. This feature is available under web features.

  • Open the SharePoint Site > Site Settings.
  • Below Site Actions > Select Manage site features.
  • Activate Workflows can use app permissions feature.

In above step, we have ensured that after activating this feature, workflow can able to use permission which we will define under next step.

II.  Grant full control permission to a workflow

  • Open the SharePoint Site Collection > Site Settings >Below Users and Permissions > Click on Site App Permissions.

  • Copy the client section of the App Identifier. The App Identifier is the identifier Guid between the last “|” and the “@” sign, as shown below.

  • Navigate to grant permission to an app page by browsing the “appinv.aspx” page of the web site.

http://siteurl/_layouts/15/appinv.aspx.

  • Paste the client section of App Identifier to the App Id field.
  • Click Lookup to fetch the required info.
  • The App Management Service must be configured to be able to lookup your identifier. If the App Management Service is not installed you will get the below error when you clicked on Lookup button.

  • Paste the below APP Permissions Request XML to grant full control permission. Make sure tags and attribute names are in correct casing because small case will not be detected.

<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl">
</AppPermissionRequest></AppPermissionRequests>

 

 

  • You will then be asked to trust the Workflow app, Click Trust It.

III. Develop the workflow actions inside an App Step using SharePoint Designer

The App Step option will be disabled in the SharePoint Designer, in case you are not followed above mentioned steps. Using App step will allow the workflow to be authorized with its identity as a Full Control and ignore the current user permissions. This is will ensure that the workflow will be executed successfully in case the current user has no permissions.

Good to Go !! Once it is added it to workflow, it is easy to write any action under it.

NOTE: If you still see app step as disabled then close the SPD instance and reopen it. If still not see it enabled, then make sure you have done above steps in correct site collection/web.

NOTE: Make sure, Under Workflow Settings >  Uncheck the “Automatic updates to workflow status to the current stage name“, then click Publish.

If you didn’t uncheck “Automatic updates to workflow status to the current stage name“, the current user will require Edit permission on the list to can edit the workflow status.

Happy SharePointing !!

Enable empty SP search textbox does not update results


Hi Guys,

This post is about enabling empty search queries. By default, when user press ‘Enter’ on an empty Search Box, nothing happens.  A very simple question might be asked that why would anyone search for empty string any way?  True, no one actually needs it desperately but while going in flow this case could cause user bed experiences because users are likely to start with the refiners.

Problem:

Consider this flow:

  1. Navigate to SharePoint Search page
  2. Search with any keyword like “Test”
  3. If search results are not relevant, I just removed Test keyword from the textbox and hit search button.
  4. Nothing actually happens here. It suppose to clear all existing results.

Without the ability to search for the empty string (or a “clear” button), the only way to do same would be to reload the page.

Solution: 

The Search Box webpart supports empty string search. Yes, its true, it’s just disabled by default.  This feature is controlled by a property, AllowEmptySearch, which can not be managed from the UI. This fix is rather easy. This is a property that can be set on the search box, by default set to false. Follow the given instructions to update this property:

  1. Edit the page where search box is placed.
  2. Export your Search Box webart.
  3. Edit the .webpart file using your favorite text editor
  4. Search for the property AllowEmptySearch and update its value to True.
  5. Now import this web part to gallery and add it to your page in place of default search box web part.

This functionality is necessary when you have pages on which you configured the search web parts to use predefined queries in order to show results when the page gets loaded.

When you update this property to true, which can be done by exporting the search box web part, and changing the following line in the XML:

<! old >
<property name=“AllowEmptySearch” type=“bool”>False</property>
<! new >
<property name=“AllowEmptySearch” type=“bool”>True</property>

Note: you can also update the web part with PowerShell.

Another way to approach it is via setting this property from within your display template. To update the property within the search box display template, you have to add the following lines of code:

// Allow empty keyword searches
if (!ctx.ClientControl.get_allowEmptySearch()) {
    ctx.ClientControl.set_allowEmptySearch(true);
}

Hope this small trick helps you solve this issue.

Happy SharePointing !

Ref: Enable empty SPsearch textbox does not update results

Add welcome pop up for first time users of your site using AngularJs Material


Hi Guys,

We really do only have one chance for putting a first impression for end users on our website. User’s will never land back to your website if there is nothing interesting found on web site. Same logic works for SharePoint sites too. When a visitor lands on your site for the first time (and maybe the last), how you welcome them will have a big impact. This can be accomplished with pop-up boxes, fullscreen welcome mats, live chat invitations, and more.

This post is all about a welcome popup on SharePoint site. In brief, I try my best to provide very easy solution of showing welcome pop up.

Requirement: One of my recent project client asked to show a welcome message. Server side webarts are not promoted by out clients because our site was built in SP online. It sounds very easy but complication added by showing this pop up only once per user.

Solution: As a solution, i suggested to achieve this using Content editor web part. Just place some quick JS code on the landing page and with the help of a list we are able to detect if user is first time user or not. So here is the components of this solution:

  1. A list “Users” which stores list of first time users
  2. Content editor web part.
  3. Site Assets library to refer the local references like Angular, Jquery, css etc.

Let me go through step by step implementation of this solution.

Step I: Create a “Users” list

  1. Visit Site > Site contents.
  2. Click on New > Choose Custom List template> Name it as “FirstTimeUsers”.
  3. Once list is created. Navigate to newly created List settings > Add column
  4. Add column “User” of type “Person and Group”.
  5. Now with this list Title field is required. We can make this field hidden or optional if not required.

We are done with creating a list which stores information about first time users. We will be updating using rest api calls and each time when user logged on to site. His/her entries will be added to this list only.

Step II: Add references for angular, material, jquery etc.

This step can be skipped in case you need to refer all required libraries from CDN. But I never recommend this way, rather download the latest files to Site assets library. It also reduces extra burden on your site to download these library each time from CDN.

  1. Navigate to the Site assets library.
  2. Create a folder called “CustomFiles”.
  3. Create another folder “AngularJS”.
  4. Download files angular.min.js, angular-animate-min.js, angular-aria.min.js, angular-material.min.css, angular-material.min.js, angular-messages.min.js, jquery-3.3.1.min.js
  5. Upload these files to AngularJs folder.   

Step III: Create angularJS app files

  1. Create two files named as: dialog.tmpl.html and dialogApp.js
  2. Copy following code to dialog.tmpl.html file: dialog_tmpl_html
  3. Copy following code to dialogApp.js: dialogapp_js
  4. Now change the <Site URL> with the url of your site.

These two files are required for angularJS to initialize and configure to show dialog box. The html file can be used to modify contents of dialog box.

Step IV: Add content editor webpart on homepage.

  1. Navigate to the page where you need to show pop up
  2. Edit this page and click on add webpart under any zone
  3. Under “Media and content” find “Content Editor” web part. and add it.
  4. Now Edit this web part and under ribbon find “Format text” tab and “Edit Source” option under it.
  5. Now past following code here:

http://SiteURL/SiteAssets/customfiles/angularjs/angular.min.js

http://SiteURL/SiteAssets/customfiles/angularjs/angular-animate.min.js

http://SiteURL/SiteAssets/customfiles/angularjs/angular-aria.min.js

http://SiteURL/SiteAssets/customfiles/angularjs/angular-messages.min.js

http://SiteURL/SiteAssets/customfiles/angularjs/angular-material.min.js

http://SiteURL/SiteAssets/customfiles/dialogApp.js
http://SiteURL/SiteAssets/customfiles/angularjs/jquery-3.3.1.min.js
<link href=”<SiteURL>/SiteAssets/customfiles/angularjs/angular-material.min.css” rel=”stylesheet”/>

​​​​​​​

</div>

That is it. Just save your page and Publish it.

Step V: Test your pop up.

Now log on with separate users on the home page and check if there is entry created under “FirstTimeUsers” list.

Let me explain here a little about the ajax calls here. The code under dialogApp.js files first get the information of the logged on user. Get user information SharePoint using REST Api. Then using REST api, it tries to find out its entry under “FirstTimeUsers” list. Here is the rest call:

/_api/web/lists/getByTitle(‘FirstTimeUsers’)/items?$select=User/EMail&$expand=User&$filter=User/EMail eq ‘<email_of_user>’

In case, it found any entry popup is not shown to user. But if it has found any entry then pop up is shown and on close event of the pop up another rest query will insert entry to the FirstTimeUsers List.

That is all about it. Don’t forget to hit like and kindly rate this article.

Happy SharePointing !!!

 

Get user information SharePoint using REST Api


Hi,

While working on a requirement, I encountered a scenario where I need to show welcome pop up to the first time users. First time user, SharePoint does not provide any api or any solution which gives information about users who logged on first time on your web site. I have documented the whole solution on some other post(Add welcome pop up for first time users of your site using AngularJs Material) But this post I only want to scope it to retrieve information of logged on user. Information mean current user’s accountId, First name, Last name, Email and other required details.

I am only talking about client side code here i.e. using REST api or SP default APIs. Below are the various ways to get the property of current user who is logged on to SP site. There are many ways to achieve this requirement but I prefer to use SP.UserProfiles.PeopleManager Api to get it. It gives us vast option to retrieve any user information. Here are some details of getting various details:

  1. Get all properties of current user:

    http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties

  2. Get single property of current user:

    http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties/PictureUrl

    OR

    http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PictureUrl

  3. Get Multiple Properties for the current user:

    http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PictureUrl,AccountName

  4. Get all properties of Specific User:
    For Office 365/SharePoint Online:

    http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v=’i:0%23.f|membership|mohit.vashishtha@siteurl.onmicrosoft.com’

    For SharePoint 2013 On-Premise:

    http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v=’domain\username’

  5. Get Specific UserProfile Property of Specific User:
    For Office 365/SharePoint Online:

    http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName=’LastName&#8217;)?@v=’i:0%23.f|membership|mohit.vashishtha@siteurl.onmicrosoft.com’

    For SharePoint 2013 On-Premise:

    http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v=’domain\username’

NOTE: I had issues with getting the specific property for a user on #5. This worked fine though:

http://siteUrl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v=’domain\mohit.vashishtha’&$select=DisplayName,AccountName,PictureUrl

Here are some details about user properties:

List of User Properties (Use the GetPropertiesFor function for these):

  • AccountName
  • DirectReports
  • DisplayName
  • Email
  • ExtendedManagers
  • ExtendedReports
  • IsFollowed
  • LatestPost
  • Peers
  • PersonalUrl
  • PictureUrl
  • Title
  • UserProfileProperties
  • UserUrl

List of User Profile Properties (Use the GetUserProfilePropertyFor function for these):

  • AboutMe
  • SPS-LastKeywordAdded
  • AccountName
  • SPS-Locale
  • ADGuid
  • SPS-Location
  • Assistant
  • SPS-MasterAccountName
  • CellPhone
  • SPS-MemberOf
  • Department
  • SPS-MUILanguages
  • EduExternalSyncState
  • SPS-MySiteUpgrade
  • EduOAuthTokenProviders
  • SPS-O15FirstRunExperience
  • EduPersonalSiteState
  • SPS-ObjectExists
  • EduUserRole
  • SPS-OWAUrl
  • Fax
  • SPS-PastProjects
  • FirstName
  • SPS-Peers
  • HomePhone
  • SPS-PersonalSiteCapabilities
  • LastName
  • SPS-PersonalSiteInstantiationState
  • Manager
  • SPS-PhoneticDisplayName
  • Office
  • SPS-PhoneticFirstName
  • PersonalSpace
  • SPS-PhoneticLastName
  • PictureURL
  • SPS-PrivacyActivity
  • PreferredName
  • SPS-PrivacyPeople
  • PublicSiteRedirect
  • SPS-ProxyAddresses
  • QuickLinks
  • SPS-RegionalSettings-FollowWeb
  • SID
  • SPS-RegionalSettings-Initialized
  • SISUserId
  • SPS-ResourceAccountName
  • SPS-AdjustHijriDays
  • SPS-ResourceSID
  • SPS-AltCalendarType
  • SPS-Responsibility
  • SPS-Birthday
  • SPS-SavedAccountName
  • SPS-CalendarType
  • SPS-SavedSID
  • SPS-ClaimID
  • SPS-School
  • SPS-ClaimProviderID
  • SPS-ShowWeeks
  • SPS-ClaimProviderType
  • SPS-SipAddress
  • SPS-ContentLanguages
  • SPS-Skills
  • SPS-DataSource
  • SPS-SourceObjectDN
  • SPS-Department
  • SPS-StatusNotes
  • SPS-DisplayOrder
  • SPS-Time24
  • SPS-DistinguishedName
  • SPS-TimeZone
  • SPS-DontSuggestList
  • SPS-UserPrincipalName
  • SPS-Dotted-line
  • SPS-WorkDayEndHour
  • SPS-EmailOptin
  • SPS-WorkDayStartHour
  • SPS-FeedIdentifier
  • SPS-WorkDays
  • SPS-FirstDayOfWeek
  • Title
  • SPS-FirstWeekOfYear
  • UserName
  • SPS-HashTags
  • UserProfile_GUID
  • SPS-HireDate
  • WebSite
  • SPS-Interests
  • WorkEmail
  • SPS-JobTitle
  • WorkPhone
  • SPS-LastColleagueAdded

Happy SharePointing !!!

%d bloggers like this: