Search code examples
acumatica

Add Files to Salesorder line item


I want to add files to salesorder line items in Acumatica using web services. What endpoint should be used? enter image description here

I want to add an image as shown in the screenshot above, using web service endpoint.


Solution

  • REST API needs to reference the detail line in the body. Since the body is used to pass the binary data of the attachment REST API can't be used to attach files to detail line.

    Below is a screen based API snippet that creates a new master/detail document and attach images to the detail line. If you choose to use the screen based API you will need to adapt the snippet for sales order ASMX screen and fetch sales order with expanded details SOLine. The pattern to attach file will be the same:

    string[] detailDescription = "Test";
    List<string> filenames = "image.jpg";
    List<byte[]> images = new byte[] { put_image_binary_data_here } ;
    
    ServiceReference1.Screen context = new ServiceReference1.Screen();
    context.CookieContainer = new System.Net.CookieContainer();
    context.Url = "http://localhost/Demo/Soap/XYZ.asmx";
    context.Login("admin@CompanyLoginName", "admin");
    
    ServiceReference1.XY999999Content content = PX.Soap.Helper.GetSchema<ServiceReference1.XY999999Content>(context);
    
    List<ServiceReference1.Command> cmds = new List<ServiceReference1.Command>
    {
        // Insert Master
        new ServiceReference1.Value { Value="<NEW>", LinkedCommand = content.Document.KeyField},
        new ServiceReference1.Value { Value="Description", LinkedCommand = content.Document.Description},
    
        // Insert Detail
        content.DataView.ServiceCommands.NewRow,
            new ServiceReference1.Value { Value = noteDetail[0], LinkedCommand = content.DataView.Description },
    
        // Attaching a file to detail
        new ServiceReference1.Value
        {
            Value = Convert.ToBase64String(images[0]),
            FieldName = filenames[0],
            LinkedCommand = content.DataView.ServiceCommands.Attachment
        },
        content.Actions.Save,
        content.Document.KeyField
    };
    
    var returnValue = context.PP301001Submit(cmds.ToArray());
    context.Logout();