如何使用acumatica web服务在acumatica屏幕上上传文件

How to Upload document in acumatica screen using acumatica web service

我刚开始使用acumatica 网络服务。是否可以在特定屏幕中上传文档/文件作为附件,如企业帐户附件。

例如。在我们手动添加的屏幕下方。

我找到解决方案并发布以帮助任何人。 要上传任何文件,我们必须将该文件转换为字节并提交转换文件的字节。

             //Get bytes of file

             byte[] filedata;
             using(System.IO.FileStream file =
             System.IO.File.Open(@"D:\Test.pdf",System.IO.FileMode.Open)) 
             {
                 filedata = new byte[file.Length];
                 file.Read(filedata,0,filedata.Length);
             }

            //   Import Data Now to Business Account

                BAccount.CR303000ImportResult[] lstObjContent = context.CR303000Import
               (
                new BAccount.Command[]
               {
                 // Must Pass BusinessAccount in which we want to update or add data
                 new BAccount.Value { Value="XXXXXX",LinkedCommand=objContent.AccountSummary.BusinessAccount},
                 new BAccount.Value { Value="TestValue123",LinkedCommand=objContent.AccountSetup.CurrentMethod},
                 new BAccount.Value { FieldName="NameOfFileWithExtension",LinkedCommand=objContent.AccountSummary.ServiceCommands.Attachment},
                 objContent.Actions.Save
                },null,new string[][] { new string[] { Convert.ToBase64String(filedata) },new string[] { Convert.ToBase64String(filedata) },}
                 ,false,false,true
            );

即使是下面的代码也可以。在版本 18R1 中验证。

 var content = _context.CR306000GetSchema(); _context.CR306000Clear();

 var commands = new List();

 ReqParameter(content, ref commands);

 commands.Add(content.Actions.Save);

 commands.Add(content.CaseSummary.CaseID);

 var orderResults = _context.CR306000Submit(commands.ToArray());

 private static void ReqParameter(CR306000Content content, ref List<Command> cmds)
    {
        if (cmds == null) throw new ArgumentNullException("cmds");        

        byte[] filedata= null;            
        Uri uri = new Uri("https://acmdev.baccahq.com/Icons/login_bg5.jpg");  // change the required url of the data that has to be fetched 

        if (uri.IsFile)
        {
            string filename = System.IO.Path.GetFileName(uri.LocalPath);
            filedata = System.Text.Encoding.UTF8.GetBytes(uri.LocalPath);
        }
        if (filedata == null)
        {
            WebClient wc = new WebClient();
            filedata = wc.DownloadData(uri);
        }

        cmds = new List<Command>
        {

            //Case Header Details
            new Value { Value="<NEW>",LinkedCommand = content.CaseSummary.CaseID},
            new Value { Value="L41",LinkedCommand = content.CaseSummary.ClassID},
            new Value { Value="ABCSTUDIOS",LinkedCommand = content.CaseSummary.BusinessAccount, Commit = true},          
            new Value { Value="Test subject created from envelop call 11C",LinkedCommand = content.CaseSummary.Subject},           

            // body of the case 
            new Value{Value= "Body of the content for created through envelop call 11B", LinkedCommand = content.Details.Description},


            //Attaching a file
            new Value
            {
                Value = Convert.ToBase64String(filedata),   // byte data that is passed to through envelop 
                FieldName = "Test.jpg",
                LinkedCommand =
            content.CaseSummary.ServiceCommands.Attachment
            },


         };
    }