+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / exception when sending a blogpost for approval via API

exception when sending a blogpost for approval via API

4 posts, 0 answered
  1. suneeth
    suneeth avatar
    0 posts
    Registered:
    11 Mar 2016
    31 Oct
    Link to this post

    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.

     

     

  2. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    01 Nov
    Link to this post

    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

  3. suneeth
    suneeth avatar
    0 posts
    Registered:
    11 Mar 2016
    01 Nov in reply to Victor Leontyev
    Link to this post

    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

     

  4. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    03 Nov in reply to suneeth
    Link to this post

    Hi suneeth,

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

4 posts, 0 answered