Monday, April 3, 2017

SharePoint Designer workflow triggering multiple emails.

I had a list containing 8 people picker columns with allow multiple values set to true. It was having out of the box forms. Whenever user submits an item it sends an email to all the users marked in all the people picker fields. SharePoint Designer workflow was used to send email to users. Workflow was having just “send an email action”.

Issue: Users were getting n number of emails on item creation/updation.

Workflow Status: Workflow was stuck in suspended state and keeps on retrying because of retrying users were getting n number of emails.

Reason: For an item is number of total users in all people picker column reaches approx. 30 or more and where few duplicate users are added in multiple fields. Then the “send an email” action tends to go to suspended state and keeps on sending emails to users marked in people picker column until the workflow is terminated.


Solution: There should not be repeated users in multiple people picker fields. For ex. User1 Should not be present in Field1 & Field2 simultaneously.  For that you can add a client side validation before item submission notifying the users whenever there are any repetition of users. 

Monday, March 20, 2017

Get User Properties using User Profile in SharePoint Online

Below are some important properties which we can retrieve from user profile for a user by passing login id.

  • Cell Phone Number
  • Manager
  • Accountname
  • Displayname
  • Directreports
  • Email
  • Extendedmanagers
  • FirstName
  • LastName
  • Department
  • PictureURL
  • UserName etc..


I would be retrieving it using Login Id of the desired user. Login id by default in SharePoint Online is of below format.

i:0#.f|membership|manjot@xyz.com

If we directly pass this format it will give you “bad request” error since while passing URL to rest calls we need to encode few characters. In above case, we need to encode ‘#’ to ‘%23’. So our login id would be:

i:0%23.f|membership|manjot@xyz.com


Now pass login name as in below code which will give you the required property

var loginName='i:0%23.f|membership|manjot@xyz.com';

GetSPListItems("/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='CellPhone')?@v=" + "'" + loginName + "'", function(data) {
  
    console.log(data.d.GetUserProfilePropertyFor); // This will give you cell phone number

}, function(error) {
    console.log(error);

});

function GetSPListItems(url, Success, Error) {
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + url,
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
            "content-Type": "application/json;odata=verbose"
        },
        success: Success,
        error: Error
    });
}

If you want to access all properties then simply replace the URL in the above code with below value.
  // in above url we specified propertyName='CellPhone' to get specific property if you want to access all then simply remove that propertyName parameter.

 URL= _api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v)?@v=" + "'" + loginName + "'  

Wednesday, October 29, 2014

Changes in Term values not getting reflected in Sites - Taxonomy Update Scheduler Job

Issue: I had a list containing some managed metadata columns bound to the respective term sets. I populated some items in the list. Then I went to the Term Store and modified a value of term that was used in one of the item. But when I went back to the list item, it was still showing the previous term only.
Reason: When doing any changes in the term store, there is a timer job called “Taxonomy Update Scheduler” that runs in background and synchronize the changes with the sites. So it will update the modified terms in the respective sites once it would run.  
Solution: You can check the status of this Taxonomy Update Scheduler timer job by following below steps:
·         Go to Central Administration.
·         Click on Monitoring on left navigation.
·         Then Under Timer Job Section, click on Check Job Status.
·         Then Under Timer Links heading on left navigation click on Scheduled Jobs.
·         On Top Right Side, under view selects Web Application and choose your web application.
·         You can find Taxonomy Update Scheduler Job from the list of specified jobs.
So there you can configure how frequently you want it to run according to your needs but generally it is configured to run every hour.
Once it runs, you can go back to the list item and check it would contain the modified term value.

Tuesday, October 28, 2014

Powershell script to create Managed Metadata Columns for each Term Set in a Term Store

I was writing a PowerShell script to create Managed Metadata columns in the library corresponding to each Term Set in the specified term store.
So below is the script with comments.

