Creating a sequence of activities
Customer requirement:
There are some approval activities in opportunity as Gate 0 Approval, Gate 1 Approval, Gate 2 Approval, Gate 3 Approval, Users will be allowed to create each approval only after the previous approval activity status is "Approved" except Gate 0 Approval.
Solution:
This I have achieved basically through scripting. First we have to create four different activity types for the above requirement. I have created below four activity types under Administration- Data -- List of Values (Lov Type - TODO_TYPE)
- ESGB Gate 0
- ESGB Gate 1
- ESGB Gate 2
- ESGB Gate 3
Then we can write validation under BusComp_PreSetFieldValue of 'Action' BC to validate the previous activity status, when the user select the activity type.
Here as we have to validate three activities, I have written a general function and then associated the function at BusComp_PreSetFieldValue .
Please be reminded that, the Action BC should be a child of Opportunity BC while we do this validation.
Function ESGBApprovalSeq(fVal)
{
var optyId ="";
//Verify whether the Parent is Opportunity
if (this.ParentBusComp() != null)
{
if (this.ParentBusComp().Name() == "Opportunity")
{
//Get the Opportunity ID related to the activity.
var Optybc = this.ParentBusComp();
optyId = Optybc.GetFieldValue("Id");
}
}
//Search in Action BC for activities which is having the opportunity ID,
//Activity type defined by function variable and activity status as approved
var boBusObj = TheApplication().GetBusObject("Opportunity");
var bcAct = boBusObj.GetBusComp("Action");
with (bcAct)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Status");
SetSearchSpec("Opportunity Id", optyId);
SetSearchSpec("Type", fVal);
SetSearchSpec("Status", "Approved");
ExecuteQuery(ForwardOnly)
//If No such record throw error;
if(FirstRecord()== false)
{
this.UndoRecord()
TheApplication().RaiseErrorText("Previous Gate Approval not yet completed!");
}
}
}
In BusComp_PreSetFieldValue , write below;
function BusComp_PreSetFieldValue (FieldName, FieldValue)
{
if(FieldName == "Type")
{
if (FieldValue == "ESGB Gate 1")
ESGBApprovalSeq("ESGB Gate 0")
else if (FieldValue == "ESGB Gate 2")
ESGBApprovalSeq("ESGB Gate 1")
else if (FieldValue == "ESGB Gate 3")
ESGBApprovalSeq("ESGB Gate 2")
}
}
This will validate whether the defined activity status is "Approved"
Hope this helps...⏩