exception when sending a blogpost for approval via API

Posted by Community Admin on 04-Aug-2018 16:03

exception when sending a blogpost for approval via API

All Replies

Posted by Community Admin on 31-Oct-2016 00:00

Hi, I am trying to to create a blogpost item through the API  and send it for approval.   I am getting an exception when I call the WorkflowManager.MessageWorkflow.

Below is my Code

            var blogsManager = BlogsManager.GetManager();
            blogsManager.Provider.SuppressSecurityChecks = true;           

            Guid id = Guid.NewGuid();
            var newBlogPost = blogsManager.CreateBlogPost(id);

            var parentBlog = blogsManager.GetBlogs().Where(b => b.UrlName.StartsWith("cooking")).SingleOrDefault();
            newBlogPost.Parent = parentBlog;

            newBlogPost.Title = model.Title;
            newBlogPost.Summary = model.Summary;
            newBlogPost.Content = model.Content;
            newBlogPost.DateCreated = DateTime.UtcNow;
            newBlogPost.PublicationDate = DateTime.UtcNow;
            newBlogPost.LastModified = DateTime.UtcNow;
            newBlogPost.UrlName = Regex.Replace(model.Title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
            blogsManager.RecompileAndValidateUrls(newBlogPost);
        

            blogsManager.SaveChanges();

            var bag = new Dictionary<string, string>();
            bag.Add("ContentType", typeof(BlogPost).FullName);
            WorkflowManager.MessageWorkflow(id, typeof(BlogPost), null, "SendForApproval", false, bag);

 

===================================================================

Below is the exception I am getting.

 

Message: HandlingInstanceID: d9a12803-e417-42fd-bff4-9f9f479f0963
An exception of type 'System.NullReferenceException' occurred and was caught.
-----------------------------------------------------------------------------
10/31/2016 15:53:12
Type : System.NullReferenceException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Object reference not set to an instance of an object.
Source : Telerik.Sitefinity
Help link : 
Data : System.Collections.ListDictionaryInternal
TargetSite : System.String MessageWorkflow(System.Guid, System.Type, System.String, System.String, Boolean, System.Collections.Generic.Dictionary`2[System.String,System.String])
HResult : -2147467261
Stack Trace :    at Telerik.Sitefinity.Workflow.WorkflowManager.MessageWorkflow(Guid itemId, Type itemType, String providerName, String operationName, Boolean isCheckedOut, Dictionary`2 contextBag)
   at SitefinityWebApp.Mvc.Controllers.BlogRequestController.Index(BlogRequestModel model) in c:\inetpub\wwwroot\MyBlog\Mvc\Controllers\BlogRequestController.cs:line 76
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<InvokeActionMethodWithFilters>b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at Telerik.Sitefinity.Mvc.ControllerWrapper.Execute()
   at Telerik.Sitefinity.Mvc.ControllerActionInvoker.ExecuteController(MvcProxyBase proxyControl)
   at Telerik.Sitefinity.Frontend.Mvc.Infrastructure.Routing.DynamicUrlParamActionInvoker.ExecuteController(MvcProxyBase proxyControl)

Please take a look.

 

 

Posted by Community Admin on 01-Nov-2016 00:00

Hi suneeth,

You need to check out temp version of blog post.

You can find the snippet of code provided by Atanas Valchev on this thread, it can be helpful for you:

http://www.sitefinity.com/developer-network/forums/bugs-issues-/workflow-exception

 

Please, let me know if you will meet problems with that solution

Posted by Community Admin on 01-Nov-2016 00:00

Hi  Victor, thanks for your reply.

I have now made like the below, But I still get the same workflowsecurityexception

step 1 ) Create the master
step 2)  checkout the master to create the temp
step 3 ) Save BlogsManager
step 4)  Send temp for workflow Approval

 

Posted by Community Admin on 03-Nov-2016 00:00

Hi suneeth,

In this case, I don't know why it's throwing an exception. Maybe guys from Telerik can tell us.

This thread is closed