Expanding the Capabilities of Numbering Tables
A colleague of mine recently posed the question: Is there any way to configure numbering tables to use the Organizational Unit id instead of the Company id? I did some research and found that E-Sourcing does not provide this capability out of the box, but with a little scripting, it can be done.
To review, the E-Sourcing/CLM Numbering Table configuration object allows you to establish a configuration for how various business documents can be uniquely identified. For example, the default configuration for the Project numbering table provided with E-Sourcing/CLM numbers the business documents like: PRO-<sequence_number>-<year>, resulting in numbers like: PRO-00018-2008.
The system does come with some additional configuration options called “tokens” that allow you to configure the generated identifier with a value from certain fields on the business document. For example, the identifier can be generated to include the Company id. Unfortunately, however, the system does not provide for inclusion of the Organizational Unit id.
To provide this capability to the system, I did the following:
1. I put my own special token in the numbering table definition. I included the string value “<%ORG_UNIT%>” in the portion of the numbering table configuration where I wanted the organizational unit id to be inserted.
2. I created a script that replaced any instances of the <%ORG_UNIT%> token above with the id of the associated organizational unit id.
Lets look at this in a bit more detail.
The following image shows the configuration of the numbering table object. Notice that the value of the prefix field includes my special token (<%ORG_UNIT%>). The configuration also calls for a three digit sequence number, followed by the year. If the Organizational Unit has an id of “IT”, the generated project identifier would be: IT-001-2008.
WIth this definition of the numbering table in place, I next added a Script Definition that will process the numbering table configuration when the project is saved. The script definition was setup as a field validation on the CREATED_AT field on the Project module. For those that desire to see actual script coding, it is listed below.
With the numbering table defintion and script in place, I was ready to have the system generate the project identifier using my custom numbering scheme. The following image shows the generated identifier on a test Project.
Although, I have demonstrated this solution in the Project module, it will work anywhere that numbering tables are used.
I hope this was an interesting post for you and I look forward to your comments.
Script Contents
pattern = “<%ORG_UNIT%>”;
// See if the numbering table has the <%ORG_UNIT%> token in it
if (hasValue(doc.getDocumentId()) @and doc.getDocumentId().indexOf(pattern) >= 0)
{
// Make sure the org unit has a value
if (hasValue(doc.getOrganizationalUnitRef()))
{
// Get the org unit external id
busUnitHome = IBeanHomeLocator.lookup(session, doc.getOrganizationalUnitRef());
busUnit = busUnitHome.find(doc.getOrganizationalUnitRef());
// Now update the UNIQUE_DOC_NAME
start = 0;
end = 0;
result = new StringBuffer();
// Replace all instances
while ((end = doc.getDocumentId().indexOf(pattern, start)) >= 0)
{
result.append(doc.getDocumentId().substring(start, end));
result.append(busUnit.getExternalId());
start = end + pattern.length();
}
result.append(doc.getDocumentId().substring(start));
// Actually, set the value
doc.getFieldMetadata(”UNIQUE_DOC_NAME”).set(doc, result.toString());
}
else
{
// Generate an error since we should not have a ORG_UNIT token without the value being set (org unit
// should be required)
throw doc.createApplicationException(null, “error.org_unit_not_set”);
}
}

