A reader of Siebel Unleashed asked for a solution of a requriement. It was an interesting requirement and one which anybody could come across.So, I thought of sharing it with everybody
Requirement:
On Service Request Screen we have a View where SR is Parent and Activity is Child of SR. If All the Child activities are marked with Status as done for a particular SR then a flag called SRAct Flag should be marked as true otherwise it should be marked as false.
I hope I am clear with the requirement.
Solution:
As usual there are two ways to do this requirement.
Scripting Solution:
On the write record of Action BC write the following Script
var searchExp;
searchExp = “[Activity SR Id] = ‘” + this.GetFieldValue(”Activity SR Id”) + “‘ AND [Status] <> ‘Done’”;
var boSR = TheApplication().GetBusObject(”Service Request”);
var bcSR = boSR.GetBusComp(”Service Request”);
var actbc = boSR.GetBusComp(”Action”);
var SRId = this.GetFieldValue(”Activity SR Id”); // Field storing SR Id
bcSR.ClearToQuery();
bcSR.SetViewMode(3);
bcSR.ActivateField(”SRAct Flag”);
bcSR.SetSearchSpec(”Id”,SRId);
bcSR.ExecuteQuery();
if(bcSR.FirstRecord())
{
actbc.ClearToQuery();
actbc.SetViewMode(3);
actbc.SetSearchExpr(searchExp);
actbc.ExecuteQuery();
if(!actbc.FirstRecord())
{
bcSA.SetFieldValue(”SRAct Flag”,”Y”);
bcSR.WriteRecord();
}
}
Explaination:
This code is executing a query on Action BC checking if there is a record whose status is not ‘Done’ If Not then set the SRAct Flag as Y on Service Request
I know I am going to raise eyebrows of many with this script but I here are some things that I would like to clear straight away.
- This code is going to fire every time you save an activity record. You could add a condition over this code that it should only execute if Status field is set on Action BC to reduce the number of times this code is executed.
- Some of you might think that getting an inactive instance of SR BC is not required and we can we straightaway do this.ParentBusComp().SetFieldValue but I must remind you that Activity also has an independent screen and it doesn’t have any parent on that screen, in that case your code is going to give error. So, this is necessary if you want your code to work from SR as well as Activities Screen
- Last but not the least I have modified a working code to get this code. So, if you try to use it AS IS then you might face some error. Please modify accordingly.
In next post I will discuss Script less solution for this same requirement. Till then have good day.


(2 votes, average: 3.5 out of 5)
13 Comments at "Updating Parent based on Child Records"
totally insane method of doing this
That’s new one
May I dare to ask what will be a sane method to do it???
I have achieved this through configuration.
Totally agree with TEST. This could be easily done just only using configuration. Scripting is evil
and should be used only as last resort.
When I was writting this post I knew I was opening a pandora’s box. The purpose was not to encourage scripting to do everything.
It is quite easy to say this is wrong but what is difficult is tell right thing.
I agree with you that this is not the optimal solution of this problem but would any of you guys would share the configuration solution with us. I am also exploring that option I will post it once done… but till then if any of you out there could share it with us it would be great
Here is config solution:
To achive mentioned functionality we need 3 things - multi-value link (MVL), multi-value field (MVF) and calculated field. Fortunately, there are already MVL “Action” and MVF “Activity Status” in Service Request BC (at least in Siebel 8.0). That’s exactly what is needed and the only thing we should to add is our “SRAct Flag” field, which will be calculated and will have following value: IIF(EXISTS([Activity Status] “Done”),”N”,”Y”)
Between [Activity Status] and “Done” should be “not equal to” operator. Due to some reason it disappeared from comment
I think MVF is not needed. We can added a search spec on the MVL such as [Activity Status] “Done”. Then on the SR BC we can create a calculated Field as “SRAct Flag”. Its calculated Value: IIF(Count(”MVL”)>0, “N”, “Y”).
But this solution will impact the performance because of using the MVL.
good one fedor,you7246mk for suggesting the config based solution…both of these solution require server outage…BUT I worked on similar requirement(defect) which come post live…& user insisted to provide the solution…will let you know how to do it…
Test, I think you need a short-term solution. You can write a BS on the server to implement the logic. (Navigate to Administration->Business Service) So the BS don’t need to be compiled. Then you can set a Runtime Event on the server to run the BS.
fedor,
This is a nice solution but my requirement SRAct is a base field flag not to have a calculated field that is updated.
The reason is that I would like to do setup a policy based on this flag can you modify your solution to reflect this.
Hi Neel,
This is one of the nice articles. Actually, i am new to the scripting. I could not understand the meaning of “actbc.SetSearchExpr(str);” in the above script. if you donot mind could you explain the meaning of that.
Sorry it’s my mistake. It should be
actbc.SetSearchExpr(searchExp); not actbc.SetSearchExpr(str);
I hope it is clear now. I am just creating a search experssion and then executing it using SetSearchExpr
Comment Now!