This post is in continuation of my series where we discuss various events that are available for us to script, today we are going to discuss BusComp_SetFieldValue event available in a BC.
SetFieldValue is similar to PreSetFieldValue in certain aspects such as it is triggered when we try to change a field value but some noticeable differences between SetFieldValue and PreSetFieldValue events are:
Execution Sequence:
PreSetFieldValue is executed before SetFieldValue event.
RaiseErrorText Behavior:
Both events respond differently when it comes to RaiseErrorText Statement.
PreSetFieldValue fires before the value is set for that field, so in case of return cancel operation or RaiseErrorText the value use is trying to set will not be set and value of that field will be reverted back to old value.
In SetFieldValue event even though user will see the error message still the value he is trying to set will be present and not reverted back.
Precaution:
While using SetFieldValue never write any validation script in this event as the changes user had made still remains and even after getting the error message user can save the record.
One more thing that you need to keep in mind is that user still has an option to UNDO the record in case your script doesn’t result in write record don’t forget to undo the changes your script has made.
For example you have written the following script
function BusComp_SetFieldValue (FieldName)
{
if ((FieldName == "Discount Amount"))
{
if(this.GetFieldValue(“Discount Amount”) == 500)
{
TheApplication().RaiseErrorText(“Not Allowed”);
}
}
}
Now the problem with this code is that user will get an error message but the value of the field will still be 500 and if user saves the record it will get saved.
You should have exercise extreme caution while implementing these kind of validations.
So, in the end we can summaries it as following
- Don’t use SetFieldValue for validation scripts
- Always have a check with Field Name before writing the script
- Try to avoid scripting in this event.
- The most common use of this event is to set value of another field based on some logic or conditions that is not possible through user properties like On Field Update Set n.
And as usual this post is open to your comments so that we can put more do’s and dont’s regarding this event. Please contribute to make it more complete.
Looking forward to your participation.


(2 votes, average: 3.5 out of 5)
1 Comment at "Siebel BC scripting events - BusComp_SetFieldValue"
SetFieldValue used in RunTimevents ( with DVM as action) will prevent the setting of field value.
Comment Now!