Business Requirement:
Create an Opportunity and step off the record. An error message should be thrown if the Probablity of the Opportunty is 0% and Sales Cycle is blank.
Solution:
Where to put the code:
@ Business Component level we are writing the code proactively,
as this is validation at record level we decided to put the code at Pre event...
function BusComp_PreWriteRecord ()
{
var prob; // declaring the objects
var sales; //declaration again
prob = this.GetFieldValue("Primary Revenue Win Probability");
sales = this.GetFieldValue("Sales Stage");
if(prob == '0' && sales == '' )
{
TheApplication().RaiseErrorText("Percentage should be greater than 0 and Sales Stage should not be blank");
}
}
Compile and test!!!
BusComp_PreWriteRecord Event : Called before a row is written out to the database.
This event can perform any final validation necessary before any internal record-level validation is performed.
CAUTION: Take caution when using the Raise Error and RaiseErrorText methods in
BusComp_PreWriteRecord, because they cancel operations. For example, if RaiseErrorText is used in
BusComp_PreWriteRecord, the user or code will not be able to step off the current record until the
condition causing the RaiseErrorText method to be invoked is addressed.
Create an Opportunity and step off the record. An error message should be thrown if the Probablity of the Opportunty is 0% and Sales Cycle is blank.
Solution:
Where to put the code:
@ Business Component level we are writing the code proactively,
as this is validation at record level we decided to put the code at Pre event...
function BusComp_PreWriteRecord ()
{
var prob; // declaring the objects
var sales; //declaration again
prob = this.GetFieldValue("Primary Revenue Win Probability");
sales = this.GetFieldValue("Sales Stage");
if(prob == '0' && sales == '' )
{
TheApplication().RaiseErrorText("Percentage should be greater than 0 and Sales Stage should not be blank");
}
}
Compile and test!!!
BusComp_PreWriteRecord Event : Called before a row is written out to the database.
This event can perform any final validation necessary before any internal record-level validation is performed.
CAUTION: Take caution when using the Raise Error and RaiseErrorText methods in
BusComp_PreWriteRecord, because they cancel operations. For example, if RaiseErrorText is used in
BusComp_PreWriteRecord, the user or code will not be able to step off the current record until the
condition causing the RaiseErrorText method to be invoked is addressed.