Friday, December 12, 2008

Workflow made simple - Part II - Iterate over child records

...welcome back to Part II of our tour de workflow

Let's reiterate the requirement #2

Retrieve total opportunity revenue for an Account
Sum up the revenue of the current Opportunities for an Account and write the result to an Account field.

This is the prototype workflow. As in part I, Siebel 8.1 was the implementation platform.

The workflow itself has the following properties:

Business Object: Account
Process Properties created: CurrentRevenue, LastRecord, RecordCount, TotalRevenue

Get Oppties Step:
Business Component: Opportunity
Operation: Query
Search Spec Expression: "[Account Id]='" + [&Object Id] + "'"
Output Args: TotalRevenue = BC Oppty.Primary Revenue Amount
RecordCount = Output Argument NumAffRows

Decision Step Last Record?
yes = Process Property LastRecord = true
no = Default

Go to next Oppty Step
BC: Opportunity
Operation: NextRecord
Output Args:
CurrentRevenue = Opportunity.Primary Revenue Amount (1)
TotalRevenue = Expression: [&TotalRevenue] + [&CurrentRevenue] (2)
LastRecord = Output Arg: NoMoreRecords (3)
Note: Numbers in brackets indicate the sequence of the output arguments

Update Account Step
BC: Account
Operation: Update
Field Input Arg: Revenue = Process Property TotalRevenue

Note #1: The workflow operates on the Account Business Object with Account as the primary BC and Opportunity as a child BC.

Note #2: Despite Note #1 it is still necessary to execute a query to get the Opportunites associated with the Account.

Note #3: The fairly new Siebel Operation NextRecord (along with its siblings PreviousRecord and QueryBiDirectional) has been introduced in Siebel 8.0. It is the first version that allows us to loop through a record set in a workflow without being outwitted by the complexity of looping. The NextRecord operation has an output argument of NoMoreRecords (true or false) which must be used in a decision step to determine whether the loop has to end or not.

Pitfall #1: Adding up the revenue amount requires two process properties. One to get the field value from the BC and the other one to serve as the accumulator. Note the sequence in the NextRecord operation to fill them in the correct order.

This article is part of a series on Siebel Workflow. So far the following articles have been posted:

Part I: Update multiple records
Part III: Display error messages
Part IV: Using dot notation

To be continued in January 2009, please post a comment if you want me to cover a specific area.



Karsten Neve said...

Hi @lex,

1. you are already in an instanciated BO for one account, e.g. a query on a child BC will only retrieve the datasets linked to this account. So I think that the SearchSpec is not necessary.

2. Looping through a child BC is also possible in 7.x - not so stylish as in 8.x, but possible within vanilla. Take a look at vanilla's BS "SIA BC Utility Service", Method "BCNextRecord" - it's made for this. It also supports automated summing up of a field's values while looping.


@lex said...

Hi Karsten,

many thanks for your comment. You are correct that the Search Spec is not really necessary, executing an empty query would also retrieve the child records.

Thank you also for mentioning one of the many useful business services in Siebel Industry Applications.

There are definitely many ways to loop through a record set without the need for scripting. I remember using EAI Siebel Adapter and its QueryPage method.

Have fun


Anonymous said...


i would be glad if u can explain me the step by step process of sending an email by workflow(email notification to the customer or manager).treat this as urgent and post ur expertise.


@lex said...

Hi Veeru,

please refer to the Siebel Workflow Guide. There is an example of using the Outbound Communications Manager business service to accomplish your requirement.

Have a nice day


Antonio said...

Hello Alex,
I am trying to build this but I am having difficulties with defining the Decision Step for testing Lastrecord.
I've created a Process Property Lastrecord, type String with Default: False.
In the GetNextStep I've pointed the Lastrecord to the OutputArgument NoMoreRecords.
When defining the Conditions for the decision step I am using the Process Property Lastrecord AllMustMatch value 'True'. It issues a msg when saving the condition (Error... check with the System admnistrator)... but somehow when looking again at Edit Conditions the condition is there..

So, is this Lastrecord a string type ? (I was hoping boolean but could not find type boolean)

Would it be possible for you to post the Export file for this sample WF ? It would be of great help...

Txs. for any help

suya said...

Defined rules to auto assign sales team members (My auto assign team feature) to the opportunity based on Org definition. i want to know how should i define the workflow of it i am fresher in Siebel please help about workflow how to create in detail

@lex said...

Hi Suya,

unfortunately your initial requirements are very unclear. Have you tried to use Assignment Manager for opportunity team assignment?

have a nice day


Nitin Jain said...

Great one, Alex !!
Just took a leaf out of it.

Alex, when running the step "go to next Oppty" for the first time, it retrieves NULL values. I was trying to concatenate strings. Added a condition to not concatenate on the first loop.

Rest, simply wonderful.. :)

Nitin Jain