Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kevin T Reynolds 3 posts 94 karma points
    Nov 13, 2018 @ 23:42
    Kevin T Reynolds
    1

    Get current page url within custom Umbraco forms workflow.

    Hey guys, long time listener first time caller.

    I have a form that appears on several pages of a site and depending on which page it is submitted on I want to route to a specific thank you page that is a child of that page.

    After searching around for a bit it seemed like the best option was to create a custom workflow and handle the logic there but I'm struggling to come up with a solution. I'm very junior and even more so to c# so I imagine there is something simple I'm missing.

    Initially I was trying to get the current URL from HttpContext.Current.Request.Url.AbsoluteUri; in something like this `

    public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {
          string currentUrl = HttpContext.Current.Request.Url.AbsoluteUri;
          HttpContext.Current.Response.Redirect(currentUrl + "/thank-you");
    
          return WorkflowExecutionStatus.Completed;
        }
    

    `

    but that was returning '%%domain%%/umbraco/RenderMvc/thank-you'

    So then I added a field to the workflow to pass a magic string [@Url] which still just gave me '/umbraco/RenderMvc'.

    then I changed the magic string to [#pageID] which has given me the correct node ID but I'm having trouble coming up with a way to get the url from the nodeID outside of the comfort of razor. I'm hoping there is a namespace I can use that'll give me the right methods, but my brain is kind of fried as is and was hoping somebody could come in and help me out.

  • Kevin T Reynolds 3 posts 94 karma points
    Nov 14, 2018 @ 08:48
    Kevin T Reynolds
    100

    If anyone comes across this it ended up being easier than I made it out to be. After going down a few rabbit holes I ended up with this.

    public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {
          var currNode = UmbracoContext.Current.ContentCache.GetById(Int32.Parse(s: PageId));
    
          if (currNode != null && currNode.FirstChild().DocumentTypeAlias == "orangePaperThankYou")
          {
            var targetUrl = currNode.FirstChild().Url;
            HttpContext.Current.Response.Redirect(targetUrl);
          }
    
          return WorkflowExecutionStatus.Completed;
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft