You are on page 1of 12

Applet : Opportunity Form Applet – Child

BusComp: Opportunity
Control: Sales Team
Field: Sales Rep
MVG : Sales Team Mvg Applet
MVG BusComp: Position

Script on MVG Applet:

function WebApplet_PreInvokeMethod (MethodName)


{
// Profile attribute "CurrentTeamMember" is being used by the
// 'Add Sales Team Popup Applet NetApp' applet
var lEmployeeId = this.BusComp().GetFieldValue("Employee Id");
TheApplication().SetProfileAttr("CurrentTeamMember", lEmployeeId);

return(ContinueOperation);
}

function WebApplet_PreCanInvokeMethod (MethodName, &CanInvoke)


{
if (MethodName == "AddTeam")
{
CanInvoke="TRUE";
return (CancelOperation);
}
else
return (ContinueOperation);
}

General Sction:-

/*
Author: Jonthan Lee
Date: 7/10/03
Desc: This function adds Sales Team members of the selected employee
to the opportunity team.
*/
function AddOpportunityTeam(BOOpty)
{
var BCOptyPosNetApp = BOOpty.GetBusComp("Opportunity Position NetApp");
var BCOpty = BOOpty.GetBusComp("Opportunity");

var sOptyId = BCOpty.GetFieldValue("Id");


var sCurrEmpId = this.BusComp().GetFieldValue("Employee Id");

if (sCurrEmpId != "")
{
var BOEmp = TheApplication().GetBusObject("Employee");
var BCEmp = BOEmp.GetBusComp("Employee Sales Team NetApp");

//query for sales team members of empID


BCEmp.ClearToQuery();
BCEmp.SetViewMode(AllView);
BCEmp.ActivateField("Employee Id NetApp");
//BCEmp.ActivateField("Employee Login NetApp");
BCEmp.ActivateField("Primary Position Id");

BCEmp.SetSearchSpec("Employee Id NetApp" , sCurrEmpId);


BCEmp.SetSearchSpec("Type", "Sales Team");
BCEmp.ExecuteQuery();

var isRecordEmp = BCEmp.FirstRecord();

while (isRecordEmp)
{
var sEmpId = BCEmp.GetFieldValue("Employee Id NetApp");
var sEmpPostnId = BCEmp.GetFieldValue("Primary Position Id");

BCOptyPosNetApp.ClearToQuery();
BCOptyPosNetApp.SetViewMode(AllView);
BCOptyPosNetApp.SetSearchSpec("Opportunity Id", sOptyId);
//BCOptyPosNetApp.SetSearchSpec("Employee Id", sEmpId);
BCOptyPosNetApp.SetSearchSpec("Position Id", sEmpPostnId);
BCOptyPosNetApp.ExecuteQuery();

if (BCOptyPosNetApp.FirstRecord())
{
//employee already part of team
}
else
{
//adds sales team members of current member to opportunity
team
BCOptyPosNetApp.NewRecord(NewAfter);
BCOptyPosNetApp.SetFieldValue("Opportunity Id", sOptyId);
//BCOptyPosNetApp.SetFieldValue("Employee Id", sEmpId);
BCOptyPosNetApp.SetFieldValue("Position Id", sEmpPostnId);
BCOptyPosNetApp.WriteRecord();
}

isRecordEmp = BCEmp.NextRecord();
}

this.BusComp().ClearToQuery();
this.BusComp().ExecuteQuery();
}

BCEmp = null;
BOEmp = null;
BCOpty = null;
BCOptyPosNetApp = null;
}

/*
Author: Jonthan Lee
Date: 7/10/03
Desc: This function adds Sales Team members of the selected employee
to the respective team.
*/
function AddTeam()
{
var BOActive = TheApplication().ActiveBusObject();
if (BOActive.Name() == "Opportunity")
{
AddOpportunityTeam(BOActive);
}
BOActive = null;
}

