web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

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

(0) ShareShare
ReportReport
Posted on by 1,836
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 .
 
I have the same question (0)
  • Dineshkarlekar Profile Picture
    1,836 on at
    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();
                    
                   
                }
            }
     
        }
     
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    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
    1,836 on at
    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 .
     
  • André Arnaud de Calavon Profile Picture
    301,109 Super User 2025 Season 2 on at
    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?
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    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?
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi , 
    thanks for reply ,
    I will update you on this . 
  • NAGA Profile Picture
    7 on at
    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
    1,836 on at
    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 

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans