Cerca nel blog

giovedì 6 giugno 2024

Mostrare nella My Inbox di Fiori gli allegati delle RdA (ME53N)

Mostrare nella My Inbox di Fiori gli allegati delle RdA (ME53N)



L'APP standard My Inbox di Fiori, normalmente permette di visualizzare e fare il download solo degli allegati inseriti in Business Workplace.




Implementeremo del codice per fare in modo che l'APP, consenta la visualizzazione/download degli allegati inseriti nelle Tcode ME51N, ME52N



Richiamare la tcode SE18, e ricercare la badi WF_OBJECT_ATTACHMENT

Fare doppio click su implementazioni, e nella schermata di dx fare doppio click su  MM_PUR_PR_WFL_ATTACHMENT


Fare doppio click sulla classe a sx, e nella schermata di dx fare doppio click prima su IF_ATTACHMENT_PROVIDER_BADI~GET_ATTACHMENT_LIST  (per fare in modo di visualizzare gli allegati nella My Inbox) e poi su IF_ATTACHMENT_PROVIDER_BADI~GET_ATTACHMENT_CONTENT (per gestire il download degli allegati)



Creare l'enhancement ZWF_OBJECT_ATTACHMENT_RDA nei 2 metodi:

Metodo: IF_ATTACHMENT_PROVIDER_BADI~GET_ATTACHMENT_LIST

ENHANCEMENT 1  ZWF_OBJECT_ATTACHMENT_RDA.    "active version
DATAlv_gos_objkey_rda  TYPE objky.
IF lt_purchaserequisitionitem[] IS NOT INITIAL AND lv_gos_objkey IS INITIAL.
  lv_gos_objkey_rda is_business_object-instid+0(10).

  TRY.
      IF lv_gos_objkey_rda IS NOT INITIAL.
        cl_odata_cv_attachment_api=>get_instance)->if_odata_cv_attachment_api~retrieve_attachments_id(
            EXPORTING
              iv_objecttype          'BO'
              iv_objecttype_long     'BUS2105'
              iv_objectkey           lv_gos_objkey_rda
              iv_run_no_auth_check   abap_false
            IMPORTING
              et_attachments         lt_attachments
              et_messages            lt_message ).
        LOOP AT lt_attachments INTO ls_attachment.
          ls_attach-filesize        ls_attachment-filesize.
          ls_attach-mime_type       ls_attachment-mimetype.
          ls_attach-created_by_user ls_attachment-createdby.
          ls_attach-created_at      ls_attachment-createdat.
          ls_attach-id              ls_attachment-file_id.
          CONCATENATE lv_gos_objkey_rda ls_attachment-filename
              INTO ls_attach-filename   SEPARATED BY space.
          ls_attach-delete_enabled  ls_attachment-deletion_indicator.
          ls_attach-changed_at      ls_attachment-createdat.
          ls_attach-changed_by_user ls_attachment-createdby.
          INSERT ls_attach INTO TABLE ct_attachment.
        ENDLOOP.
      ENDIF.
    CATCH cx_odata_cv_base_exception INTO lx_odata_cv_base.
      IF lt_message IS NOT INITIAL.
        RAISE EXCEPTION TYPE cx_swf_run_attachment_badi
          EXPORTING
            previous lx_odata_cv_base.
      ENDIF.
  ENDTRY.
ENDIF.

ENDENHANCEMENT.

ENDMETHOD.

Metodo: IF_ATTACHMENT_PROVIDER_BADI~GET_ATTACHMENT_LIST

ENHANCEMENT 2  ZWF_OBJECT_ATTACHMENT_RDA.    "active version
DATAlv_gos_objkey_rda  TYPE objky.
IF lv_gos_objkey_rda IS INITIAL.
  lv_gos_objkey_rda is_business_object-instid+0(10).

  TRY.
*       GOS Attachments
      IF lv_gos_objkey_rda IS NOT INITIAL.
        cl_odata_cv_attachment_api=>get_instance)->if_odata_cv_attachment_api~retrieve_attachments_id(
          EXPORTING
            iv_objecttype_long     'BUS2105'
            iv_objectkey           lv_gos_objkey_rda
            iv_run_no_auth_check   abap_true
          IMPORTING
            et_attachments lt_attachments_gos
            et_messages    lt_message
          ).
        APPEND LINES OF lt_attachments_gos TO lt_attachments.
      ENDIF.
    CATCH cx_odata_cv_base_exception INTO lx_odata_cv_base.
      RAISE EXCEPTION TYPE cx_swf_run_attachment_badi
        EXPORTING
          previous lx_odata_cv_base.
  ENDTRY.
  READ TABLE lt_attachments INTO ls_attachment WITH KEY file_id lv_attachment_id.
  IF sy-subrc EQ 0.
    IF ls_attachment-mimetype EQ 'text/url'" this is an URL attachment
      lv_url ls_attachment-url.
      CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
        EXPORTING
          text   lv_url
        IMPORTING
          buffer lv_xurl.

* --- Attaching content of URL file ---
      INSERT VALUE #(
                      id        ls_attachment-file_id
                      data      lv_xurl
                      mime_type 'text/uri-list'
                      filename  ls_attachment-filename
                      filesize  0
                     INTO TABLE ct_attachment_content.
    ELSE"Other attachment (non-URL)
      TRY.
          APPEND lv_attachment_id TO lt_attachment_id.
          cl_odata_cv_attachment_api=>get_instance)->if_odata_cv_attachment_api~retrieve_attachments_content(
            EXPORTING
              iv_objecttype_long     COND #WHEN ls_attachment-documenttype EQ 'GOS' THEN 'BUS2105' ELSE 'EBAN' )
              iv_objectkey           COND #WHEN ls_attachment-documenttype EQ 'GOS' THEN lv_gos_objkey_rda ELSE lv_dms_objkey )
              it_file_ids            lt_attachment_id
              iv_run_no_auth_check   abap_false
            IMPORTING
              et_attachment_contents lt_att_content
              et_messages            lt_message
          ).
* Fill the attachment structure
          LOOP AT lt_att_content INTO ls_att_content WHERE file_id lv_attachment_id.
            INSERT VALUE #(
                            id        ls_att_content-file_id
                            data      ls_att_content-attachment_content
                            mime_type ls_att_content-mimetype
                            filename  ls_att_content-filename
                            filesize  ls_att_content-filesize
                          INTO TABLE ct_attachment_content.
          ENDLOOP.
        CATCH cx_odata_cv_base_exception INTO lx_odata_cv_base.
          RAISE EXCEPTION TYPE cx_swf_run_attachment_badi
            EXPORTING
              previous lx_odata_cv_base.
      ENDTRY.
    ENDIF.
  ENDIF.
ENDIF.
ENDENHANCEMENT.

ENDMETHOD.






SE MI CONTATTATE IN PRIVATO, PAGATE LA META' DEL PREZZO DI AMAZON, E POTETE SCEGLIERE IL FORMATO WORD o PDF. 



Nessun commento:

Posta un commento