I created a Custom Document ID Service for a user specific requirement on Document ID. Basically everything was working already with my Document ID Service.
One of my colleague had another requirement to populate another column with the value from the Custom Document ID for Presentation purposes. He tried to use a workflow but it was encountering problems and sometimes the column is not populated with value. Our suspect is that the workflow didn't sync with the Document ID Service.
I tried to make a workaround by updating the Field through my code for the Custom Document ID Service. It worked well and the Column is now being populated however, the Original Document ID Column is not being populated anymore.
My Code is listed below, basically the 'PopulateCaseFileID' is my method to populate the other column.
//Generate the custom document id
public override string GenerateDocumentId(SPListItem listItem)
{
if (listItem == null)
{
throw new ArgumentNullException("listItem");
}
// PopulateCaseFileID(string.Format(this.idFormat, "STG", DateTime.Today.Year.ToString(),FormatSeed(listItem.ID)), listItem.ID);
return string.Format(this.idFormat, "STG", DateTime.Today.Year.ToString(), FormatSeed(listItem.ID));
}
//Populate Case File ID Column
private void PopulateCaseFileID(string sCaseFileID, int iID)
{
try
{
using (SPSite site = new SPSite("http://intra01ip/sites/ContractManagement/"))
// Or SPContext.Current.Site.Url
{
using (SPWeb Web = site.OpenWeb())
{
Web.AllowUnsafeUpdates = true;
// Open List
SPList list = Web.Lists["Case File"];
SPListItem item = list.GetItemById(iID);
item["Case File ID"] = sCaseFileID;
item.Update();
Web.AllowUnsafeUpdates = false;
}
}
}
catch (Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("Contract Management", ex.Message);
}
}
Artificial intelligence can never beat natural stupidity.