#This will load the SharePoint Snappin if not already loaded and also it will not throw any error if already loaded.
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin Microsoft.SharePoint.PowerShell
}

    #define SPSite and SpWeb Object
    $spSite = Get-SPSite "http://sharepoint.com"
    $spWeb = $spSite.OpenWeb("")

    #Get Taxonomy Session
    $taxonomySession = Get-SPTaxonomySession -Site $spWeb.Site
    #Get TermStore
    $termStore = $taxonomySession.TermStores["Managed Metadata Service"]
    #Get Term group corresponding to which columns would be created in the target  list
    $group = $termStore.Groups["Term Group"]
    #Get Reference to List
    $targetList=$spWeb.Lists["Target List"]
    for($i=0;$i -lt $group.TermSets.Count;$i++){
    
     #Get Current TermSet    
     $termSet = $group.TermSets[$i]
    
     #Check if another column is already present in the list.
     if(!($targetList.Fields.ContainsField($termSet.Name)))
     {
         $taxonomyField = $targetList.Fields.CreateNewField("TaxonomyFieldType", $termSet.Name)

         #Gets or sets the GUID that identifies the TermStore object, which contains the Keywords for the site that the current TaxonomyField belongs to.
         $taxonomyField.SspId = $termSet.TermStore.Id

         #Gets or sets the GUID of the TermSet object that contains the Term objects used by the current TaxonomyField object.
         $taxonomyField.TermSetId = $termSet.Id

         #if true then user can select multiple terms
         $taxonomyField.AllowMultipleValues = $true

         #group in which this field will be saved
         $taxonomyField.Group = $fieldGroup
         $taxonomyField.StaticName = $termSet.Name
         $taxonomyField.ShowInEditForm = $true
         $taxonomyField.ShowInNewForm = $true
         $taxonomyField.Hidden = $false
         $taxonomyField.Required = $false
         $targetList.Fields.Add($taxonomyField);

        
     }
    }   
    $targetList.Update(); 
    $spWeb.Dispose()
    $spSite.Dispose()
   
    Write-host “Script Completed"           

Wednesday, October 1, 2014

Error while adding/updating Items

I was creating a PowerShell script to add files to Shared Documents library. Everything was going fine. I was able to add files to the library but suddenly I got the below error while running the script.





It says URL “Shared Documents/new.txt” is invalid. I was looking for error in script if I had done something wrong but it was the same script that was working fine a minute ago.  Error also says “It may refer to a nonexistent file or folder” but file and folder both exists.
I was able to upload document to library using PowerShell but in different web app. Now it was confirmed that Script is fine. So error was not with Script but with something else.
I tried to add and edit items in document manually by going to Shared Document Library and I got the below error. I was getting the error while doing any CRUD operations.












On doing some testing, I found that there was not enough space on database server which was causing the issue.
So the issue got resolved by cleaning up the database server.



Wednesday, September 10, 2014

Strange Boxes in Nintex Workflow Designer

Recently I was developing a workflow in Nintex but while working on it I found some strange extra boxes on the designer as shown in the image.



This is really strange. I tried to Google out if anyone faced this strange thing but hard luck. After consulting with Nintex Support, came to know that these strange boxes appears in cases where some custom css is being referred on master page.
Good news is after extensively testing the workflows found out that these are just visual error and do not impact the performance of the workflow.


 

Monday, September 8, 2014

Error in "Pause for" Action - Nintex Workflows

Error in Pause for Action
Recently I was working on a project where I had to develop multiple workflows calling each other. To provide some delays I used “Pause for” action at the start of the workflow so that the all the other workflows should complete before the current workflow proceeds ahead.
But what I found during this implementation was, whenever workflow pauses for some duration lets say 1  minute at “Pause for” action it throws error. But interesting thing was, even after throwing error, workflow continues to run and completes successfully.
Email triggered says Workflow Terminated unexpectedly for item.
Error message logged was “Error POC 1” failed to run.
I got below information when I discussed this issue with nintex support.

Reason: Nintex workflows are run by SharePoint workflow engine only (i.e. Windows workflow foundation). Workflow is first executed generally in World Wide Web Publishing Services (w3wp.exe). After a delay or pause, in which the workflow "sleeps", it wakes up and is then run by the SharePoint Timer Service (the owstimer.exe process). The only time this isn’t the case is if the w3wp.exe is under excessive load, in which case it postpones the workflow and the Timer Service is then used to the continue the process.

SharePoint dictates which Workflow Timer Service will run the workflow - so this could occur on any server on which the "Microsoft SharePoint Foundation Workflow Timer Service" is enabled.

When Nintex is deployed it install’s some DLL’s required for workflows on the WFE’s where
 Microsoft SharePoint Foundation Web Application service is enabled.
So when Workflow Timer Service attempts to run a workflow where Microsoft SharePoint Foundation Web Application is disabled it throws error.

Solution:
1)      Disable Workflow Timer Service to all the WFE’s where Microsoft SharePoint Foundation Web Application service is disabled.
2)      Or Enable Microsoft SharePoint Foundation Web Application Service on all WFE’s.

Related Issues: So due to the above reasons not only “Pause for” action throws error but some below mentioned actions also throws error.

Change State: Since while changing state in a State Machine Workflow, a hidden delay is involved. So in that case also, it may throw error in case after delay it got caught by WFE where Microsoft SharePoint Foundation Web Service is disabled but Workflow Timer Service is enabled.

Pause Until: This action also throws error while in a paused state until some date is passed.

Assign Flexi Task: Due to the delay involved before sending reminders, it may error out.

Similarly Task Reminder Action, Request Data, or any other action where delay is involved may throw errors if occupied by wrongly configured WFE’s.