Skip to main content
Solved

Files - How to access ADD LINK button from Code Level

  • 2 September 2024
  • 2 replies
  • 47 views

Forum|alt.badge.img

Hello Everyone,

We have requirement to add the Files in the FILES section using the ADD LINK button. Can you please help me how to add the Files using ADD LINK button from Code?

 

 

Best answer by taras

Hi, Add Link button creates link between File and some Entity. To create this link from code you need to insert into NoteDoc NoteID of an Entity and FileID of a File. You can use code of Add Link button: 
 

    protected IEnumerable addLink(PXAdapter a)
    {
        try
        {
            PXFilter<FileDialog> fileDialog = FileDialog;
            if (fileDialog != null && (fileDialog.Current?.Entity).HasValue && Files.Current != null)
            {
                PXDatabase.Insert<NoteDoc>(new PXDataFieldAssign[2]
                {
                    new PXDataFieldAssign("NoteID", PXDbType.UniqueIdentifier, FileDialog?.Current?.Entity),
                    new PXDataFieldAssign("FileID", PXDbType.UniqueIdentifier, Files.Current.FileID)
                });
            }

            return a.Get();
        }
        catch (PXDatabaseException ex)
        {
            if (ex.ErrorCode != PXDbExceptions.PrimaryKeyConstraintViolation)
            {
                throw ex;
            }

            throw new Exception("Can't insert link more than once", ex);
        }
    }

 

View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img+1
  • Jr Varsity I
  • 21 replies
  • Answer
  • September 3, 2024

Hi, Add Link button creates link between File and some Entity. To create this link from code you need to insert into NoteDoc NoteID of an Entity and FileID of a File. You can use code of Add Link button: 
 

    protected IEnumerable addLink(PXAdapter a)
    {
        try
        {
            PXFilter<FileDialog> fileDialog = FileDialog;
            if (fileDialog != null && (fileDialog.Current?.Entity).HasValue && Files.Current != null)
            {
                PXDatabase.Insert<NoteDoc>(new PXDataFieldAssign[2]
                {
                    new PXDataFieldAssign("NoteID", PXDbType.UniqueIdentifier, FileDialog?.Current?.Entity),
                    new PXDataFieldAssign("FileID", PXDbType.UniqueIdentifier, Files.Current.FileID)
                });
            }

            return a.Get();
        }
        catch (PXDatabaseException ex)
        {
            if (ex.ErrorCode != PXDbExceptions.PrimaryKeyConstraintViolation)
            {
                throw ex;
            }

            throw new Exception("Can't insert link more than once", ex);
        }
    }

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3382 replies
  • September 4, 2024

@nsmith51  Have you tried with the SetFileNotes?


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings