Skip to main content
Solved

EDM File - Attach to email using command_sys


Forum|alt.badge.img+10

I have created the following to attach a EDM file to an email, but I am getting this error in app messages:

 

CURSOR get_inv
Is 
SELECT po_ref_number, invoice_id, company, invoice_no
, ifsapp.purchase_order_cfp.Get_Cf$_Buyer_Name(ifsapp.purchase_order_cfp.Get_Objkey(ifsapp.man_supp_invoice_api.Get_Purchase_Order_Ref_Number(company,invoice_id))) Buyers_name
, ifsapp.purchase_order_api.Get_Buyer_Code(po_ref_number) Buyers_code
, dr.doc_class, dr.doc_no, dr.doc_rev, dr.doc_sheet
FROM ifsapp.POSTING_PROPOSAL_INV_OVERVIEW pp Inner Join ifsapp.doc_reference_object dr On dr.Lu_Name='ManSuppInvoice' and dr.key_ref =  'COMPANY='||company||'^INVOICE_ID='||invoice_id||'^'
where message_id='No Arrival' and po_ref_number='C775261';


BEGIN
  For rec in get_inv loop
    ifsapp.EDM_FILE_API.REFERENCE_EXIST(f_ ,rec.doc_class, rec.doc_no, rec.doc_sheet ,rec.doc_rev ,'VIEW');
    
    IF f_ = 'TRUE' THEN 
            doc_type_ := 'VIEW';
         ELSE
            doc_type_ := 'ORIGINAL';
         END IF;
    file_name_ := ifsapp.EDM_FILE_API.GET_NEW_LOCAL_FILE_NAME(rec.doc_class, rec.doc_no, rec.doc_sheet ,rec.doc_rev, doc_type_, '1');
   
      ifsapp.command_sys.mail(sender_   => 'IFSAPP'
                      ,from_     => 'IFSAPP'
                      ,to_list_  => email_addr_
                      ,cc_list_  => ''
                      ,bcc_list_ => ''
                      ,subject_  => 'No Arrivals for PO: ' || rec.po_ref_Number || ', Invoice: ' || rec.invoice_no
                      ,text_     => 'The following invoice/s have been received and the receipts have not yet been received.  Please receipt in so the invoices can be matched.' || chr(13) ||
                                      'Regards Accounts Payable'
                      ,attach_   => file_name_);

Best answer by dsj

Hi @JannetteC 

 

According to your code, file_name_ should be the path for the file. SInce you are in Apps10, you can use Batch_Transfer_Handler_Api to copy the file to a folder in application server and use the path.

Read this post on how to fetch documents to a server folder and attach in the email 

https://dsj23.me/2017/03/20/include-additional-attachments-in-ifs-e-mail-report/

 

But a more future proof solution would be to get the files from edm file storage and attached to the email itself.

See below topic on a nice example on this approach.

Need assistance for sending emails with attachments triggered by an event. (23R1) | IFS Community

Following blog aims for IFS Cloud but it should work for IFS10 as well

https://dsj23.me/2023/04/10/how-to-include-additional-attachments-in-e-mail-reports-in-ifs-cloud/

 

Hope it helps!

Damith

View original
Did this topic help you find an answer to your question?

7 replies

dsj
Ultimate Hero (Partner)
Forum|alt.badge.img+22
  • Ultimate Hero (Partner)
  • 880 replies
  • Answer
  • January 12, 2024

Hi @JannetteC 

 

According to your code, file_name_ should be the path for the file. SInce you are in Apps10, you can use Batch_Transfer_Handler_Api to copy the file to a folder in application server and use the path.

Read this post on how to fetch documents to a server folder and attach in the email 

https://dsj23.me/2017/03/20/include-additional-attachments-in-ifs-e-mail-report/

 

But a more future proof solution would be to get the files from edm file storage and attached to the email itself.

See below topic on a nice example on this approach.

Need assistance for sending emails with attachments triggered by an event. (23R1) | IFS Community

Following blog aims for IFS Cloud but it should work for IFS10 as well

https://dsj23.me/2023/04/10/how-to-include-additional-attachments-in-e-mail-reports-in-ifs-cloud/

 

Hope it helps!

Damith


Forum|alt.badge.img+10
  • Author
  • Hero (Customer)
  • 62 replies
  • February 7, 2024

Hi @dsj ,

Thanks for you comment, however I am unable to access this link as it is for selected users.

 

Need assistance for sending emails with attachments triggered by an event. (23R1) | IFS Community

 

I have written the code and it appears to mostly work, however if a PO does not have a document to be attached it adds what was on the previous email.  

Is there a way to clear the attachments array after the email have been produced and sent ?

 

Thanks in advance


dsj
Ultimate Hero (Partner)
Forum|alt.badge.img+22
  • Ultimate Hero (Partner)
  • 880 replies
  • February 7, 2024
JannetteC wrote:

Hi @dsj ,

Thanks for you comment, however I am unable to access this link as it is for selected users.

 

