How to go to another location on Run button push - 6.x
Using run parameters to determine a page to go to when the run button is pressed.
Links
How to do SQL database operations on lists of data
Alternative 1
Steps
- Create a user macro goto-url
- No macro body
Output HTML
<script type="text/javascript">location.replace('$paramurl');</script>
- Determine the url you need
- 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
- 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>
- Create the run markup as needed
- 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}