如何实现SAP WebClient UI附件批量上传
Recently several customers have asked for multiple attachment upload functionality in CRM. As current UI component GS_CM does not support this, I have built a simple prototype to achieve it. Although the UI does not look so good, it could fundamentally support multiple attachment upload at the same time.
How does this prototype looks like
I have created a new button in UI component GS_CM:
Once clicked, there will be a new popup:
Click button “Choose Files”, and you can select multiple files from your local disk using Ctrl key:
once done, it will shows 4 files are selected with each file name:
Click “Upload” button and wait for a while, the successful upload information is displayed:
And the four files just uploaded are now displayed in Attachment assignment block.
How does the prototype work
The major steps to finish this prototype are listed below.
(1) Enhance UI component view GS_CM/DocList Create a new event handler EH_ON_MULTIPLEUPLOAD.
METHOD eh_on_multipleupload.
DATA: lr_popup TYPE REF TO if_bsp_wd_popup.
DATA: lv_product_guid TYPE string.
lv_product_guid = me->typed_context->cmbusobj->collection_wrapper->get_current( )->get_property_as_string( 'INSTID' ).
cl_zupload_main_impl=>product_guid = lv_product_guid.
lr_popup = me->comp_controller->window_manager->create_popup( iv_interface_view_name = 'ZUPLOAD/MainWindow'
iv_usage_name = 'ZUPLOAD'
iv_title = 'Multiple Upload' ).
lr_popup->set_display_mode( if_bsp_wd_popup=>c_display_mode_plain ).
lr_popup->set_window_width( 700 ).
lr_popup->set_window_height( 700 ).
lr_popup->open( ).
ENDMETHOD.
(2) in Event handler implementation, it is necessary to pass the guid of current product to the multiple file upload popup view. The offical way to pass this argument is via contenxt node binding. Since this is a prototype, I just achieve this by storing the product guid to a static attribute ( cl_zupload_main_impl=>product_guid ) of popup view controller.
(3) UI component view ZUPLOAD/MainWindow contains the major logic to support multiple upload, which we will create later.
Create a new button in GS_CM/DocList
Append the following code to method CL_GS_CM_DOCLIST_IMPL~FILL_BUTTONS:
* MULTIPLE UPLOAD ENHANCEMENT - BEGIN
* Separator
CLEAR ls_button.
ls_button-type = cl_thtmlb_util=>gc_separator.
APPEND ls_button TO gt_button.
CLEAR ls_button.
ls_button-id = 'newMultiple'. "#EC NOTEXT
ls_button-type = cl_thtmlb_util=>gc_icon_new.
ls_button-text = 'Multiple upload'.
ls_button-on_click = 'multipleUpload'. "#EC NOTEXT
ls_button-enabled = lv_enabled.
APPEND ls_button TO gt_button.
* MULTIPLE UPLOAD ENHANCEMENT - End
Add component usage to ZUPLOAD.
Since now component ZUPLOAD does not exist, you can do this step later when you have finished the component creation.
(2) Create new UI component ZUPLOAD.
Create a new UI component ZUPLOAD and a new view, paste the source code from document attachment “ZUPLOAD_main.html” to the view.
Brief explanation on the design of ZUPLOAD/main.htm
2.1 a control to support multiple file selection
We enable multiple file selection by using control input with attribute “multiple” equals to true. For more detail about this, please google with keyword “html5 fileupload multiple”. For sure if you need to use this multiple upload functionality, you must use a browser which supports this html5 tag attribute, like Chrome.
line 106: οnchange=”printFiles(this.files)”: once files are selected, this function is called to display the name of chosen files. line 108: οnclick=”my_upload(<%= lv_uuid %>);”: once clicked, this function will submit the file upload request to ABAP server
2.2 populate the url to be sent to ABAP server
currently I hard code the url in Javascript code in line 34. the path “/sap/crm/file_upload” actually represents an ICF node, which we will create in next step. The product uuid passed from Product overview page is appended to the url.
2.3 submit file upload request via HTTP Post
The request is submitted via Javascript built-in object XMLHttpRequest.
(3) Create and implement SICF node
After the HTTP post is sent to ABAP server, the SICF node will actually pick up this request and create attachment accordingly. Create a new ICF node under path /default_host/sap/crm:
Currently I just hard code the BOR type BUS1178 for product in the implementation, feel free to change it to other BOR type if necessary.
Activate SICF node and now this prototype is ready to use.
Useful tools during my development of this prototype
(1) Chrome F12 development tool
I use the tab Network to monitor whether the multipart/form-data request assembled in my Javascript is correct.
(2) Winhex
I need to ensure the binary content of my local file and the content sent via Javascript and received in ABAP server are exactly the same. For non-text files I could not directly view their binary content in Chrome development tools, so I use Winhex.
Limitations of this prototype
(1) currently the HTTP post url for file upload is hard coded in Javascript code. This could be changed that the url containing host name and port number is populated in ABAP instead.
(2) currently after the multiple upload popup is closed, the attachment assignment block is not automatically refreshed. We need to navigate to other UI and back in order to see the latest uploaded files through this prototype.
(3) existing feature like Authorization Scope is not integrated in this prototype. ( this is technically feasible and not difficult ).
(4) the UI look-and-feel is not so consistent with SAP CRM UI.
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- PHP基于swoole多进程操作示例
- PHP格式化显示时间date()函数代码
- php函数式编程简单示例
- php进程(线程)通信基础之System V共享内存简单实例分析
- Laravel5.1 框架数据库查询构建器用法实例详解
- php swoole多进程/多线程用法示例【基于php7nts版】
- PHP JWT初识及其简单示例
- PHP保存Base64图片base64_decode的问题整理
- php实现小程序支付完整版
- Laravel5.1 框架路由基础详解
- Laravel框架实现抢红包功能示例
- Laravel5.1 框架模型创建与使用方法实例分析
- php实现单笔转账到支付宝功能
- PHP发送邮件确认验证注册功能示例【修改别人邮件类】
- PHP实现微信退款功能