Skip to main content

Notifications

Announcements

No record found.

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

To delete attachments from header , if attachment from line is deleted.

(0) ShareShare
ReportReport
Posted on by 1,457
hi i have button on form which upload the attachment on line and pass it to  header using buftobuf, but when i delete the attachment from line i want the same attchment to be deleted from header , can any one help me out how can i get this done .
where do i need to code which method i need to use can you please guide me on this . below is the code i written on button .
 
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To delete attachments from header , if attachment from line is deleted.
    hi 
    every one , 
     as of requirement , i cannot create display field , and as the attachent symbol shows sum i need to show the sum of both line and header on that symbol , i have managed to delete the attachment if line is deleted then the attachment in header will also get deleted , using the relation and value recid on docuref table . but as martin said ,  and due to data duplication is need to work on it more it now it is given for testing .i will update on it soon .
     
    thanks ,
    regards ,
    Dinesh 
  • NAGA Profile Picture
    NAGA 7 on at
    To delete attachments from header , if attachment from line is deleted.
    Hi Dineshkarlekar,
     
    If your goal is to display the number of attachments for the document (Header + Lines), Why don't you use a display field on the Header to do the same. This will save the resources from duplicate data. 
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To delete attachments from header , if attachment from line is deleted.
    hi , 
    thanks for reply ,
    I will update you on this . 
  • Martin Dráb Profile Picture
    Martin Dráb 230,468 Most Valuable Professional on at
    To delete attachments from header , if attachment from line is deleted.
    I'm not convinced that changing the meaning of this number at a single place is good idea. It looks confusing that the number will mean the number of attachments of the current record in the whole system except your modification, and the combined number for the header and all lines at the single place you're changing.
    If they're fine with you copying all attachments to the header, why they don't simply put their attachments there?
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,759 Super User 2024 Season 2 on at
    To delete attachments from header , if attachment from line is deleted.
    Hi Dineshkarlekar,
     
    The approach is wrong. You can better create an additional view to show attachments from lines and the header in a central place. Currently, it is not even possible to find the header attachment as you don't maintain any link between the header and the line attachments. 
     
    Why not just let the user add all attachments on the header? As Martin also asked, what is the business requirement? What is the process about? Why is someone maintaining attachments on the lines?
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To delete attachments from header , if attachment from line is deleted.
    hi martin thanks for reply ,
    as per requirement , when i attch the file from line the total of header and line should be shown on the attachment symbol, , that why i am passing the line attachment to header but when the line is deleted that attachement should also get deleted from both header and line .
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,468 Most Valuable Professional on at
    To delete attachments from header , if attachment from line is deleted.
    If you ask me, the problem is in a wrong design - you should avoid of duplicating the data at two places. It wastes data in database, it waste resources by keeping the copies in sync (or cause data inconsistency if you fail to implement synchronization correctly) and it sounds confusing from user's perspective as well/.
     
    What is the business requirement that you decided to duplicate DocuRef records? Maybe we can suggest a solution that we'll be both easier to implement and more efficient to use.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To delete attachments from header , if attachment from line is deleted.
    code on button to pass the record from line to header .
     public static void main(Args _args)
        {
            FileUploadTemporaryStorageResult  result;
            DTPropertyLine        dtPropertyLine;
            DTProrpertyHeader     dTProrpertyHeader;
            DocuRef               docuRef2;
            dtPropertyLine = _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(
                                dtPropertyLine.TableId,
                                dtPropertyLine.RecId,
                                dtPropertyLine.DataAreaId,
                                "Propertyattachment",
                                stream,
                                fileName,
                                System.Web.MimeMapping::GetMimeMapping(filename),
                                fileName);
                  select * from dTProrpertyHeader
                        where dTProrpertyHeader.RecId == dtPropertyLine.RefRecId;
    
                  buf2Buf(docuRef,docuRef2);
                    docuRef2.RecId = 0;
                    docuRef2.RefTableId =  dTProrpertyHeader.TableId;
                    docuRef2.RefRecId =  dTProrpertyHeader.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! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,468 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans