cancel
Showing results for 
Search instead for 
Did you mean: 

Call Javascript function on Click of a button in UI in .htm page

kumar5
Active Contributor
0 Kudos


Hi ,

I am trying to implement export to excel functionality as mentioned in the below given wiki.

Download data from web ui to Excel and PPT - CRM - SCN Wiki

but when I click on the button then nothing happens in Web UI. Could you please help me and let me know if I am missing anything.

Thanks & Regards,

Kumar Gaurav

Accepted Solutions (0)

Answers (2)

Answers (2)

devashish_bhattacharya
Active Participant
0 Kudos

Hey Kumar,

I have a requirement to call UI5 app from button of BSP component.

So, could you please direct me the right path?

Thanks,

Devashish

kumar5
Active Contributor
0 Kudos

Below is the code I have written in .htm page:

<%@page language="abap" %>

<%@extension name="htmlb" prefix="htmlb" %>

<%@extension name="thtmlb" prefix="thtmlb" %>

<%@extension name="chtmlb" prefix="chtmlb" %>

<%@extension name="bsp" prefix="bsp" %>

<%

  data: lv_xml      type string.

  DATA : lv_visible_row_count  type i value 10.

  lv_xml    = controller->CONFIGURATION_DESCR->GET_CONFIG_DATA( ).

  data: lv_iterator type ref to CL_CRM_TPMOE_ADSEARE_ITERATOR2.

  create object lv_iterator

  exporting

  ir_context_node = advancedsearchresult

  iv_mass_approve_flag = controller->GV_CUCOTRADE->mass_approve_flag.

  lv_visible_row_count = controller->GET_VISIBLE_ROW_COUNT( ).

  if lv_visible_row_count is initial or lv_visible_row_count = 0.

  lv_visible_row_count = controller->GET_VISIBLE_ROW_COUNT( ).

  endif.

%>

<%--<thtmlb:tray height = "100%"

              id     = "RPC">



  <thtmlb:trayBody>   --%>



<chtmlb:tableExtension tableId = "Table"

                       layout  = "FIXED" >

  <chtmlb:configCellerator id                       = "theCellerator"

                     actions                  = "<%= controller->gt_button %>"

                     actionsMaxInRow          = "10"

                     iterator2                = "<%= lv_iterator %>"

                     table                    = "//ADVANCEDSEARCHRESULT/table"

                     usage                    = "SEARCHRESULT"

                     selectionMode            = "MULTI"

                     onRowSelection           = "select"

                     tableLayout              = "FIXED"

                     selectedRowIndexTable    = "<%= ADVANCEDSEARCHRESULT->SELECTION_TAB %>"

                     scrollRowCount           = "20"

                     hasExpander              = " "

                     horizontalScrolling      = "TRUE"

                     expandedObjectIndexTable = "<%= controller->GT_EXPANDALL %>"

                     visibleRowCount          = "<%= lv_visible_row_count %>"

                     isExpanded               = "FROMREQUEST"

                     downloadToExcel          = "TRUE" />

</chtmlb:tableExtension>



              <%--****RPC Mass change Upload and download buttons --GAP043--%>

<% DATA: v_vkorg TYPE VKORG,

        lv_org  TYPE VKORG.

  CALL METHOD zcl_crm_webui_org_data_helper=>get_active_sales_org

    IMPORTING

      ev_vkorg = v_vkorg.



  SELECT SINGLE SALESORG from zvt_rpcmasschang INTO lv_org WHERE salesorg eq v_vkorg.

   if sy-subrc eq 0.

%>



<%--     CLEAR i_button.--%>

<BR>

<thtmlb:button   id       = "RPCDownload"

                 design   = "EMPHASIZED"

                 text     = "RPC Download"

                 enabled  =  "TRUE"

                 onClientClick = "javascript:dwnToExcel( );" />

<%--<bsp:htmlbEvent name  = "namedown"

                 id    = "iddown"

                 onClick = "serverEvent"

                 p1 = "p1"

                 p2 = "p2"

                 p3 = "p3" />--%>



<script language="javascript">

<%--var button = document.getElementById("RPCDownload");

   button.focus();

   button.click();--%>



function dwnToExcel( )

{

var Excel, Workbook;

var count=1;

Excel = NEW ActiveXObject("Excel.Application");

Workbook = Excel.Workbooks.Add();

Workbook.ActiveSheet.Cells(1,1).Value = "Product ID";

Workbook.ActiveSheet.Cells(1,2).Value = "SoldToParty";

Workbook.ActiveSheet.Cells(1,3).Value = "Condition Value";

Workbook.ActiveSheet.Cells(1,4).Value = "Currency";

Workbook.ActiveSheet.Cells(1,5).Value = "Valid from";

Workbook.ActiveSheet.Cells(1,6).Value = "ValidTo";



Workbook.ActiveSheet.Range("A1:F1").Interior.ColorIndex = 43;

Workbook.ActiveSheet.Range("A1:F6").Borders(7).LineStyle = 2;

Workbook.ActiveSheet.Range("A1:F6").Borders(8).LineStyle = 2;

Workbook.ActiveSheet.Range("A1:F6").Borders(9).LineStyle = 2;

Workbook.ActiveSheet.Range("A1:F6").Borders(10).LineStyle = 2;

Workbook.ActiveSheet.Range("A1:F6").Font.Size = 10;







Workbook.ActiveSheet.Cells(1,1).Value = "<%= '50' %>";

Workbook.ActiveSheet.Cells(2,2).Value = "<%= '60' %>";

Workbook.ActiveSheet.Cells(3,3).Value = "<%= '70' %>";

Workbook.ActiveSheet.Cells(4,4).Value = "<%= '80' %>";

Workbook.ActiveSheet.Cells(5,5).Value = "<%= '90' %>";

Workbook.ActiveSheet.Cells(6,6).Value = "<%= '100' %>";





Excel.Visible = "true";

}

</Script>

   <% endif.

   %>

<%--</thtmlb:trayBody>

</thtmlb:tray>--%>



<%

  CLEAR controller->GT_EXPANDALL.

%>

Former Member
0 Kudos

Change


Excel = NEW ActiveXObject("Excel.Application");

to

Excel = new ActiveXObject("Excel.Application");


Now your js function will be called.


To be sure that your js function is getting called write:


function dwnToExcel( )

{

alert("function called");

<%--your code lines--%>

}

kumar5
Active Contributor
0 Kudos

Thanks Ritu. Thats helpful..But still the Javascript code is not getting executed.

former_member203215
Participant
0 Kudos

HI Kumar,

In SAP CRM onClick event is for trigger the sap crm event.

to trigger the event from java script we have to mention the event name onClientClick = 'eventname'

then only event will be triggered.

make sure that your javascript code does not contain any syntax error. otherwise the event will be not be triggered.

you can check javascript code errors in

http://www.javascriptlint.com/online_lint.php

Former Member
0 Kudos

I have executed your code and it is working fine.

The output was :


Your javacript code will only work in IE browser because all browsers does not support ActiveXObject.


Thanks,

Ritu