Showing posts with label Workflow Designer. Show all posts
Showing posts with label Workflow Designer. Show all posts

2016-12-14

Setting Related Item on a SharePoint 2013 Worfklow's SingleTask

Sometimes when we design workflows it is necessary to set related item in SingleTask to something different than the default listitem. Default list item is the item on which workflow was started. So, lets say we start workflow on doc1.docx. Inside the workflow we define SingleTask. This SingleTask, when opened in SharePoint UI, will have, by default, a link to doc1.docx. Sometimes we would like this SingleTask to have related item which is different than that particular doc1.docx.

Microsoft has intended for this purpose SingleTask argument named RelatedContentLinkListItemIntegerId. Great, you just set the list ID and item ID and you have your problem solved. Wrong!! Setting this property will have no impact on related item. At least, not if you use default generated SingleTask activity.

The solution:
Setting RelatedContentLinkListItemIntegerId will only work if you delete a particular child element in workflow markup (XAML). So, first open your workflow in Code mode (Visual Studio View Code - F7). Then locate the SingleTask activity which you would like to configure. This should be p:SingleTask XML element. Delete p:SingleTask.RelatedContentLinkListItemId child elemet. Save your workflow and voila, it will change related item to whatever value you set it.

2015-12-22

NullReferenceException When Clicking a Task in Workflow Designer

The other day I was designing a Workflow (Workflow Manager technology) in Visual Studio 2012 when I stumbled upon on an exception when clicking on a SingleTask activity in Workflow Designer within Visual Studio. When I first click on a task I get "Communicating with SharePoint" dialog:


After Visual Studio establishes communication with SharePoint I end up with the following dialog:

Full exception stack trace is as follows:
-------------------------
Workflow Designer
-------------------------
NullReferenceException:
Object reference not set to an instance of an object.
-------------------------

Server stack trace:
   at Microsoft.VisualStudio.SharePoint.Designers.List.ModelAccess.SharePointSolutionModelStorage.GetAllFiles(ISharePointProject project)
   at Microsoft.VisualStudio.SharePoint.Designers.List.ModelAccess.SharePointSolutionModelStorage.Refresh(ISharePointProject project)
   at Microsoft.VisualStudio.SharePoint.Designers.List.ModelAccess.SharePointCompositeModelStorage.RefreshProjectModels()
   at Microsoft.VisualStudio.SharePoint.WorkflowDesignerSupport.ListInfoService.GetContentTypes(String BaseTypeId)
   at Microsoft.VisualStudio.SharePoint.WorkflowExtensions.SharePointListService.<GetWorkflowTaskContentTypes>b__10(IListInfoService service)
   at Microsoft.VisualStudio.SharePoint.WorkflowExtensions.SharePointListService.ConvertValues(Func`2 producer)
   at Microsoft.VisualStudio.SharePoint.WorkflowExtensions.SharePointListService.GetWorkflowTaskContentTypes()
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Microsoft.SharePoint.DesignTime.Activities.Design.Services.ISharePointListService.GetWorkflowTaskContentTypes()
   at Microsoft.SharePoint.DesignTime.Activities.Design.ContentTypesProvider.ProvideItems(ISharePointListService service)
   at Microsoft.SharePoint.DesignTime.Activities.Design.IndependentDataProvider`1.GetItems(ModelItem owner, PropertyValue propertyValue)
   at Microsoft.SharePoint.DesignTime.Activities.Design.SharePointItemChooserViewModel`1.GetItems(ModelItem Owner, PropertyValue PropertyValue)
   at Microsoft.SharePoint.DesignTime.Activities.Design.ChooserViewModel`1.PopulateItems()
   at Microsoft.SharePoint.DesignTime.Activities.Design.GenericChooser`2.SharePointBaseChooser_Loaded(Object sender, RoutedEventArgs e)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.RouteItem.InvokeHandler(RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.EventRoute.InvokeHandlers(Object source, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
-------------------------


After a long debugging session of Workflow Designer I realized that my colleague accidentally deleted Package folder from SharePoint App project. I pulled the latest version and I didn't notice that folder was missing. When I restored the folder, Workflow Designer didn't throw any exceptions any more.