Acorel
To Acorel.nl
Acorel background

Open a URL after a button click in the CRM Webclient

Edwin van den Meijdenberg, 15 January 2014

Within the CRM Webclient it’s very easy to enhance views and add, for example, a button. These buttons can be used for all kind of actions and of course you are completely free in implementing your own business logic. Let’s assume you added a button to create a quotation or a different type of output. Most likely the user will not only be interested in creating the document, but he would also like to view it. You might think of a solution where the user clicks the button to create the quotation and afterwards clicks a link to call it’s URL. But why not combining these two actions? Is that possible? The answer is YES and we will show you how to.

Add button to a view

The first thing we need to do is add a button to a view, to be able to create an output document. This action is already explained in one of our previous blogs.
Add buttons to view

The output could be a document created by an Adobe Form. Unfortunately for you we will not describe how to create forms and how to generate output, after clicking the button in the CRM Webclient. Plenty of blogs could be written on that topic. For now we assume that a PDF document is created, after clicking the button, and that it can be viewed by calling the correct URL.

Store link to output document

Once the output is created we need to store it’s location. For that purpose, in the controller class of the view, we create an attribute to save the URL.


This attribute is filled in the event handler of the button.

Open the URL

Now that we added the button, created the output document, stored it’s location (URL), the final step is to directly open the URL. For that purpose we need to enhance the .htm page of the view and add a piece of ABAP/JavaScript.

<script type=”text/javascript” language=”javascript”>
<%
  IF controller->gv_quotation_url IS NOT INITIAL .
%>
window.open (“<%= controller->gv_quotation_url %>”,”<%= sy-uzeit %>”);
<%
  clear controller-> gv_quotation_url.
  ENDIF.
%>
</script>

Once the button is clicked, the action is performed and the page is refreshed, so the views .htm page is called. Here we check if a URL is stored in the controller class. If so, we open a window and view the document. Finally we clear the controller’s attribute again, to avoid calling the URL each time the page is displayed. You might notice the addition “sy-uzeit” within the “window.open” statement. This is to make sure that the window we open is unique. Otherwise calling the same URL will not open a new window again.

Conclusion

It’s quite easy to combine document creation/display into a single action. Besides that the users would really be happy, since it saves them a button click.

Edwin van den Meijdenberg

Read all my blogs

Receive our weekly blog by email?
Subscribe here: