In my last post I described how we can use ParentBusComp() to reduce the amount of scripting that we have to do while updating the parent record based on some even on child record. But you shouldn’t be using this with you eyes closed as this can result in error at some places. I will try to explain it with example.
You write the following line of code in the Action BC WriteRecord
if (this.ParentBusComp().Name() == “Service Request”)
{
Do something
}
As we all know that we have Activities screen based on Action BC in where it has no parent. If I go there and try to save the record it is going to give an error.
“NULL Types cannot be converted into objects”
Reason:
Because Action has no parent in the given scenario so this.ParentBusComp() returns a null so the statement is evaluated in this way null.Name () == “ServiceRequest” which is wrong.
Solution:
You should always take care of scenario where it ParentBusComp() function can return a null.
This can be done in following way
if (this.ParentBusComp() != null)
{
if (this.ParentBusComp().Name() == “Service Request”)
{
Your logic
}
}
One more solution can be use this.ParentBusComp() only for BC’s which will always have a parent.
Use normal way to query on an inactive instance in case there are some places where BC has no parent.

(1 votes, average: 4 out of 5)
1 Comment at "this.ParentBusComp() use with caution"
This is an excellent info. I’ve stumbled upon some issues related to this. This is really a good tip. Thanks.
Comment Now!