Showing posts with label Nintex Workflows 2010. Show all posts
Showing posts with label Nintex Workflows 2010. Show all posts

Monday, October 26, 2015

How to check if user is member of an SP Group in a Nintex Workflow

There is no direct method to determine that if current user who is triggering a Nintex workflow on a list item is member of a SharePoint Group or not. In one of my recent projects I needed that functionality to differentiate set of actions based on user's group membership.A common example is that if user is member of an HR group for purpose of approval.

Achieving this is easy in a Nintex Form by using the built in method "fn-IsMemberOfGroup". This function takes one argument that is the "Group Name" and returns true or false indicating the membership status of current user for given SP group.

Getting the same functionality in Nintex Workflow is not straight forward. It requires couple of actions to achieve the same result. Here is the solution of how this can be achieved in a Nintex Workflow.

1. In Nintex Workflow designer add couple of variables to the workflow

varUserGroupResults     Multiple lines of text
currentUser                     Person or Group
varUserGroupNames      Collection
varUserMemberOfGroup Yes/No

2. Next add "Call Web Service" action and in the action set the following details as shown in the screenshot. This service call calls the usergroup.asmx web service and calls GetGroupCollectionFromUser web method to get all groups to which the user has access to.


The resulting groups are stored in varUserGroupResults in XML format.
3. Now extract the group names as a collection using Query XML action. Add Query XML action to the workflow having following details

Now all the group names are in the collection and easy to iterate through.
4. Add "Collection Operation" action to the workflow to iterate through and compare the value with a group name you want to check against e.g. Approvers Group. If comparison returns true then user is part of that group else not.

The variable varUserMemberOfGroup is a boolean type which shows that whether current user is part of a specific SharePoint group or not.

There might be other ways of achieving the same result but just thought of sharing this as it took me a while to make this working.

Happy Work-flowing!!


Wednesday, May 13, 2015

Nintex Workflow Task Form giving error Failed to retrieve form from workflow. Error: Value cannot be null.

Issue: A strange error started coming on one of the SharePoint 2010 environment when a Nintex 2010 workflow task form is opened by the assigne, it breaks and does not open the task form. The reason is unknown but the issue is grave because none of the assigned task form works.

Detailed error stack trace is like

Area     : SharePoint FoundationCategory : GeneralEventID  : 8ncaMessage  : Application error when access /XXXX/Lists/Workflow Tasks/EditForm.aspx, Error=Value cannot be null.  Paramete           r name: s   at System.IO.StringReader..ctor(String s)     at Nintex.Workflow.WorkflowConfig2010.LoadWorkflow           Config(String configXml)     at Nintex.Workflow.Forms.ControlTemplates.TaskForm.GetWorkflowConfig()     at N           intex.Workflow.Forms.ControlTemplates.TaskForm.GetForm(String formKey, FormData formData)     at Nintex.Work           flow.Forms.ControlTemplates.TaskForm.ConfigureFiller()     at Nintex.Workflow.Forms.ControlTemplates.TaskFor           m.InitialiseForm()     at Nintex.Workflow.Forms.ControlTemplates.TaskForm.OnInit(EventArgs e)     at System.           Web.UI.Control.InitRecursive(Control namingContainer)     at System.Web.UI.Control.InitRecursive(Control nam           ingContainer)     at System.Web.UI.Control.AddedControl(Control control, Int32 index)     at Microsoft.Share           Point.WebPartPages.ListFormWebPart.CreateChildControls()     at System.Web.UI.Control.EnsureChildControls()               at Microsoft.SharePoint.WebPartPages.WebPart.get_WebPartMenu()     at Microsoft.SharePoint.WebPartPages.          ListFormWebPart.CreateWebPartMenu()     at System.Web.UI.Control.OnLoad(EventArgs e)     at Microsoft.ShareP           oint.WebPartPages.ListFormWebPart.OnLoad(EventArgs e)     at System.Web.UI.Control.LoadRecursive()     at Sy           stem.Web.UI.Control.LoadRecursive()     at System.Web.UI.Control.LoadRecursive()     at System.Web.UI.Contro           l.LoadRecursive()     at System.Web.UI.Control.LoadRecursive()     at System.Web.UI.Control.LoadRecursive()               at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAft           erAsyncPoint)


Resolution: In order to resolve this issue I tried saving the task form by opening the task form in the Nintex workflow and saving it, republishing the workflow couple of times but in vain. Even the ULS logs provided only the above error with no clue as to why it was breaking. I took following steps to resolve this issue:

1. Export the existing error prone workflow as a backup copy.
2. Delete the workflow from the list in the current environment.
3. Export the same workflow from another environment i.e. production.
4. Imported the exported workflow to the problematic environment and publish it.

After publishing the workflow the task forms started opening correctly and the error was gone. There was no change in list permission level, site user groups, list definition or task form. However, it might save someones time in getting around such issue.

Happy Workflow-ing :)