使用附件更新现有 activity

Updating existing activity with attachments

我需要使用 Web API 将现有 activity 的附件从我的申请更新到 Acumatica 合作伙伴门户中的现有案例。

我已经为此写了一个代码,但它总是更新到第一个 activity 而不是我传递 noteid 的 activity。

我通过检索创建的 activity 的 noteid,然后发送相同的 noteid 和 caseid 来更新附件。

以下是更新现有 activity 附件的代码,请提出建议。

var origActivities = context1.Export
 (
  new SP203010WS.Command[]
  {
    new SP203010WS.Value
    {
     Value = currentAcumaticaCaseNo,
     LinkedCommand = content.Case.CaseID
    },

    content.Activities.Type,
    content.Activities.Summary,
    new SP203010WS.Field
    {
     FieldName = "NoteID",
     ObjectName = content.Activities.Summary.ObjectName
    },
    content.Activities.CreatedAt,
  },
  null, 0, false, false
 );

Guid?[] origActivityNoteID = null;
DateTime?[] origActivityCreatedDate = null;
if (origActivities != null && origActivities.Count() > 0)
{
 origActivityNoteID = new Guid?[origActivities.Count()];
 origActivityCreatedDate = new DateTime?[origActivities.Count()];

 int i = 0;
 foreach (string[] activity in origActivities)
 {
  origActivityNoteID[i] = new Guid(activity[2].ToString());
  origActivityCreatedDate[i] = Convert.ToDateTime(activity[3]);
  i++;
 }
}

*****Adding new activity*****

var newActivities = context.Export
 (
  new SP203010WS.Command[]
  {
    new SP203010WS.Value
    {
     Value = currentAcumaticaCaseNo,
     LinkedCommand = content.Case.CaseID
    },

    content.Activities.Type,
    content.Activities.Summary,
    new SP203010WS.Field
    {
     FieldName = "NoteID",
     ObjectName = content.Activities.Summary.ObjectName
    },
    content.Activities.CreatedAt,
  },
  null, 0, false, false
 );

Guid? newActivityNoteID = null;

for (var i = 1; i <= newActivities.GetUpperBound(0); i++)
{
 if(origActivityNoteID != null && origActivityCreatedDate != null)
 {
  if((Array.IndexOf<Guid?>(origActivityNoteID, new Guid(newActivities[i][2])) <= 0) &&
    (Array.IndexOf<DateTime?>(origActivityCreatedDate, Convert.ToDateTime(newActivities[i][3])) <= 0))
  {
   newActivityNoteID = new Guid(newActivities[i][2]);
   break;
  }
 }
}

*****getting a list of all attachments*****

foreach (FileInfo fi in fileInfo)
{
 SP203010WS.Content[] content1 = context.Submit
 (
  new SP203010WS.Command[]
   {
    new SP203010WS.Value
    {
     //Value = actiPartner.AcumaticaCaseID,
     Value = currentAcumaticaCaseNo,
     LinkedCommand = CR306000.Case.CaseID
    },
    new SP203010WS.Value
    {
     Value = newActivityNoteID.ToString(),
     LinkedCommand = new SP203010WS.Field { FieldName="NoteID", ObjectName="Activities" }
    },
    new SP203010WS.Value
    {
     FieldName = fi.Name,
     Value = Convert.ToBase64String(fi.BinData),
     LinkedCommand = CR306000.Activities.ServiceCommands.Attachment
    },
    CR306000.Actions.Save
   }
 );
}

看起来基于屏幕的搜索 API 不支持 GUID。您必须通过其他字段值找到必要的附件,例如:Type、Summary 和 CreatedAt:

Screen context = new Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.Url = "http://localhost/ActivityAttachments/Soap/CR306000.asmx";
context.Login("admin", "123");

var content = context.GetSchema();

var newActivities = context.Export
(
    new Command[]
    {
            new Value
            {
                Value = "000110",
                LinkedCommand = content.CaseSummary.CaseID
            },

            content.Activities.Type,
            content.Activities.Summary,
            content.Activities.CreatedAt,
    },
    null, 0, false, false
);

byte[] filedata;
using (FileStream file = File.Open("EP507011.txt", FileMode.Open))
{
    filedata = new byte[file.Length];
    file.Read(filedata, 0, filedata.Length);
}

Content[] content1 = context.Submit
(
    new Command[]
    {
        new Value
        {
            Value = "000110",
            LinkedCommand = content.CaseSummary.CaseID
        },
        new Key
        {
            ObjectName = content.Activities.Type.ObjectName,
            FieldName = content.Activities.Type.FieldName,
            Value = string.Format("='{0}'", newActivities[newActivities.Length - 2][0])
        },
        new Key
        {
            ObjectName = content.Activities.Summary.ObjectName,
            FieldName = content.Activities.Summary.FieldName,
            Value = string.Format("='{0}'", newActivities[newActivities.Length - 2][1])
        },
        new Key
        {
            ObjectName = content.Activities.CreatedAt.ObjectName,
            FieldName = content.Activities.CreatedAt.FieldName,
            Value = newActivities[newActivities.Length - 2][2]
        },
        new Value
        {
            FieldName = "EP507011.txt",
            Value = Convert.ToBase64String(filedata),
            LinkedCommand = content.Activities.ServiceCommands.Attachment
        },
        content.Actions.Save
    }
);