Skip to main content
Dynamics 365 Community / Forums / Finance forum / To Pass the attachemnt...
Finance forum
Answered

To Pass the attachemnt from one form to another

editSubscribe (0) ShareShare
ReportReport
Posted on by 1,279
I have created button on customise from which on click pass add the files in attachment , but at the same time i want to add the same attachment to custinvoicejour record both record have invoice id and invoice date same , please suggest me how can i get this done, can any one help me on this . 
below is my code .
thanks ,
Regards,
Dinesh
 
 
 
  • Verified answer
    Dineshkarlekar Profile Picture
    Dineshkarlekar 1,279 on at
    To Pass the attachemnt from one form to another
    hi , everyone 
     
    Thanks for reply ,
     
    i was not getting the value attached in custinvoiced jour .
    now i am getting the attachement copy .
     
    Thanks,
    Regards,
    Dinesh
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 1,945 on at
    To Pass the attachemnt from one form to another
    Hi Dinesh,
     
    Did you try your code? What is the result? I can see on your code:
     
     CustInvoiceJour       custInvoiceJour; ---- Empty buffer and it wasn't used.
     
    Thanks
    Waed Ayyad,
    If this helped, please mark it as "Verified" for others facing the same issue
     
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,279 on at
    To Pass the attachemnt from one form to another
    hi ,
    Everyone 
    I have written the code on the extension of custinvoice jour. please let me what changes i need to de in code .   
     
     class DTDMCLinesAttachment
    {
        public static void main(Args _args)
        {
            FileUploadTemporaryStorageResult  result;
            DTDMCHeaderLines      dTDMCHeaderLines;
            CustInvoiceJour       custInvoiceJour;
            //DocuRef               docuRef2;
            DocuType              docuType;
            dTDMCHeaderLines = _args.record();
            docuType = DocuType::find('Image');
            CustInvoiceId       invoiceId;
    
            invoiceId = dTDMCHeaderLines.InvoiceId;
    
            select * from custInvoiceJour
                        where custInvoiceJour.InvoiceId == invoiceId;
     
            result = File::GetFileFromUser(classStr(FileUploadTemporaryStorageStrategy));
            if(result != null)  /* result.getUploadStatus()*/
            {
                str fileName = result.getFileName(); //Insert the name of the attachchment
    
                using(System.IO.MemoryStream stream = result.openResult() as System.IO.MemoryStream)
                {
                    DocuRef docuRef = DocumentManagement::attachFile(
                                 dTDMCHeaderLines.TableId,
                                 dTDMCHeaderLines.RecId,
                                 dTDMCHeaderLines.DataAreaId,
                                docuType.TypeId,
                                stream,
                                fileName,
                                System.Web.MimeMapping::GetMimeMapping(filename),
                                fileName);  
                }
    
                custInvoiceJour.doUpdate();
            }
     
        }
    
    }
     
    ExtensionOf(tableStr(CustInvoiceJour))]
    final class DTCustInvoiceJourTbl_DmcAttachment_Extension
    {
        public void doUpdate()
        {
            next doUpdate();
            
            DTDMCHeaderLines dTDMCHeaderLines = DTDMCHeaderLines::find(this.InvoiceId);
            CustInvoiceJour  custInvoiceJour;
    
            DocuRef docuRef = DocuRef::findTableIdRecId(dTDMCHeaderLines.DataAreaId, dTDMCHeaderLines.TableId, dTDMCHeaderLines.RecId);
            ttsbegin;
            custInvoiceJour.selectForUpdate(true);
            custInvoiceJour.reread();
    
            if (docuRef)
            {
                docuRef.RefTableId = this.TableId;
                docuRef.RefRecId = this.RecId;
                docuRef.insert();
            }
            custInvoiceJour.doUpdate();
            ttscommit;
        }
    
    }
    
     
    thanks,
    Regards,
    Dinesh.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,279 on at
    To Pass the attachemnt from one form to another
    hi ,
    everyone ,
    thanks for reply ,
     
    i have debug the issue , i am getting the the error , the file type does  not exists , i need to configure share point settings so i can proceed further .
    can you please tell me do i have to add new relation between my custom table and cust invoice jour , so if yes which fields should i use for  relation  to get required results , do i have to make any changes in index , please suggest me on this .
     
    thanks,
    regards,
    Dinesh
     
  • Andre Arnaud de Calavon Profile Picture
    Andre Arnaud de Cal... 283,066 Super User on at
    To Pass the attachemnt from one form to another
    Hi Dinesh,
     
    Can you describe the current behavior of your coding? Do you get an error? Is the attachment for one or both of the tables missing? Have you already used the debugger to find any possible issues?
  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,534 Super User on at
    To Pass the attachemnt from one form to another
  • Layan Jwei Profile Picture
    Layan Jwei 2,789 Super User on at
    To Pass the attachemnt from one form to another
    Hi Dinesh,
     
    So if you have code that inserts attachments to let's say table1 and it's working correctly. Can't you write similar code to also insert to custInvoiceJour?
     
    Thanks,
    Layan Jweihan
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,279 on at
    To Pass the attachemnt from one form to another
     class DTDMCLinesAttachment
    {
        public static void main(Args _args)
        {
            FileUploadTemporaryStorageResult  result;
            DTDMCHeaderLines      dTDMCHeaderLines;
            CustInvoiceJour       custInvoiceJour;
            DocuRef               docuRef2;
            dTDMCHeaderLines = _args.record();
     
            result = File::GetFileFromUser(classStr(FileUploadTemporaryStorageStrategy));
            if(result != null)  /* result.getUploadStatus()*/
            {
                str fileName = result.getFileName(); //Insert the name of the attachchment
    
                using(System.IO.MemoryStream stream = result.openResult() as System.IO.MemoryStream)
                {
                    DocuRef docuRef = DocumentManagement::attachFile(
                                 dTDMCHeaderLines.TableId,
                                 dTDMCHeaderLines.RecId,
                                 dTDMCHeaderLines.DataAreaId,
                                "DailyCollectionattachment",
                                stream,
                                fileName,
                                System.Web.MimeMapping::GetMimeMapping(filename),
                                fileName);
                    select * from custInvoiceJour
                        where custInvoiceJour.InvoiceId == dTDMCHeaderLines.InvoiceId;
    
                    buf2Buf(docuRef,docuRef2);
                    docuRef2.RecId = 0;
                    docuRef2.RefTableId =  custInvoiceJour.TableId;
                    docuRef2.RefRecId =  custInvoiceJour.RecId;
                    docuRef2.insert();
                    
                   
                }
            }
     
        }
    
    }
     

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,066 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,585 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans