Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

To Pass the attachemnt from one form to another

(0) ShareShare
ReportReport
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 6,493 Super User 2024 Season 2 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... 291,642 Super User 2024 Season 2 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,550 Super User 2024 Season 1 on at
    To Pass the attachemnt from one form to another
  • Layan Jwei Profile Picture
    Layan Jwei 7,264 Super User 2024 Season 2 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();
                    
                   
                }
            }
     
        }
    
    }
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans