Loading...

RE: How to create a correct GotoURL in Custom Actions

RE: How to create a correct GotoURL in Custom Actions

#5649
Anonymous
Anonymous
Participant

I think there is still possibility to do it without actually coding a server side soluton (build custom action and deploy it to the SharePoint). If you are fluent in JavaScript, this can be acheived using client side JavaScript. Below is the psudo code:

  1. drop a Script Editor (under Media and Content web part category) or HTML Form Web Part (under Form category) so you may inject custom JavaScript
  2. modify the HTML Form Web Part source to include some JavaScript function, which allows you to locate the button (New) and attach onclick event so it can take over the execution from your custom JavaScript function to do whatever you would like, like go to the URL you really want
  3. use JavaScript function to obtain the Source, ID and other parameters from query string and construct the proper URL string
  4. load that URL from JavaScript to have the same effect of having a custom action GoToUrl with the exact URL

For #2, I have some code snippet to get you started (it is using jquery and also due to an issue with our code, even if you specified an ID for the toolbar item in Custom Action, this ID is not part of the generated HTML code so you would not be able to select the button by the ID unfortunately).

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

<script type="text/javascript">

  function loadButton() {

    // as a workaround as currently even if you specify ID for the custom action item

    // the ID is not attached to the UI element, so you will have to come up with your

    // own jquery selector to locate the custom action button/menu

    $('a.rmRootLink').click(function(evt) {

      evt.preventDefault();

      alert("Run my function…");

    });

  };

  loadButton();

</script>

In function loadButton() is where you need to obtain from Source URL and concatenate your new URL and load that URL. If you Google it, you should find code snippet to get that done.