我需要使用Web API从我的应用程序更新现有活动的附件到Acumatica合作伙伴门户网站中的现有案例。
我已经为此编写了一个代码,但它总是更新到第一个活动而不是我传递noteid的活动。
我这样做是通过检索所创建活动的noteid然后发送相同的noteid以及caseid来更新附件。
以下是使用附件更新现有活动的代码,请建议。
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
}
);
}
答案 0 :(得分:1)
在基于屏幕的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
}
);