Need assistance for sending emails with attachments triggered by an event. (23R1) | IFS Community

 

I have written the code and it appears to mostly work, however if a PO does not have a document to be attached it adds what was on the previous email.  

Is there a way to clear the attachments array after the email have been produced and sent ?

 

Thanks in advance

 

Hi @JannetteC 

If you are sending mails for different POs inside a loop, you need to clear the attachment array first. Can you share your code, so it could be easy to find what’s wrong :)


Forum|alt.badge.img+10
  • Author
  • Hero (Customer)
  • 62 replies
  • February 7, 2024

Hi @dsj 

 

 


Forum|alt.badge.img+10
  • Author
  • Hero (Customer)
  • 62 replies
  • February 7, 2024

DECLARE

info_ varchar2(200) :=null ;
email_addr_ VARCHAR2(2000) :=null ;
file_name_ varchar2(32000)  :=null ;
email_body_ VARCHAR2(2000)  :=null ;
error_message_ VARCHAR2(32000)  :=null ;
attachments_  ifsapp.COMMAND_SYS.ATTACHMENT_ARR;


CURSOR get_inv
Is


SELECT po_ref_number, invoice_id, company, invoice_no
, ifsapp.purchase_order_cfp.Get_Cf$_Buyer_Name(ifsapp.purchase_order_cfp.Get_Objkey(ifsapp.man_supp_invoice_api.Get_Purchase_Order_Ref_Number(company,invoice_id))) Buyers_name
, ifsapp.purchase_order_api.Get_Buyer_Code(po_ref_number) Buyers_code
, dr.doc_class, dr.doc_no, dr.doc_rev, dr.doc_sheet, edm.file_data, edm.doc_type
FROM ifsapp.POSTING_PROPOSAL_INV_OVERVIEW pp Left Outer Join ifsapp.doc_reference_object dr On dr.Lu_Name='ManSuppInvoice' and dr.key_ref =  'COMPANY='||company||'^INVOICE_ID='||invoice_id||'^'
    left outer join ifsapp.edm_file_storage edm On edm.DOC_CLASS= dr.doc_class and edm.DOC_NO = dr.doc_no and edm.dOC_SHEET=dr.doc_sheet and edm.DOC_REV=dr.doc_rev
where message_id='No Arrival' --and po_ref_number not like 'E%' 
--and po_ref_numBer In ('C776839','C778141','C775591','C774557','C771026');
and po_ref_numBer In ('C776839','C775591','C774557');

BEGIN
  For rec in get_inv loop

  email_addr_ := ifsapp.fnd_user_property_api.get_value(rec.Buyers_code ,'SMTP_MAIL_ADDRESS' ) ;

      
     file_name_ := ifsapp.Edm_File_Util_API.Generate_Docman_File_Name_( rec.doc_class, rec.doc_no, rec.doc_sheet, rec.doc_rev, rec.doc_type);
     ifsapp.COMMAND_SYS.Add_Attachment(attachments_, file_name_, file_data_);


         ifsapp.COMMAND_SYS.Mail(sender_      => 'IFSAPP',
                   from_        => 'IFSAPP',
                   to_list_     => 'xxxxxxxx' ,
                   cc_list_  => info_ ,
                   bcc_list_ => info_ ,
                   subject_     => 'No Arrivals for PO: ' || rec.po_ref_Number || ', Invoice: ' || rec.invoice_no ,
                   text_        => 'The following invoice/s have been received and the receipts have not yet been received.  Please receipt in so the invoices can be matched as the invoice will not be paid until received.  <br /> 
                                   Regards <br /> Accounts Payable' ,
                   attachments_ => attachments_);
                   
  If Nvl(email_addr_ ,'NO EMAIL') != 'NO EMAIL' Then
   Begin
     ifsapp.Transaction_SYS.Log_Status_Info('PO Ref: ' || rec.po_ref_Number || ', Invoice: ' || rec.invoice_no || ' email sent to ' || email_addr_ , 'INFO');
     exception when others then
     error_message_ := 'PO Ref: ' || rec.po_ref_Number || ', Invoice: ' || rec.invoice_no || ' - '||substr(SQLERRM, 1, 1990);
     ifsapp.Transaction_SYS.Log_Status_Info(error_message_ , 'WARNING');
   End ;
   
   End If ; 
   
  End Loop;
  
  End;


dsj
Ultimate Hero (Partner)
Forum|alt.badge.img+22
  • Ultimate Hero (Partner)
  • 880 replies
  • February 7, 2024

Seems you are not resetting the attachment array inside the loop.

Hope it will be a 1 line fix ðŸ˜Ž

Add attachments_.DELETE; after sending the mail to reset the attachment array and see if it works!

 

Cheers!

Damith

 

 


Forum|alt.badge.img+10
  • Author
  • Hero (Customer)
  • 62 replies
  • February 7, 2024

Hi @dsj 

Perfect, fixed my issue

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings