Pages

Monday, June 5, 2017

Sequence Number Field in parent BC

Customer requirement as below;

On updating sales stage of Opportunity to a particular stage (Eg: “Governance Approval”), There will be a custom field as ESGB reference number, which will be generated sequentially in a defined format (Eg: ESGB000300001)


Solution:

I have used the vanilla BC sequence generation to accomplish the requirement together with some scripting to generate the format

It is also possible to create a DB sequence and associate the sequence to the field.(Which is not discussed here)

So in our way, first we create the sequence field as below;

  • Add a Field in the Opportunity BC
    • Name: esgb_seq
    • Type : DTYPE_NUMBER
    • Column : X_ESGB_SEQ (Pls add a new column or associate existing column which is not used)
  • Add a Business Component User property to Opportunity  BC
    • Name: Sequence Field
    • Value : esgb_seq
  • Create a new Business Component
    • Name: Opportunity.esgb_seq (Sequence)
    • Class : CSSSequence
    • Sort Spec: Sequence (DESCENDING)
    • Table: S_OPTY
  • Add a field in BC created above step
    • Name : Sequence
    • Column : X_ESGB_SEQ
  • Add the Business Object Component under Business Object Opportunity
    • Bus Comp : Opportunity.esgb_seq (Sequence)
Now a sequence number should be generated starting from 1 for each new opportunity created.
You can expose the esgb_seq field in UI for verification. But later you should remove it from UI

Then define a method to populate this sequence(Formatted according to requirement) to a different field when a button is clicked.


function BusComp_PreInvokeMethod (MethodName)
{
if (MethodName=="ESGBRef")
{
var rowSeq=this.GetFieldValue("esgb_seq");
var strEsgbSeq="" ;
var strLength = 9 - rowSeq.length;
if (strLength == 1)
strEsgbSeq = "ESGB" +  "0" + rowSeq;
else if (strLength == 2)
strEsgbSeq = "ESGB" +  "00" + rowSeq;
else if (strLength == 3)
strEsgbSeq = "ESGB" +  "000" + rowSeq;
else
strEsgbSeq = "ESGB" + rowSeq;
this.SetFieldValue("ESGB_Number", strEsgbSeq);
this.WriteRecord();
}
}

Here I have used the starting value of the sequence as 300001 to fulfill the formatting

Hope this helps...

No comments:

Post a Comment