function AddTeamORIG()
{
/*
This code is valid only when there is one one to one relationship between Position and Login Id
ie User.
*/

try
{
var posBC ;
var searchExpr = "";
var newLine = String.fromCharCode(10);
var noPosAdded = true;

// newLine = newLine + String.fromCharCode(13);

posBC = this.BusComp();
var empID = posBC.GetFieldValue("Active Emp Id");

var empBO = TheApplication().GetBusObject("Employee");


var empBC = empBO.GetBusComp("Employee Sales Team NetApp");
empBC.SetViewMode(3);
empBC.ActivateField("Employee Id NetApp");
empBC.ActivateField("Employee Login NetApp");
empBC.ClearToQuery();
empBC.SetSearchSpec("Employee Id NetApp" ,empID);
empBC.SetSearchSpec("Type", "Sales Team");
empBC.ExecuteQuery();
var isRecordEmp = empBC.FirstRecord();

while (isRecordEmp)
{
if (searchExpr == "" )
{
searchExpr = "EXISTS([Login Name] = '" ;
searchExpr = searchExpr + empBC.GetFieldValue("Employee
Login NetApp") ;
searchExpr = searchExpr + "')";
}
else if (searchExpr != "")
{
searchExpr = searchExpr + " OR EXISTS([Login Name] = '" ;
searchExpr = searchExpr + empBC.GetFieldValue("Employee
Login NetApp")
searchExpr = searchExpr + "')";
}

isRecordEmp = empBC.NextRecord();
}

if (searchExpr != "")
{

var newPosBO = TheApplication().GetBusObject("Position");


var newPosBC = newPosBO.GetBusComp("Position");
newPosBC.SetViewMode(3);
newPosBC.ActivateField("Active First Name");
newPosBC.ActivateField("Active Last Name");
newPosBC.ClearToQuery();
newPosBC.SetSearchExpr(searchExpr);
newPosBC.ExecuteQuery();
var accntposBO = TheApplication().GetBusObject("Account");
var accntposBC = accntposBO.GetBusComp("Account Position
NetApp");
accntposBC.SetViewMode(3);
accntposBC.ActivateField("Opportunity Id");
accntposBC.ActivateField("Position Id");
var intValue = newPosBC.FirstRecord();
while (intValue)
{
var newExpr = "[Account Id] = '" +
posBC.ParentBusComp().GetFieldValue("Id") + "' AND [Position Id] = '" +
newPosBC.GetFieldValue("Id") +"'" ;

accntposBC.ClearToQuery();
accntposBC.SetSearchExpr(newExpr);
accntposBC.ExecuteQuery();
var isRecord = accntposBC.FirstRecord();

if (isRecord == false)
{
accntposBC.NewRecord(NewAfter);
accntposBC.SetFieldValue("Account Id"
,posBC.ParentBusComp().GetFieldValue("Id"));
accntposBC.SetFieldValue("Position Id"
,newPosBC.GetFieldValue("Id"));
noPosAdded = false;
accntposBC.WriteRecord();

}
/*
else
{

var msg = newPosBC.GetFieldValue("Active First


Name");
msg = msg + " " + newPosBC.GetFieldValue("Active
Last Name");
msg = msg + " is already a member of the Sales
Team.";
msg = msg + newLine;
msg = msg + newLine;
msg = msg + "Please add another record or close the
pop-up list and continue.";
TheApplication().MsgBox(msg ,"Error");
}
*/

intValue = newPosBC.NextRecord();
}

// newPosBC.AllowNotification();
if (noPosAdded )
TheApplication().RaiseErrorText("All the team members are
already added.");

}
else
{
TheApplication().RaiseErrorText("There are no team members for the
person selected");
}
}
catch(e)
{
}
finally
{
posBC.ClearToQuery();
posBC.ExecuteQuery();
accntposBC = null;
accntposBO = null;
newPosBC = null;
posBC = null;
}
}
_______________________________________________________________________
_
Assoc Applet: Team Member Assoc Applet
Assoc BusComp: NetApp CE Position

Script on Assoc Applet :

/********************************************************************
Author: Mohana Jaganathan
This function is written for MOP# 1381146
/********************************************************************/
function WebApplet_PreInvokeMethod (MethodName)
{
try
{
switch(MethodName)
{
case "NAEmp":
{
NetAppEmp();
SetButtonFlags(false, true);

return(CancelOperation);
}

case "NAPartner":
{

var boOpty = TheApplication().ActiveBusObject();


var bcOpty = boOpty.GetBusComp("Opportunity");

var lDistributor = bcOpty.GetFieldValue("Distributor PRM");


var lConsolidator = bcOpty.GetFieldValue("Consolidator
PRM");

var lSearchDCExpr = "";


if(lDistributor != "")

lSearchDCExpr = "([Name] = '" + lDistributor + "'


AND [Channel Partner Type] = 'Distributor')";

if(lConsolidator != "")
{
if(lSearchDCExpr != "")
lSearchDCExpr += " OR ";

lSearchDCExpr += "([Name] = '" + lConsolidator + "'


AND [Channel Partner Type] = 'Consolidator')";
}

var lMyOrgSearchString = "";


if(lSearchDCExpr != "")
lMyOrgSearchString =
GetChannelPartnerIDForMyOrg(lSearchDCExpr);

if(lMyOrgSearchString != "")
lMyOrgSearchString += " OR ";

lMyOrgSearchString += GetPartnersForMyOrg();

if(lMyOrgSearchString == "")
lMyOrgSearchString = "[Id] IS NULL";

GetPositionData(lMyOrgSearchString);

SetButtonFlags(true, false);

bcOpty = null;
boOpty = null;

return(CancelOperation);
}
}

return(ContinueOperation);
}
catch(e)
{
throw(e);
}
}

______________________________________________________________________________
________

/********************************************************************
Author: Mohana Jaganathan
This function is written for MOP# 1381146

/********************************************************************/
function WebApplet_PreCanInvokeMethod (MethodName, &CanInvoke)
{
switch(MethodName)
{
case "NAEmp":
{
if(gNetAppEmp)
CanInvoke = "TRUE";

return(CancelOperation);
}

case "NAPartner":
{
if(gNetAppPartner)
CanInvoke = "TRUE";

return(CancelOperation);
}
}

return(ContinueOperation);
}

______________________________________________________________________________
________
function WebApplet_Load ()
{
this.BusComp().ClearToQuery();

this.BusComp().ActivateField("Active Login Name");

this.BusComp().SetSearchSpec("Active Login Name", " not like *XXX");

this.BusComp().ExecuteQuery();

if(TheApplication().GetProfileAttr("ApplicationName") == "Siebel Sales Enterprise" )


{
var sPosition = TheApplication().GetProfileAttr("Position");
var bExists = sPosition.indexOf("Channel");
if(bExists > 0)
{
this.BusComp().ClearToQuery();

this.BusComp().ActivateField("Active Login Name");

this.BusComp().SetSearchSpec("Active Login Name", " not like *XXX");

this.BusComp().SetViewMode(3); // All

this.BusComp().ExecuteQuery();
}
}
NetAppEmp();
SetButtonFlags(false, true);
}

Declarations :
//Mohana Jaganathan

var gNetAppEmp;
var gNetAppPartner;

______________________________________________________________________________
________

/********************************************************************
Author: Mohana Jaganathan
This function is written for MOP# 1381146
/********************************************************************/
function GetChannelPartnerIDForMyOrg(iSearchExpr)
{
try
{
var boChannelPartner = TheApplication().GetBusObject("Channel Partner");
var bcChannelPartner = boChannelPartner.GetBusComp("Channel Partner");

var oSearchString = "";

bcChannelPartner.ClearToQuery();
bcChannelPartner.SetViewMode(AllView);
bcChannelPartner.SetSearchExpr(iSearchExpr);
bcChannelPartner.ExecuteQuery();

for(var isRec = bcChannelPartner.FirstRecord() ; isRec ; isRec =


bcChannelPartner.NextRecord())
{
var lChannelPartnerID = bcChannelPartner.GetFieldValue("Id");
if(oSearchString != "")
oSearchString += " OR ";

oSearchString += "[Organization Id] = '" + lChannelPartnerID + "'";


}

return(oSearchString);
}
catch(e)
{
throw e;
}
finally
{
bcChannelPartner = null;
boChannelPartner = null
}
}

/********************************************************************
Author: Mohana Jaganathan
This function is written for MOP# 1381146
/********************************************************************/
function GetPartnersForMyOrg()
{
try
{
var boOpty = TheApplication().ActiveBusObject();
var bcAccountOpty = boOpty.GetBusComp("Account Opportunity NetApp");

var oSearchExpr = "";

bcAccountOpty.ClearToQuery();
bcAccountOpty.SetViewMode(AllView);
bcAccountOpty.ActivateField("Opportunity Id")
bcAccountOpty.ActivateField("Account Id");
bcAccountOpty.SetSearchSpec("Opportunity Id",
TheApplication().GetSharedGlobal("gCurrOptyId"));
bcAccountOpty.ExecuteQuery();

for(var isRec = bcAccountOpty.FirstRecord() ; isRec ; isRec =


bcAccountOpty.NextRecord())
{
var lAccountId = bcAccountOpty.GetFieldValue("Account Id");
if(oSearchExpr != "")
oSearchExpr += " OR ";

oSearchExpr += "[Organization Id] = '" + lAccountId + "'";

return(oSearchExpr);
}
catch(e)
{
throw e;
}
finally
{
bcAccountOpty = null;
boOpty = null;
}
}

/********************************************************************
Author: Mohana Jaganathan
This function is written for MOP# 1381146
/********************************************************************/
function GetPositionData(iSearchExpr)
{
try
{
var bcNetAppPosition = this.BusComp();

bcNetAppPosition.ClearToQuery();

bcNetAppPosition.SetViewMode(AllView);

bcNetAppPosition.SetNamedSearch("CECollSearch", iSearchExpr);

bcNetAppPosition.ExecuteQuery();
}
catch (e)
{
throw(e);
}
finally
{
bcNetAppPosition = null;
}
}

/********************************************************************
Author: Mohana Jaganathan
This function is written for MOP# 1381146
/********************************************************************/
function NetAppEmp()
{
var bcNetAppPosition = this.BusComp();

bcNetAppPosition.ClearToQuery();

var sExpr = "[Organization] = 'Default Organization'";


bcNetAppPosition.SetNamedSearch("CECollSearch", sExpr);

bcNetAppPosition.ExecuteQuery();

// Destroying the variables


bcNetAppPosition = null;
}
/********************************************************************
Author: Mohana Jaganathan
This function is written for MOP# 1381146
/********************************************************************/
function SetButtonFlags(iNetAppEmp, iNetAppPartner)
{
gNetAppEmp = iNetAppEmp;
gNetAppPartner = iNetAppPartner;
}