Loading...

How to create a correct GotoURL in Custom Actions

How to create a correct GotoURL in Custom Actions

  • This topic is empty.
Viewing 5 reply threads
  • Author
    Posts
    • #5646
      Anonymous
      Anonymous
      Participant

      Hello,

      The address on that page is:

      https://worksites.connect.inbaxter.com/sites/CIM/Lists/Data%20Tables/DispForm.aspx?ID=165&Source=https%3A%2F%2Fworksites%2Econnect%2Einbaxter%2Ecom%2Fsites%2FCIM%2FLists%2FData%2520Tables%2FCMDMV%2520Tables%2Easpx&ContentTypeId=0x0100F4916BBB010FD84A962E1B57C42CFCCA

      If I could get that in the 2nd Source parameter, that would be amazing.  The %3F and the %26 I keyed in myself in order to 'fool' the GotoURL process to put in the ? and & for me.  You can see that in the CustomAction Parameter Names.

    • #5647
      Anonymous
      Anonymous
      Participant

      I see. Have you thought about using Session to pass ID values around instead of using it as part of the Source URL string? If you always know the URL of the Source you want to go back to, I would consider using Session. The way the above Source URL being nested is going to confuse people and hard to maintain the application flow in my opinion.

    • #5648
      Anonymous
      Anonymous
      Participant

      That is what I normally use and it works great.  Except in this case, my Tables list has more then 8 lookup columns which is why I am forced to use a custom action per your support dept's previous workaround instructions re:Quest bug.

    • #4484
      Anonymous
      Anonymous
      Participant

      Using Quest forms (list form and list view) I have a 3 level edit process where I start from the Main Page to get a list of Tables, from the list of tables, I can select a table (Parent) to view and from the table’s view (see image) I can add a new column (Child) .

      qwps.JPG

      Because my parent list (on the list form) has more than 8 lookup columns, I can’t use the session to send its ID to the child’s NewForm.  Quest (Dell) has acknowledged that this is a bug and they are working on it. In the meantime, the workaround is to create my own New button and URL to call the NewForm.  No problem so far, that is easily done.

      It gets complicated when trying to code the &Source parameter.  I want to ensure that when the user clicks Save or Cancel, SharePoint knows what page to display (i.e. first the parent view form above and then if they click cancel on that form, the list of tables). The correct syntax would be the following:

      https://worksites.connect.inbaxter.com/sites/CIM/Lists/Data%20Columns/NewForm.aspx?ParentID=165&Source=../Data%20Tables/DispForm.aspx%3FID=165%26Source=../Data%20Tables/CMDMV%20Tables.aspx

      In red is the correct URL for the NewForm… Notice the ParentID parameter. In blue is the correct Source string for the Parent and in orange is the Parent’s Source string.

      Here’s the Custom Action code for the List View New button:

      <CustomActions>

      <Toolbar>

        <ActionItem ID=”NewButton” Text=”New” ImageUrl=”https://worksites.connect.inbaxter.com/sites/CIM/_layouts/QuestSoftware/WAResources/Invariant/Images/NewItem.gif” AccessKey=”N” Position=”0″>

         <Action Type=”GoToURL” URL=”../Data%20Columns/NewForm.aspx” OpenURL=”CurrentWindow”>

          <Parameter Name=”ParentID” Source=”HttpRequest” SourceName=”ID” />

          <Parameter Name=”Source” Source=”HttpRequest” SourceName=”URL” />

          <Parameter Name=”%3FID” Source=”HttpRequest” SourceName=”ID” />

          <Parameter Name=”%26Source” Source=”HttpRequest” SourceName=”Source” />

         </Action>

        </ActionItem>

        <ActionItem ID=”Separator” Text=”-” Position=”1″ />

      </Toolbar>

      </CustomActions>

      This creates this URL:

      https://worksites.connect.inbaxter.com/sites/CIM/Lists/Data%20Columns/NewForm.aspx?ParentID=165&Source=/sites/CIM/Lists/Data Tables/DispForm.aspx&%3FID=165&%26Source=https://worksites.connect.inbaxter.com/sites/CIM/Lists/Data%20Tables/CMDMV%20Tables.aspx

      This is very close, but not close enough… my added %3f and %26 would work if it weren’t for the ‘&’ that quest adds for each parameter… If I take the ‘&’ out and try it manually, the behavior is correct.

      I’m looking for help to find a way to either take the ‘&’ away or to generate the URL differently.  I think I could use the ResultFromAction…i.e. the first Action would create the URL as above and the second action would replace ‘&%’ to ‘%’ with a simple regex. But I have no idea how to code an action. I am open or other solutions as well.

      Any help would be greatly appreciated. Thanks in advance.

    • #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.

    • #5464
      Anonymous
      Anonymous
      Participant

      Hi Richard

      What is the URL looks like on the page where you have the table view (from screen shot) from which you can add a new column (child)? From the way you extracting out the parameter, it looks like the original URL may contain the Source URL parameter you wanted already. %3F is URL encoded string for "?" and %26 is URL encoded for "&". I understand the outcome URL you would like when user clicks the New button but would like to see the original incoming URL that this custom action is trying to work with.

Viewing 5 reply threads

You must be logged in to reply to this topic.