Master Data Services : Getting Errors out of a ModelMembersBulkUpdate/Merge with API

In fact, you can get the error codes on MDS website : in “Integration Management/Staging Batches” clicking on the batch you want and clicking on button “view details for selected batch”
in order to do the same thing with API (get error codes), you’ll need to get info from the batch after it has been inserted. 


 

//get information related to a staging batch
 public Collection StagingGet(Collection stagingBatch, bool ReturnAllCriteria, bool ReturnMembers, bool ReturnAttributes, bool ReturnRelationShips, ref OperationResult or)
 {
 Collection colUnbatched = new Collection();
 Collection colBatches = new Collection();
 using (ServiceClient c = MDS_WSConnect.CreateMdsProxy())
 {
 or = new OperationResult();
 colBatches = c.StagingGet(new International(), true, new StagingResultCriteria() { All = ReturnAllCriteria, Attributes = ReturnAttributes, Members = ReturnMembers, Relationships = ReturnRelationShips },
 new StagingSearchCriteria() { StagingBatches = stagingBatch, StagingDataStatus= StagingDataStatus.All }, out or, out colUnbatched);
 List lstErr = new List();
//...do what you need with the error collection
foreach (StagingBatchError err in colBatches.First().Errors)
{
 lstErr.Add(err.ErrorCode + " - " + err.TargetCode);
 }
return colBatches;
}
}

so, complete process would be:

DateTime dtBefore = DateTime.Now; 
OperationResult or = new OperationResult();
  //filling new staging batch with entityMembers
  Collection colStaging = ModelMembersBulkMerge(colEntMembers);
  //initiating the staging process (not sure I really need that here in fact)
  Collection colBatches = StagingGet(colStaging, true, true, true, false, ref or);
  //triggering staging
  ProcessUnbatchedStaging(pModelId, pVersionId);
DateTime dtAfter = DateTime.Now;
TimeSpan ts = dtAfter.Subtract(dtBefore);

MessageBox.Show("members (bulk) inserted : " + colEntMembers.First().Members.Count() + "\r\n" + "time elapsed (seconds):" + ts.TotalSeconds.ToString());
//get back the batch to see if any errors

colBatches = StagingGet(colStaging, true, true, true, false, refor);

note: StagingDataStatus= StagingDataStatus.All –> get all including Errors

Bookmark the permalink.

About Xavier

7 years+ .net consulting

Leave a Reply

Your email address will not be published.

Captcha * Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.