Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / To Pass the attachemnt...
Finance forum
Answered

To Pass the attachemnt from one form to another

Posted on by 1,457
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,457 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 3,904 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,457 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,457 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
     
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 288,584 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,540 Super User on at
    To Pass the attachemnt from one form to another
  • Layan Jwei Profile Picture
    Layan Jwei 4,815 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,457 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

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,584 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,864 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans