2016-08-30 41 views
0

我需要使用Web API將現有活動的附件更新到Acumatica Partner's Portal中的現有案例。使用附件更新現有活動

我已經爲此編寫了代碼,但它始終更新爲第一個活動,而不是用於傳遞noteid的活動。

我這樣做是通過檢索創建的活動的noteid,然後發送相同的noteid以及caseid來更新附件。

下面是用附件更新現有活動的代碼,請建議。

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

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

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

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

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

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

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

 
Guid? newActivityNoteID = null; 
 

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

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

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

回答

1

看起來像在屏幕基於API搜索提供的GUID的支持。您將必須通過其他字段值來定位必要的附件,例如:類型,摘要和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 
    } 
); 
+0

仍然無法正常工作並更新第一個活動。 – Krunal

+0

你能解釋一下你爲什麼混合來自SP2​​03010WS和CR306000命名空間的類嗎?不知道這應該如何工作... – RuslanDev

+0

對不起,混亂。 CR306000不過是一個對象名稱。它已經在工作,但進行錯誤的活動。以下是供您參考的代碼 SP203010WS.Screen context = new SP203010WS.Screen(); context.CookieContainer = new System.Net.CookieContainer(); context.AllowAutoRedirect = true; context.EnableDecompression = true; context.Timeout = 1000000; context.Url =「https://sso.acumatica.com/Soap/SP203010.asmx」; SP203010WS.LoginResult result = context.Login(username,password); SP203010WS.Content CR306000 = context.GetSchema(); – Krunal