How to Create a ID field in BCO which behaves as counter
Recently I was involved in a project to create a fine tuning activity which act like any maintenance table in SAP CRM. The purpose of this fine tuning was to create entries in it & later using it in scripts and avoid any hard coding of any attribute values in code.
To create a BCO we have to provide atleast one mandatory field which should be unique , for example ID in my requirement.
But unlike any fine tuning activity we do not want to enter any ID value manually as it should be unique & we might make mistake once table entry increases .
To solve it we can create a counter on ID field which will increment after every add row operation .
Finally it would look like as shown below
To achieve it open BCO QA view in UI designer and follow below steps
- Create a data field in data model as counter
- Go to controller and open ADD Row event Handler
- Create a script type and write below ruby code code
$data.Counter = $data.BC_SETS.RowCount $data.Counter = $data.Counter + 1
- Next create a DataOperation type and assign counter field to data list as shown below
Note : I am still finding why counter increased from 1 to 3 but purpose to create unique ID’s will be solved.
Happy Learning !