How to go to another location on Run button push

Using run parameters to determine a page to go to when the run button is pressed.

Links

Alternative 1

Steps

  1. Create a user macro goto-url
    • No macro body
    • Output HTML

      <script type="text/javascript">location.replace('$paramurl');</script> 
      
  2. Determine the url you need
  3. Create the run markup as needed

Example

{run:replace=name:My new page|titleRun=New page}

{goto-url:url=$base_url/pages/createpage-name.action?name=$name&spaceKey=$space_key&fromPageId=$page_id}

{run}

Getting Confluence urls to use

Any macro that produces a link on a page can be used to create a url to use in this scenario. For example the add-page macro can create some complex urls for creating pages with various parameters. Use this macro on some test page to get the url you want. Copy and paste into your run macro markup substituting run parameter values - user defined or Pre-defined variables.

Alternative 2

This uses a more complex user macro to extract the link from the body and then redirect to the referenced link.

Steps

  1. Create a user extract-link user macro or use the extract-link macro from Run Self-Service Reports for Confluence.
    • Has macro body - use Convert wiki markup to HTML so it will render embedded macros and markup
    • Output HTML

      ## Macro to search the body text for the first element that looks like a link.
      ## Finds any quoted (single or double) http:// or https:// link or href= value
      ## Returns the unquoted value as raw text or locates to the link if redirect=true
      ## @param redirect:title=Redirect|type=boolean|desc=Redirect to link|default=false
      
      #set ($body = $body.trim())
      
      <script type="text/javascript">
      var regex = /['"](http[s]{0,1}:\/\/[^'"]*)['"]/;   // http type link
      var match = regex.exec('$body');
      var redirect = ('$paramredirect' == 'true')
      
      if (!match) {  // no http type link found
         regex = /href=['"]([^'"]*)['"]/;      // href link
         match = regex.exec('$body');
      } 
      if (match) {
          if (redirect) {
              try {
                  location.replace(match[1]);
              } catch (e) {
                  document.write('Error: ' + e.message + '. ' +  match[1]);
              }
          } else {
              document.write(match[1]);
          }
      } 
      </script> 
      
  2. Create the run markup as needed
  3. Create the body of the run macro so that it produces the link desired.

Examples

{run:titleRun=Show going to a page on button press|replace=page:home}
{extract-link:redirect=true} Some text [$page] some more text {extract-link}
{run}
{run:titleRun=Create a page|replace=name:example}
{extract-link:redirect=true} 
{add-page:name=$name|template=template1|parent=@self}This is ignored{add-page}
{extract-link}
{run}

Log a request with our support team.

Confluence®, Jira®, Atlassian Bamboo®, Bitbucket®, Fisheye®, and Atlassian Crucible® are registered trademarks of Atlassian®
Copyright © 2005 - 2024 Appfire | All rights reserved. Appfire™, the 'Apps for makers™' slogan and Bob Swift Atlassian Apps™ are all trademarks of Appfire Technologies, LLC.