Scenario II
User needs to save a newly created opportunity along with proper validations in the various fields.
Following are the Events applicable to these scenarios
Event 2.1
BC:
Event : BusComp_NewRecord
The NewRecord event is called after a new row has been created in the business component and that row has been made active.
Functional Use: This event is used set up default values for Field ‘Sales Method’ in the
Code:
function BusComp_NewRecord ()
{
this.ActivateField('Sales Method');
this.SetFieldValue('Sales Method', 'XYZ Sales Methodology');
}
Event 2.2
BC: Opportunity
Event : BusComp_PreWriteRecord
The PreWriteRecord event is called before a row is written out to the database. The event may perform any final validation necessary before the actual save occurs.
function BusComp_PreWriteRecord ()
{
var SalesStage,AccountStatus,bcAccount,boAccount,AccountId,Name,Stat;
SalesStage=this.GetFieldValue("Sales Stage");
if (SalesStage == "" || SalesStage == null )
{
this.SetFieldValue("Sales Stage", "01 - Prospecting")
}
else if (SalesStage == "10 - Closed / Won")
{
ActivateField("Account Id");
AccountId = GetFieldValue("Account Id");
with(bcAccount)
{
SetViewMode(AllView);
SetSearchSpec("Id", AccountId);
ExecuteQuery(ForwardOnly);
Name= GetFieldValue("Name");
ActivateField("Account Status");
Stat=GetFieldValue("Account Status");
}
if (Stat == "Prospect")
{
bcAccount.SetFieldValue ("Account Status","Initiate Request");
bcAccount.WriteRecord();
}
bcAccount=null;
boAccount=null;
}
return (ContinueOperation);
}
Event 2.3
BC:
This event is fired after the record is written to the database. This event can be used to perform any associated actions immediately after the record is written to the database.
Code:
function BusComp_WriteRecord ()
{
var SalesStage,clsdate,boOpty,bcRealizable,month,day,year,Fyearret;//declared for realizable revenue
if (ibProdModify || ibProdModifyMore)
{
var Id = GetFieldValue("Id");
var CloseDate = GetFieldValue("Close Date");
var BOCurrent = TheApplication().ActiveBusObject();
var BOOpty, BCOpty, BCOptyProd;
if ( BOCurrent == "
{
BOOpty = BOCurrent;
BCOptyProd = BOOpty.GetBusComp('
}else
{
BOOpty = TheApplication().GetBusObject("
BCOpty = BOOpty.GetBusComp('
BCOptyProd = BOOpty.GetBusComp('
}
BCOptyProd.ClearToQuery();
BCOptyProd.ExecuteQuery();
var Ret = BCOptyProd.FirstRecord();
if (SalesStage != "14 - Closed / Scrapped" && SalesStage != "10 - Closed / Won" && SalesStage != "12 - Closed / Lost" && SalesStage != "13 - Closed / Shelved")
{
while(Ret)
{
BCOptyProd.SetFieldValue("Expected Delivery Date",CloseDate);
BCOptyProd.WriteRecord();
Ret = BCOptyProd.NextRecord();
}
}
No comments:
Post a Comment