Showing posts with label escript. Show all posts
Showing posts with label escript. Show all posts

Friday, September 5, 2014

CMI Business Services

 

 

Business Service Server Scripts

Parent Business Service
Name
Script

CMI ATP Promised Date BS
GenerateOrderATPPromisedDate
/*************************************************************************************************************************
Created By : David
Created On : 15th Jun 2011
Method Name: function GenerateOrderATPPromisedDate(Inputs, Outputs)
C&I Number: 4460
Requirement #: S120
Functionality: when click the button "Update Requested Date",It would update all line itmes (except Labor,Misc,one Off item) Requested Date from Header Level
Input: NA
Output: NA
************************************************************************************************************************/
function GenerateOrderATPPromisedDate(Inputs, Outputs)
{
try
{
var oBO:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var oActiveBO:BusObject = TheApplication().ActiveBusObject();
if(oActiveBO == null)
{
return;
}
var oActiveOrder:BusComp = oActiveBO.GetBusComp("Order Entry - Orders");
var vOrderId:String = oActiveOrder.GetFieldValue("Id");
var vOrderShipDate:String = oActiveOrder.GetFieldValue("Requested Ship Date");
var oOrderItem:BusComp = oBO.GetBusComp("Order Entry - Line Items");
with(oOrderItem)
{
SetViewMode(AllView);
ActivateField("Id");
ActivateField("Order Header Id");
ActivateField("Due Date");
ClearToQuery();
SetSearchExpr("[Product Type] <> LookupValue ('PRODUCT_TYPE', 'Labor') AND [Product Type] <> LookupValue ('PRODUCT_TYPE', 'Misc') AND [Product Type] <> LookupValue ('PRODUCT_TYPE', 'Flat Rate') AND ([Part Number] <> 'SEBLRSVWIP1' OR [Part Number] IS NULL) AND [Order Header Id] = '"+vOrderId+"'");//This Searchspec is mainly to indicate for which line items the ATP call can be done.
ExecuteQuery(ForwardOnly);
var hasRecord = FirstRecord();
while(hasRecord){
//setFieldValue("Due Date",vOrderShipDate); -- commented and corrected the Syntax for Defect# 106 by JW919 on 09/20/2011
SetFieldValue("Due Date",vOrderShipDate);
WriteRecord();
hasRecord = NextRecord();
}
}
}
catch(e){
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally{
vOrderId = null;
vOrderShipDate = null;
oOrderItem = null;
oActiveBO = null;
oBO = null;
//sOrderItemId = null;
//Added by shanmukh for code clean up 08/26/2011
oActiveOrder = null;
}
}

CMI ATP Promised Date BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//try catch added by shanmukh for code clean up 08/26/2011
try
{
if(MethodName == "GenerateOrderATPPromisedDate"){
GenerateOrderATPPromisedDate(Inputs, Outputs);
//Commented and added the correct method for defect# 106 by JW919 on 09/20/2011
//GenerateQuoteATPPromisedDate(Inputs, Outputs);
//Added the refresh applet code for defect#92 by JW919 on 09/27/2011
TheApplication().GetService("FINS Teller UI Navigation").InvokeMethod("RefreshCurrentApplet",TheApplication().NewPropertySet(), TheApplication().NewPropertySet());
return(CancelOperation);
}
else if(MethodName == "GenerateQuoteATPPromisedDate"){
GenerateQuoteATPPromisedDate(Inputs, Outputs);
//Added the refresh applet code for defect#92 by JW919 on 09/27/2011
// TheApplication().GetService("FINS Teller UI Navigation").InvokeMethod("RefreshCurrentApplet",TheApplication().NewPropertySet(), TheApplication().NewPropertySet());
return(CancelOperation);
}
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}//end of catch
return (ContinueOperation);
}

CMI ATP Promised Date BS
GenerateQuoteATPPromisedDate
/*************************************************************************************************************************
Created By : David
Created On : 15th Jun 2011
Method Name: function GenerateQuoteATPPromisedDate(Inputs, Outputs)
C&I Number: 4460
Requirement #: S120
Functionality: when click the button "Update Requested Date",It would update all line itmes (except Labor,Misc,one Off item) Requested Date from Header Level
Input: NA
Output: NA
************************************************************************************************************************/
function GenerateQuoteATPPromisedDate(Inputs, Outputs)
{
try
{
var oBO:BusObject = TheApplication().GetBusObject("Quote");
var oActiveBO:BusObject = TheApplication().ActiveBusObject();
if(oActiveBO == null)
{
return;
}
var oActiveQuote:BusComp = oActiveBO.GetBusComp("Quote");
var vQuoteId:String = oActiveQuote.GetFieldValue("Id");
var vQuoteShipDate:String = oActiveQuote.GetFieldValue("Requested Ship Date");
var oQuoteItem = oBO.GetBusComp("Quote Item");
with(oQuoteItem)
{
SetViewMode(AllView);
ActivateField("Id");
ActivateField("Quote Id");
ActivateField("Requested Delivery Date");
ClearToQuery();
SetSearchExpr("([CMI NO ATP FLAG]='Y' AND ([Part Number] <> 'SEBLRSVWIP1' OR [Part Number] IS NULL) AND [CMI NO ATP Category Flag] = 'Y') AND ([CMI Main Assembly Flag] <>'Y' OR [CMI Main Assembly Flag] IS NULL) AND [Quote Id] = '"+vQuoteId+"'");//This Searchspec is mainly to indicate for which line items the ATP call can be done.
ExecuteQuery(ForwardOnly);
var hasRecord = FirstRecord();
while(hasRecord){
//setFieldValue("Due Date",vOrderShipDate); -- commented and corrected the Syntax for Defect# 106 by JW919 on 09/20/2011
SetFieldValue("Requested Delivery Date", vQuoteShipDate);
WriteRecord();
hasRecord = NextRecord();
}
}
}
catch(e){
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally{
vQuoteId = null;
vQuoteShipDate = null;
oQuoteItem = null;
oActiveBO = null;
oBO = null;
//sQuoteItemId = null; -- commented as this variable is not declared by JW919 on 09/18/2011
//Added by shanmukh for code clean up 08/26/2011
oActiveQuote = null;
}
}

CMI Action Common BS
ConcatTechName
/*
Created By : JF344
Created On : 15-Feb-2011
C&I Number : 4468
Requirement # :
Method Name: ConcatTechName
Functionality:
Input: None
Output: None
Customization Approval #: NA
*/
function ConcatTechName(Inputs, Outputs)
{
try
{
var sName = "";
var sSRId = Inputs.GetProperty("SRId");
Outputs.SetProperty("CatName","");
if(sSRId != "") return;//MODIFIED BY SAURABH
//contact tech name for those type = Service Labor, status <> Unscheduled, Sceduled, Completed, Done, Cancelled
var bo =TheApplication().GetBusObject("Action");
var bc = bo.GetBusComp("Action");
with (bc)
{ //
ClearToQuery();
SetViewMode(AllView);
var sExpr = "[Activity SR Id] = '"+sSRId+"' AND [Type] = '"+ TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Service Labor")
+ "' AND [Status] <> '" + TheApplication().InvokeMethod("LookupValue","EVENT_STATUS", "Unscheduled")
+ "' AND [Status] <> '" + TheApplication().InvokeMethod("LookupValue","EVENT_STATUS", "Scheduled")
+ "' AND [Status] <> '" + TheApplication().InvokeMethod("LookupValue","EVENT_STATUS", "Completed")
+ "' AND [Status] <> '" + TheApplication().InvokeMethod("LookupValue","EVENT_STATUS", "Done")
+ "' AND [Status] <> '" + TheApplication().InvokeMethod("LookupValue","EVENT_STATUS", "Cancelled")
+"'";
SetSearchExpr(sExpr);
ExecuteQuery(ForwardOnly);
var bHasRecord = FirstRecord();
while(bHasRecord)
{
var sTempName = GetFieldValue("CMI Owner FullName");
if(sTempName != "")
{
if(sName == "")
sName = sTempName
else
sName = sName +"; "+ sTempName;
}
bHasRecord = NextRecord();
}
Outputs.SetProperty("CatName", sName);
}
}
catch(e)
{
throw e;//the throw statement added by saurabh
//var err = e.toString();
}
finally
{
bc = null;
bo = null;
}
}

CMI Action Common BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//Try catch added by shanmukh for code clean up on 08/20/2011
try
{
if(MethodName == "ConcatTechName")
{
ConcatTechName(Inputs, Outputs);
return CancelOperation;
}
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}//end of catch
return (ContinueOperation);
}

CMI Activity Creation Sales BS
(declarations)
var sQuoteId;

CMI Activity Creation Sales BS
CreateActivity
function CreateActivity(sQuoteId)
{
try {
TheApplication().Utility.logStack("CreateActivity", this);
var oBO = TheApplication().GetBusObject("Quote");
var oBCAction = oBO.GetBusComp("Action (Quote Order)");//JQ486:Added Correct BC
var oBCQuote = oBO.GetBusComp("Quote");
var serviceQuote = TheApplication().InvokeMethod("LookupValue", "QUOTE_TYPE", "Service Quote");//JW918 07.04.11.Defect#490
var sActType = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Quote Follow-up");
var actCategory = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "General");
var sStatus = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "In Progress");
var sDoneStatus = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Done");
var sCalcVar;//JQ486:Declared New Variable
var OwnerName;//JQ486:05Jan2011, Added Script.
var sSalesRepPickBC;//JQ486:05Jan2011, Added Script.
var ldCurrDate;//JW918 07.04.11.Defect 490
var lsCurrDate;
var sActionId = "";
with(oBCQuote) {
SetViewMode(AllView);
ActivateField("CMI Status As Of Date Calc");
ActivateField("Quote Display Type");
ActivateField("Sales Team");
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardBackward);
if(FirstRecord()) {
var quoteType = GetFieldValue("Quote Display Type");
sCalcVar = GetFieldValue("CMI Status As Of Date Calc");//JQ486:Getting the Calculated Value
OwnerName = GetFieldValue("Sales Team");//JQ486:05Jan2011, Added Script.
oBCAction.ActivateField("Type");
oBCAction.ActivateField("Planned");
oBCAction.ActivateField("Primary Owner Id");//JQ486:05Jan2011, Added Script.
oBCAction.ActivateField("CMI Owner FullName");
oBCAction.ActivateField("Due");
oBCAction.SetViewMode(AllView);
oBCAction.ClearToQuery();
oBCAction.SetSearchSpec("Type", "Quote Follow-up");
oBCAction.SetSearchSpec("Status", "<>'"+sDoneStatus+"'");
oBCAction.ExecuteQuery();
var activityFound = oBCAction.FirstRecord();
TheApplication().Utility.logVars("Quote ("+sQuoteId+") Type", quoteType, "Open Follow-up Activity Found?", activityFound);
while(activityFound) {
oBCAction.SetFieldValue("Status",sDoneStatus);
oBCAction.WriteRecord();
activityFound = oBCAction.NextRecord();
}
oBCAction.NewRecord(NewAfter);
oBCAction.SetFieldValue("Category",actCategory);//MJB 11/7/12 INC000003660351 Set first as Type is constrained by this value
oBCAction.SetFieldValue("Type",sActType);//JQ486:Setting Type Value
oBCAction.SetFieldValue("Planned",sCalcVar);//JQ486:Setting Started ValuesTemplatePickBC = oBCActivityPlan.GetPicklistBusComp("Template");
oBCAction.SetFieldValue("Status", sStatus);
TheApplication().Utility.logVars("Quote ("+sQuoteId+") Type", quoteType);
ldCurrDate = new Date();
if(quoteType == serviceQuote) {
ldCurrDate.setDate(ldCurrDate+2);
} else {
ldCurrDate.setDate(ldCurrDate+7);
}
lsCurrDate = TheApplication().Utility.DateToString(ldCurrDate);
oBCAction.SetFieldValue("Due",lsCurrDate);
oBCAction.WriteRecord();
TheApplication().Utility.logVars("Owner Name", OwnerName);
sSalesRepPickBC = oBCAction.GetPicklistBusComp("Primary Owner Id"); //cq8171 Use field w/ Pick w/ All Visibility
sSalesRepPickBC.SetViewMode(AllView);
sSalesRepPickBC.ClearToQuery();
sSalesRepPickBC.SetSearchSpec("Login Name",OwnerName);
sSalesRepPickBC.ExecuteQuery(ForwardOnly);
var isPickBCRec = sSalesRepPickBC.FirstRecord();
TheApplication().Utility.logVars("Owner found?", isPickBCRec);
if(isPickBCRec) {
sSalesRepPickBC.Pick();
}
oBCAction.WriteRecord();
sActionId = oBCAction.GetFieldValue("Id");
} //end of else
var boActive = TheApplication().ActiveBusObject();
if (boActive.Name() == "Quote") {
var bcActive = boActive.GetBusComp("Action");
bcActive.InvokeMethod("RefreshBusComp");
}
} //end of with (oBCQuote)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcActive = null;
boActive = null;
sSalesRepPickBC = null;
sActType = null;
oBCAction = null;
sQuoteId = null;
oBCQuote = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Activity Creation Sales BS
MailToOwner
//function MailToOwner(Inputs, Outputs)
function MailToOwner(sActionId)
{
try {
/* var context_string = Inputs.GetProperty("Context");
var context_array = context_string.split(", ");
var sProfile = context_array[1];
sProfile = sProfile.replace(/\"/g,'');
if(sProfile == "") sProfile = "DBUNextGen_Dev";
var sPackageList = context_array[3];
sPackageList = sPackageList.replace(/\"/g,'');
if(sPackageList == "") sPackageList = "CMI Parts Quote Approval Notification";*/
var sProfile = "DBUNextGen_Dev";
var sPackageList = "CMI Follow Up Activity Email";
// var sActionId = TheApplication().GetProfileAttr("CMIFollowupActionId");
if(sActionId == "") return;
var bs = TheApplication().GetService("Outbound Communications Manager");
var psIn = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();
psIn.SetProperty("RecipientGroup","CMI Activity Owner");
psIn.SetProperty("CommProfileOverride",sProfile);
psIn.SetProperty("SourceIdList",sActionId);
psIn.SetProperty("PackageNameList",sPackageList);
bs.InvokeMethod("CreateRequest", psIn, psOut);
}
catch(e)
{
var a=e.toString();
}
finally
{
bs = null;
psIn = null;
psOut= null;
}
}

CMI Activity Creation Sales BS
SearchFolloUpActivity
function SearchFolloUpActivity()
{
/****************************************************************************************************
Created By : Sujay Patil(JW918)
Created On : 11 April 2011
Requirement # : followup activity
Functionality: This BS method will be triggered on through a repeating component job.
It will search for all the activities with Type = Quote Follow up and Follow Up date= today.
For the returned activities,it will send the Email.
**********************************************************************************************************/
try {
var sActBo = TheApplication().GetBusObject("Action");
var sActBC = sActBo.GetBusComp("Action");
var lsType = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Quote Follow-up");
var lsStatus = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Done");
var ldcurrtm = Clib.localtime(Clib.time());
var lsmonth = ldcurrtm.tm_mon + 1;
var lsyear = ldcurrtm.tm_year + 1900;
var lsday = ldcurrtm.tm_mday;
var lsCurrentStDate = lsmonth + '/' + lsday + '/' + lsyear + ' ' + "00" + ':' + "00" + ':' + "01";
var lsCurrentEndDate = lsmonth + '/' + lsday + '/' + lsyear + ' ' + "23" + ':' + "59" + ':' + "59";
var lsExpr = "[Type]= '" + lsType + "' AND [Due] >= '" + lsCurrentStDate + "' AND [Due] <= '" + lsCurrentEndDate + "' AND [Status] <> '" + lsStatus + "' AND [Time Sheet Related Flag] = 'N'";
with(sActBC) {
ActivateField("Due");
ActivateField("Time Sheet Related Flag");
SetViewMode(AllView);
ClearToQuery()
SetSearchExpr(lsExpr);
ExecuteQuery();
var lsRecord = FirstRecord();
while(lsRecord) {
var lsDueDate = GetFieldValue("Due");
var lsId = GetFieldValue("Id");
MailToOwner(lsId);
SetFieldValue("Time Sheet Related Flag","Y");
lsRecord = NextRecord();
}
}
} catch(e) {
throw(e);
} finally {
sActBC = null;
sActBo = null;
}
}

CMI Activity Creation Sales BS
SendEmail
function SendEmail(Inputs,Outputs)
{
try {
var context_string = Inputs.GetProperty("Context");
var context_array = context_string.split(", ");
var sProfile = context_array[1];
sProfile = sProfile.replace(/\"/g,'');
if(sProfile == "") sProfile = "DBUNextGen_Dev";
var sPackageList = context_array[3];
sPackageList = sPackageList.replace(/\"/g,'');
if(sPackageList == "") sPackageList = "CMI Follow Up Activity Email";
//sProfile = "DBUNextGen_Dev";
//var sPackageList = "CMI Follow Up Activity Email";
var sActionId = TheApplication().GetProfileAttr("CMIFollowupActionId");
if(sActionId == "") return;
var bs = TheApplication().GetService("Outbound Communications Manager");
var psIn = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();
psIn.SetProperty("RecipientGroup","CMI Activity Owner");
psIn.SetProperty("CommProfileOverride",sProfile);
psIn.SetProperty("SourceIdList",sActionId);
psIn.SetProperty("PackageNameList",sPackageList);
bs.InvokeMethod("CreateRequest", psIn, psOut);
}
catch(e)
{
var a=e.toString();
}
finally
{
bs = null;
psIn = null;
psOut= null;
}
}

CMI Activity Creation Sales BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//Add try catch by jw920 on 18/8/2011
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retValue = CancelOperation;
switch(MethodName) {
case "CreateQuote":
sQuoteId = TheApplication().GetProfileAttr("Quote Id");
CreateActivity(sQuoteId);
break;
case "MailToOwner":
MailToOwner(Inputs, Outputs);
break;
case "SearchFolloUpActivity":
SearchFolloUpActivity(Inputs, Outputs);
break;
case "UpdateFollowUpActivity":
UpdateFollowUpActivity();
break;
case "SendEmail":
SendEmail(Inputs,Outputs);
break;
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retValue);
}
return (retValue);
}

CMI Activity Creation Sales BS
UpdateFollowUpActivity
function UpdateFollowUpActivity()
{
//***************************************************************************
// Author: Sujay Patil
// Date Created: 07.04.2011
// Purpose: This functions updates the Activity status to Done once
// Quote status gets udated to 'Accepted'
//****************************************************************************
try {
TheApplication().Utility.logStack("UpdateFollowUpActivity", this);
var lsAccQuoteId = TheApplication().GetProfileAttr("CMI AccQuote Id");
var lsType = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Quote Follow-up");
var lsStatus = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Done");
var loQuoteBo = TheApplication().GetBusObject("Quote");
var loActBC = loQuoteBo.GetBusComp("Action (Quote Order)");
with(loActBC) {
SetViewMode(AllView);
ClearToQuery()
SetSearchSpec("Quote Id",lsAccQuoteId);
SetSearchSpec("Type", lsType);
SetSearchSpec("Status", "<>" + "'" + lsStatus + "'");
ExecuteQuery(ForwardOnly);
//CMI DBU Rel#1, Defect# 3968, Script: commented the old code which updates only first record
//Added the code to update all open Quote Followup activities to done status by JW919 on 01/18/2012
var HasRecord = FirstRecord();
while(HasRecord) {
SetFieldValue("Status",lsStatus);
WriteRecord();
HasRecord = NextRecord();
}
}
TheApplication().SetProfileAttr("CMI AccQuote Id","");
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
loActBC = null;
loQuoteBo = null;
TheApplication().Utility.logUnstack();
}
}

CMI Add CD-EM Products
DeleteAllCDEM
function DeleteAllCDEM(lineBC)
{
/*******************************************************************************************
Created By : JW918
Created On : 15.09.2011
C&I Number : 4462 .Enhancement# S041
Functionality: This function deletes the unnecessary CD-EM products.
Enhancement#S041
**********************************************************************************************/
try {
TheApplication().Utility.logStack("DeleteAllCDEM", this);
var sCD = TheApplication().InvokeMethod("LookupValue","CMI_CD_EM","Customer Down");
var sEM = TheApplication().InvokeMethod("LookupValue","CMI_CD_EM","Economy");
//CMI DBU relase#1, C&I 4462, Config: BC changed to Quote Item (Simple) to avoid trigerring RTE on DeleteRecord by JW919 on 12/19/2011
//oQuoteItemBC = oQuoteBO.GetBusComp("Quote Item");
with(lineBC) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Product", "'"+sCD+"' OR '"+sEM+"'");
ExecuteQuery(ForwardBackward);
while(FirstRecord()) {
DeleteRecord();
}
//Refresh the quote since lines have been deleted
ClearToQuery();
ExecuteQuery(ForwardBackward);
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
}

CMI Add CD-EM Products
AddCD_EMProducts
function AddCD_EMProducts(Inputs,Outputs)
{
/*******************************************************************************************
Created By : Sujay Patil(JW918)
Created On : 15.09.2011
C&I Number : 4462 .Enhancement# S041
Functionality: This business service gets triggers when user clicks on Apply Special Charges button on Quote/Order Line item to create the CD/EM Quote Line item.
Enhancement#S041
**********************************************************************************************/
try {
TheApplication().Utility.logStack("AddCD_EMProducts", this);
var sQuoteId:String = Inputs.GetProperty("Id");
var specialCharges:String;
var spcCustDown = TheApplication().InvokeMethod("LookupValue","CMI_CD_EM","Customer Down");
var spcEconomy = TheApplication().InvokeMethod("LookupValue","CMI_CD_EM","Economy");
var uomEach = TheApplication().InvokeMethod("LookupValue","UNIT_OF_MEASURE","Each");
var lineTypeBillOnly = TheApplication().InvokeMethod("LookupValue","CMI_LINE_TYPE","Bill Only");
var freight= TheApplication().InvokeMethod("LookupValue", "CMI_SUB_TYPE_LOV", "Freight");
var lineTypeCleanCore = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type");
var lineTypeDirtyCore = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type");
var countCD=0;//:Number = 0;
var countEC=0;//:Number = 0;
var countNorm=0;//Number = 0;
var boQuote:BusObject;
var bcQuote:BusComp;
var bcQuoteItem:BusComp;
var sQuoteItemId;//:String; //Removed the Strong typeing as If condition was failing.
var countTotal = 0;//:Number = 0;
var countParentCD = 0;//Removed the Strong typing as If condition was failing.
var countParentEC = 0;//Removed the Strong typing as If condition was failing.
var countChildCD:Number = 0;
var countChildEC:Number = 0;
var parentCDId;//:String;//Removed the Strong typing as If condition was failing.
var parentECId:String;
var childCDId:String;
var childECId:String;
var childECIdList="";
var childCDIdList="";
var prodCD:String = GetDummyProduct(spcCustDown);
var prodEC:String = GetDummyProduct(spcEconomy);
var searchExpr:String = "";
if(prodCD == "" || prodEC == "" || prodCD == null || prodEC == null) {
TheApplication().RaiseErrorText("The products named "+spcCustDown+" / "+spcEconomy+" do not exist. Kindly contact the Administrator to create the products and try again.");
}
boQuote = TheApplication().GetBusObject("Quote");
bcQuote = boQuote.GetBusComp("Quote");
bcQuoteItem = boQuote.GetBusComp("Quote Item (Simple)");
with(bcQuote) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sQuoteId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logId("Quote", sQuoteId);
TheApplication().Utility.logVars("Quote ("+sQuoteId+") found?", FirstRecord());
if(FirstRecord()) {
searchExpr = "([CMI Line Type]<>'"+lineTypeCleanCore+"' OR [CMI Line Type]<>'"+lineTypeDirtyCore+"' OR [CMI Line Type] IS NULL OR [CMI Product Sub Type]<>'"+freight+"' OR [CMI Product Sub Type] IS NULL)"
//Query on QI to check the Special Charges field.
with(bcQuoteItem) {
ActivateField("CMI Special Charges");
ActivateField("CMI Line Type"); //CQ: 6107 kw920 Dt.4/4/12
ActivateField("CMI Fulfillment Set Id"); //CQ: 2934 Dt.06/19/12
ActivateField("CMI Fulfillment Set");
ActivateField("Parent Quote Item Id");
ActivateField("Root Quote Item Id");
ActivateField("CMI Parent Special Charges");
ActivateField("CMI Unit of Measure");
ActivateField("Product");
ActivateField("Product Id");
//CQ#8943 Added by LC657
ActivateField("CMI Root Fulfilment Set Id");
ClearToQuery();
SetViewMode(AllView);
SetSearchExpr(searchExpr);
ExecuteQuery(ForwardBackward);
//Count and categorize existing special charge settings on all quote items for this quote
var isRecord = FirstRecord();
while(isRecord) {
specialCharges = GetFieldValue("CMI Special Charges");
var sParQuoteItId = GetFieldValue("Parent Quote Item Id");
var sProduct = GetFieldValue("Product");
if(specialCharges == spcCustDown) {
countCD = countCD +1;
} else if(specialCharges == spcEconomy) {
countEC = countEC +1;
} else if(specialCharges == "" && sParQuoteItId == "" && sProduct != spcCustDown && sProduct != spcEconomy) {
countNorm = countNorm+1;
}
//Total lines that a special charge is Eligible for regardless of whether one is applied
if(specialCharges == spcCustDown || specialCharges == spcEconomy || (specialCharges == "" && sParQuoteItId == "" && sProduct != spcCustDown && sProduct != spcEconomy)) {
countTotal = countTotal + 1;
}
//Count non charge Parent lines where a special charge has been specified
if(sProduct == spcCustDown && sParQuoteItId == "") {
countParentCD = countParentCD + 1;
parentCDId = GetFieldValue("Id");
} else if(sProduct == spcEconomy && sParQuoteItId == "") {
countParentEC = countParentEC + 1;
parentECId = GetFieldValue("Id");
}
//Count child special charges lines
if(sProduct == spcCustDown && sParQuoteItId != "") {
countChildCD = countChildCD + 1;
childCDId = GetFieldValue("Parent Quote Item Id");
childCDIdList = childCDIdList + " OR " + childCDId;
} else if(sProduct == spcEconomy && sParQuoteItId != "") {
countChildEC = countChildEC + 1;
childECId = GetFieldValue("Parent Quote Item Id");
childECIdList = childECIdList + " OR " + childECId;
}
isRecord = NextRecord();
}//End of while isRecord
TheApplication().Utility.logStep("Total Items (Cust Down/Economy/Neither): "+countTotal+"("+countCD+" / "+countEC+" / "+countNorm+")");
TheApplication().Utility.logStep("Parent CD / Parent Econ / Child CD / Child Econ: "+countParentCD+" / "+countParentEC+" / "+countChildCD+" / "+countChildEC);
//If there are no charges needed any longer, remove them all
if(countCD==0 && countEC==0 && countNorm==countTotal) {
DeleteAllCDEM(bcQuoteItem);
//If all lines are Customer Down, there is not a parent level Customer Down product, and there are no Non special charge lines
} else if(countTotal == countCD && countParentCD == 0 && countNorm == 0) {
//There might be an old parent level Economy charge which needs to be removed. Also remove child child charges
//as a single parent level charge will be created
if(countParentEC >0 || countChildCD > 0 || countChildEC >0) {
DeleteAllCDEM(bcQuoteItem);
}
//var sFulfillmentSetNumber = GetDefaultFulfilmentSet(bcQuoteItem);
LastRecord();
NewRecord(NewAfter);
SetFieldValue("Product Id",prodCD);
SetFieldValue("CMI Unit of Measure", "Each");
SetFieldValue("CMI Line Type",lineTypeBillOnly); //CQ: 6107 kw920 Dt.4/4/12
var oBCPick = GetPicklistBusComp("CMI Fulfillment Set");
with (oBCPick)
{
ClearToQuery();
SetSearchSpec("CMI Fulfillment Set", "1");
ExecuteQuery(ForwardOnly);
if (FirstRecord())
Pick();
}
oBCPick = null;
WriteRecord();
//If all lines are Economy, there is not a parent level Economy product, and there are no Non special charge lines
} else if(countTotal == countEC && countParentEC ==0 && countNorm == 0) {
//There might be an old parent level Customer Down charge which needs to be removed. Also remove child child charges
//as a single parent level charge will be created
if(countParentCD >0 || countChildCD > 0 || countChildEC >0) {
DeleteAllCDEM(bcQuoteItem);
}
LastRecord();
NewRecord(NewAfter);
SetFieldValue("Product Id",prodEC);
SetFieldValue("CMI Unit of Measure", "Each");
SetFieldValue("CMI Line Type",lineTypeBillOnly); //CQ: 6107 kw920 Dt.4/4/12
//SetFieldValue("CMI Fulfillment Set",1); // CQ8943 LC657
var oBCPick = GetPicklistBusComp("CMI Fulfillment Set");
with (oBCPick)
{
ClearToQuery();
SetSearchSpec("CMI Fulfillment Set", "1");
ExecuteQuery(ForwardOnly);
if (FirstRecord())
Pick();
}
oBCPick = null;
WriteRecord();
//If there are Some Customer Down charges or Some Economy charges but not all lines are one or the other charges
//must be created as child lines
} else if((countCD>0 && countTotal > countCD) || (countEC >0 && countTotal > countEC)) {
//When child lines are added, if the line number is not specified, it will use hierarchical notation (1.1) by default
//This notation is not desireable when passing data to EBS so instead, query to get the max sequence and add 1 to it
var iSequence:Number = 0;
var boQuote2:BusObject = TheApplication().GetBusObject("Quote");
var bcQuoteItem2 = boQuote2.GetBusComp("Quote Item (Simple)");
with(bcQuoteItem2) {
ActivateField("Line Number");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Quote Id", sQuoteId);
SetSortSpec("Line Number (DESC)");
ExecuteQuery(ForwardBackward);
isRecord = FirstRecord();
if (isRecord) iSequence = ToNumber(GetFieldValue("Line Number"));
}
var sRecord = FirstRecord();
while(sRecord) {
specialCharges = GetFieldValue("CMI Special Charges");
sQuoteItemId = GetFieldValue("Id");
var sParQIId = GetFieldValue("Parent Quote Item Id");
var sProdId = GetFieldValue("Product");
var sParSpeCharges = GetFieldValue("CMI Parent Special Charges");
var sChildCDExist:Number = childCDIdList.indexOf(sQuoteItemId);
var sChildCDExist1:Number = childCDIdList.indexOf(sParQIId);
var sChildEMExist:Number = childECIdList.indexOf(sQuoteItemId);
var sChildEMExist1:Number = childECIdList.indexOf(sParQIId);
//CQ#8943 Added by LC657
var sRootFulfilmentId = GetFieldValue("CMI Root Fulfilment Set Id");
//Existing special charge child but the parent is now blank so need to delete the child charge
if((sProdId == spcCustDown || sProdId == spcEconomy) && sParSpeCharges == "") {// && sChildCDExist1 == -1)
TheApplication().Utility.logStep("Process Child "+sProdId+" with Parent charge: "+sParSpeCharges);
DeleteRecord();
sRecord=PreviousRecord();
//Existing Customer Down child but the parent is now Economy so need to delete the child charge and create new
} else if(sProdId == spcCustDown && sParSpeCharges == spcEconomy) {// && sChildCDExist1 == -1)
TheApplication().Utility.logStep("Process Child "+sProdId+" with Parent charge: "+sParSpeCharges+" - New Line: "+iSequence);
DeleteRecord();
sRecord=PreviousRecord();
NewRecord(NewAfter);
iSequence += 1;
SetFieldValue("Line Number", iSequence);
SetFieldValue("Product Id",prodEC);
SetFieldValue("Parent Quote Item Id", sParQIId);
SetFieldValue("Root Quote Item Id", sParQIId);
//SetFieldValue("CMI Fulfillment Set Id", sParQIId);//CQ 2934 kw920
SetFieldValue("CMI Fulfillment Set Id",sRootFulfilmentId); //CQ8943 LC657
SetFieldValue("CMI Unit of Measure", uomEach);
SetFieldValue("CMI Line Type",lineTypeBillOnly); //CQ: 6107 kw920 Dt.4/4/12
WriteRecord();
//Existing Economy child but the parent is now Customer Down so need to delete the child charge and create new
} else if(sProdId == spcEconomy && sParSpeCharges == spcCustDown) {// && sChildCDExist1 > 0 && sChildEMExist1 == -1)
TheApplication().Utility.logStep("Process Child "+sProdId+" with Parent charge: "+sParSpeCharges+" - New Line: "+iSequence);
DeleteRecord();
sRecord=PreviousRecord();
NewRecord(NewAfter);
iSequence += 1;
SetFieldValue("Line Number", iSequence);
SetFieldValue("Product Id",prodCD);
SetFieldValue("Parent Quote Item Id", sParQIId);
SetFieldValue("Root Quote Item Id", sParQIId);
//SetFieldValue("CMI Fulfillment Set Id", sParQIId);// CQ:2934
SetFieldValue("CMI Fulfillment Set Id",sRootFulfilmentId); // CQ8943 LC657
SetFieldValue("CMI Unit of Measure", uomEach);
SetFieldValue("CMI Line Type",lineTypeBillOnly); //CQ: 6107 kw920 Dt.4/4/12
WriteRecord();
//Line needs a Customer Down charge and there are no child charges
} else if(specialCharges == spcCustDown && sChildCDExist == -1 && sChildEMExist == -1) {
TheApplication().Utility.logStep("Process Parent "+sProdId+" with charge: "+spcCustDown+" - New Line: "+iSequence);
//Create the Child Line item with product- Customer Down;
NewRecord(NewAfter);
iSequence += 1;
SetFieldValue("Line Number", iSequence);
SetFieldValue("Product Id",prodCD);
SetFieldValue("Parent Quote Item Id", sQuoteItemId);
SetFieldValue("Root Quote Item Id", sQuoteItemId);
//SetFieldValue("CMI Fulfillment Set Id", sQuoteItemId);//CQ2934
SetFieldValue("CMI Fulfillment Set Id", sRootFulfilmentId);//CQ8943 LC657
SetFieldValue("CMI Unit of Measure", uomEach);
SetFieldValue("CMI Line Type",lineTypeBillOnly); //CQ: 6107 kw920 Dt.4/4/12
WriteRecord();
//Line needs an Economy charge and there are no child charges
} else if(specialCharges == spcEconomy && sChildEMExist == -1 && sChildCDExist == -1) {
TheApplication().Utility.logStep("Process Parent "+sProdId+" with charge: "+spcCustDown+" - New Line: "+iSequence);
//Create the Child Line item with product- Economy;
NewRecord(NewAfter);
SetFieldValue("Product Id",prodEC);
iSequence += 1;
SetFieldValue("Line Number", iSequence);
SetFieldValue("Parent Quote Item Id", sQuoteItemId);
SetFieldValue("Root Quote Item Id", sQuoteItemId);
//SetFieldValue("CMI Fulfillment Set Id", sQuoteItemId);//CQ:2934
SetFieldValue("CMI Fulfillment Set Id", sRootFulfilmentId);//CQ8943 LC657
SetFieldValue("CMI Unit of Measure", uomEach);
SetFieldValue("CMI Line Type",lineTypeBillOnly); //CQ: 6107 kw920 Dt.4/4/12
WriteRecord();
}
//Delete the Parent level charge since all charges will be child lines
if(parentCDId == sQuoteItemId || parentECId == sQuoteItemId) {
DeleteRecord();
} else sRecord = NextRecord();
}//end of while(FirstRecord())
}//end of else if
} //end of with(bcQuoteItem)
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcQuoteItem2 = null;
boQuote2 = null;
bcQuoteItem = null;
bcQuote = null;
boQuote = null;
TheApplication().Utility.logUnstack();
}
}

CMI Add CD-EM Products
GetDefaultFulfilmentSet
function GetDefaultFulfilmentSet()
{
bcQuoteItem.GetPickListBusComp("CMI Fulfillment Set");
}

CMI Add CD-EM Products
GetDummyProduct
function GetDummyProduct(aDummyProduct)
{
/*******************************************************************************************
Created By : JW918
Created On : 15.09.2011
C&I Number : 4462 .Enhancement# S041
Functionality: This function gets the Customer Down & Economy products.
Enhancement#S041
**********************************************************************************************/
try {
TheApplication().Utility.logStack("GetDummyProduct", this);
var sProductId:String = "";
var oProductBO:BusObject = TheApplication().GetBusObject("Admin ISS Product Definition");
var oProductBC:BusComp = oProductBO.GetBusComp("Internal Product - ISS Admin");
with(oProductBC) {
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Name", aDummyProduct);
ExecuteQuery(ForwardOnly);
var PHasRecord = FirstRecord();
if(PHasRecord) {
sProductId = GetFieldValue("Id");
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oProductBC = null;
oProductBO = null;
TheApplication().Utility.logUnstack(sProductId);
}
return(sProductId);
}

CMI Add CD-EM Products
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var sRefreshIP;
switch (MethodName) {
case "AddCD_EMProducts":
TheApplication().ActiveBusObject().GetBusComp("Quote Item").WriteRecord();
AddCD_EMProducts(Inputs, Outputs);
// Defect 883 : To refresh the view (basically Quote BC) to avoid Selected Record error by KM101 on 12/12/2011
sRefreshIP = TheApplication().NewPropertySet();
sRefreshIP.SetProperty("Refresh All", "Y");
// AddCD_EMProducts(Inputs, Outputs);
TheApplication().GetService("FINS Teller UI Navigation").InvokeMethod("RefreshCurrentApplet", sRefreshIP, TheApplication().NewPropertySet());
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sRefreshIP = null;
TheApplication().Utility.logUnstack();
}
return (CancelOperation);
}

CMI Add CD-EM Products-Order
AddCD_EMProducts
function AddCD_EMProducts(Inputs,Outputs)
{
/*******************************************************************************************
Created By : Sujay Patil(JW918)
Created On : 15.09.2011
C&I Number : 4462 .Enhancement# S041
Functionality: This business service gets triggers when user clicks on Apply Special Charges button on Order/Order Line item to create the CD/EM Order Line item.
Enhancement#S041
**********************************************************************************************/
try
{
var sOrderId:String = Inputs.GetProperty("Id");
var sEntity:String = Inputs.GetProperty("Entity");
var sSpecialCharges:String;
var sCD = TheApplication().InvokeMethod("LookupValue","CMI_CD_EM","Customer Down");
var sEM = TheApplication().InvokeMethod("LookupValue","CMI_CD_EM","Economy");
var sFreightType= TheApplication().InvokeMethod("LookupValue", "CMI_SUB_TYPE_LOV", "Freight");
var sCleanCore = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type");
var sDirtyCore = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type");
var i=0;//:Number = 0;
var j=0;//:Number = 0;
var k=0;//Number = 0;
var oOrderBO:BusObject;//:BusObject;
var oOrderBC:BusComp;//:BusComp;
var oOrderItemBC:BusComp;//:BusComp;
var sCDProduct:String;
var sEMProduct:String;
var sLineNum:Number;
var sOrderItemId;//:String; //Removed the Strong typeing as If condition was failing.
var sTotalCount = 0;//:Number = 0;
var sParentCDCount = 0;//Removed the Strong typeing as If condition was failing.
var sParentEMCount = 0;//Removed the Strong typeing as If condition was failing.
var sChildCDCount:Number = 0;
var sChildEMCount:Number = 0;
var sParentCDId;//:String;//Removed the Strong typeing as If condition was failing.
var sParentEMId:String;
var sChildCDId:String;
var sChildEMId:String;
var sChildEMIdList="";
var sChildCDIdList="";
sCDProduct = GetDummyProduct(sCD);
sEMProduct = GetDummyProduct(sEM);
if(sCDProduct == "" || sEMProduct == "" || sCDProduct == null || sEMProduct == null)
{
TheApplication().RaiseErrorText("The products named "+sCD+" / "+sEM+" does not exist. Kindly contact the Administrator to create the products and try again.");
}
oOrderBO = TheApplication().GetBusObject("Order Entry (Sales)");
var oOrderBO_new:BusObject = TheApplication().ActiveBusObject();
//oOrderBC = oOrderBO.GetBusComp("Order");
//oOrderItemBC = oOrderBO.GetBusComp("Order Item");
//oOrderItemBC = oOrderBO.GetBusComp("Order Entry - Line Items");
oOrderItemBC = oOrderBO.GetBusComp("Order Entry - Line Items (Simple)");
var oOrderItemBC_new:BusComp = oOrderBO_new.GetBusComp("Order Entry - Line Items");
var oProdBC:BusComp;
//Query on QI to check the Special Charges field.
with(oOrderItemBC)
{
ActivateField("CMI Special Charges");
ActivateField("CMI Parent Special Charges");
ActivateField("Due Date");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Order Header Id", "='"+sOrderId+"' AND ([CMI Line Type]<>'"+sCleanCore+"' OR [CMI Line Type]<>'"+sDirtyCore+"' OR [CMI Line Type] IS NULL OR [CMI Product Sub Type]<>'"+sFreightType+"' OR [CMI Product Sub Type] IS NULL)");
//SetSearchSpec("Order Id", sOrderId);
ExecuteQuery();
var isRecord = FirstRecord();
while(isRecord)
{
sSpecialCharges = GetFieldValue("CMI Special Charges");
var sParOrderItId = GetFieldValue("Parent Order Item Id");
var sProduct = GetFieldValue("Product");
//sLineNum = GetFieldValue("Line Number");
if(sSpecialCharges == sCD)
{
i = i +1;
}
else if(sSpecialCharges == sEM)
{
j = j +1;
}
else if(sSpecialCharges == "" && sParOrderItId == "" && sProduct != sCD && sProduct != sEM)
{
k = k+1;
}
if(sSpecialCharges == sCD || sSpecialCharges == sEM || (sSpecialCharges == "" && sParOrderItId == "" && sProduct != sCD && sProduct != sEM))
{
sTotalCount = sTotalCount + 1;
}
if(sProduct == sCD && sParOrderItId == "")
{
sParentCDCount = sParentCDCount + 1;
sParentCDId = GetFieldValue("Id");
}
else if(sProduct == sEM && sParOrderItId == "")
{
sParentEMCount = sParentEMCount + 1;
sParentEMId = GetFieldValue("Id");
}
if(sProduct == sCD && sParOrderItId != "")
{
sChildCDCount = sChildCDCount + 1;
sChildCDId = GetFieldValue("Parent Order Item Id");
sChildCDIdList = sChildCDIdList + "OR" + sChildCDId;
}
else if(sProduct == sEM && sParOrderItId != "")
{
sChildEMCount = sChildEMCount + 1;
sChildEMId = GetFieldValue("Parent Order Item Id");
sChildEMIdList = sChildEMIdList + "OR" + sChildEMId;
}
isRecord = NextRecord();
}//End of while isRecord
//Get the Requested Date from Order
if((sTotalCount == i || sTotalCount == j) && k ==0)
{
oOrderBC = oOrderBO.GetBusComp("Order Entry - Orders");
with(oOrderBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var sRequestedDate = GetFieldValue("Requested Ship Date");
}
}
}
// }// end ofwith(oOrderItemBC)
if(i==0 && j==0 && k==sTotalCount)
{
DeleteAllCDEM(sOrderId);
}
if(sTotalCount == i && sParentCDCount == 0 && k == 0)
{
if(sParentEMCount >0 || sChildCDCount > 0 || sChildEMCount >0)
{
DeleteAllCDEM(sOrderId);
}
NewRecord(NewAfter);
// SetFieldValue("Line Number", sLineNum+1);
SetFieldValue("Order Header Id",sOrderId);
oProdBC = GetPicklistBusComp("Product");
with(oProdBC)
{
ClearToQuery();
SetSearchSpec("Product ID", sCDProduct);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
Pick();
}
}
//SetFieldValue("Product Id",sCDProduct);
SetFieldValue("Due Date", sRequestedDate);
WriteRecord();
}
else if(sTotalCount == j && sParentEMCount ==0 && k == 0)
{
if(sParentCDCount >0 || sChildCDCount > 0 || sChildEMCount >0)
{
DeleteAllCDEM(sOrderId);
}
NewRecord(NewAfter);
// SetFieldValue("Line Number", sLineNum+1);
SetFieldValue("Order Header Id",sOrderId);
oProdBC = GetPicklistBusComp("Product");
with(oProdBC)
{
ClearToQuery();
SetSearchSpec("Product ID", sEMProduct);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
Pick();
}
}
//SetFieldValue("Product Id",sEMProduct);
SetFieldValue("Due Date", sRequestedDate);
WriteRecord();
}
else if((i>0 && sTotalCount > i) || (j >0 && sTotalCount > j))
{
var sRecord = FirstRecord();
while(sRecord)
{
sOrderItemId = GetFieldValue("Id");
var sParQIId = GetFieldValue("Parent Order Item Id");
var sProdId = GetFieldValue("Product");
var sParSpeCharges = GetFieldValue("CMI Parent Special Charges");
var sChildCDExist:Number = sChildCDIdList.indexOf(sOrderItemId);
var sChildCDExist1:Number = sChildCDIdList.indexOf(sParQIId);
var sChildEMExist:Number = sChildEMIdList.indexOf(sOrderItemId);
var sChildEMExist1:Number = sChildEMIdList.indexOf(sParQIId);
var sReqDate = GetFieldValue("Due Date");
if(sProdId == sCD && sParSpeCharges == sEM)// && sChildCDExist1 == -1)
{
DeleteRecord();
sRecord=PreviousRecord();
NewRecord(NewAfter);
SetFieldValue("Order Header Id",sOrderId);
oProdBC = GetPicklistBusComp("Product");
with(oProdBC)
{
ClearToQuery();
SetSearchSpec("Product ID", sEMProduct);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
Pick();
}
}
//SetFieldValue("Product Id", sEMProduct);
SetFieldValue("Parent Order Item Id", sParQIId);
SetFieldValue("Root Order Item Id", sParQIId);
SetFieldValue("Due Date", sReqDate);
WriteRecord();
}
else if(sProdId == sEM && sParSpeCharges == sCD)// && sChildCDExist1 > 0 && sChildEMExist1 == -1)
{
DeleteRecord();
sRecord=PreviousRecord();
NewRecord(NewAfter);
SetFieldValue("Order Header Id",sOrderId);
oProdBC = GetPicklistBusComp("Product");
with(oProdBC)
{
ClearToQuery();
SetSearchSpec("Product ID", sCDProduct);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
Pick();
}
}
//SetFieldValue("Product Id",sCDProduct);
SetFieldValue("Parent Order Item Id", sParQIId);
SetFieldValue("Root Order Item Id", sParQIId);
SetFieldValue("Due Date", sReqDate);
WriteRecord();
}
else if(GetFieldValue("CMI Special Charges") == sCD && sChildCDExist == -1 && sChildEMExist == -1)
{
//Create the Child Line item with product- Customer Down;
NewRecord(NewAfter);
// SetFieldValue("Line Number", lsSequence);
SetFieldValue("Order Header Id",sOrderId);
oProdBC = GetPicklistBusComp("Product");
with(oProdBC)
{
ClearToQuery();
SetSearchSpec("Product ID", sCDProduct);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
Pick();
}
}
//SetFieldValue("Product Id",sCDProduct);
SetFieldValue("Parent Order Item Id", sOrderItemId);
SetFieldValue("Root Order Item Id", sOrderItemId);
SetFieldValue("Due Date", sReqDate);
WriteRecord();
}
else if(GetFieldValue("CMI Special Charges") == sEM && sChildEMExist == -1 && sChildCDExist == -1)
{
//Create the Child Line item with product- Economy;
NewRecord(NewAfter);
// SetFieldValue("Line Number", lsSequence);
SetFieldValue("Order Header Id",sOrderId);
oProdBC = GetPicklistBusComp("Product");
with(oProdBC)
{
ClearToQuery();
SetSearchSpec("Product ID", sEMProduct);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
Pick();
}
}
//SetFieldValue("Product Id",sEMProduct);
SetFieldValue("Parent Order Item Id", sOrderItemId);
SetFieldValue("Root Order Item Id", sOrderItemId);
SetFieldValue("Due Date", sReqDate);
WriteRecord();
}
// if((sParentCDCount > 0 && sParentCDId == sOrderItemId) || (sParentEMCount > 0 && sParentEMId == sOrderItemId))
if(sParentCDId == sOrderItemId || sParentEMId == sOrderItemId)
{
DeleteRecord();
}
else
sRecord = NextRecord();
}//end of while(FirstRecord())
}//end of else if
} //end of with(oOrderItemBC)
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally
{
oProdBC = null;
oOrderItemBC_new = null;
oOrderBO_new = null;
oOrderItemBC = null;
oOrderBC = null;
oOrderBO = null;
}
}

CMI Add CD-EM Products-Order
DeleteAllCDEM
function DeleteAllCDEM(sOrderId)
{
/*******************************************************************************************
Created By : JW918
Created On : 15.09.2011
C&I Number : 4462 .Enhancement# S041
Functionality: This function deletes the unnecessary CD-EM products.
Enhancement#S041
**********************************************************************************************/
try
{
var oOrderBO:BusObject;
var oOrderItemBC:BusComp;
var sCD = TheApplication().InvokeMethod("LookupValue","CMI_CD_EM","Customer Down");
var sEM = TheApplication().InvokeMethod("LookupValue","CMI_CD_EM","Economy");
oOrderBO = TheApplication().GetBusObject("Order Entry (Sales)");
//CMI DBU relase#1, C&I 4462, Config: BC changed to Order Entry - Line Items (Simple) to avoid trigerring RTE on DeleteRecord by JW919 on 12/19/2011
//oOrderItemBC = oOrderBO.GetBusComp("Order Entry - Line Items");
oOrderItemBC = oOrderBO.GetBusComp("Order Entry - Line Items (Simple)");
with(oOrderItemBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Order Header Id", "='"+sOrderId+"' AND ([Product]='"+sCD+"' OR [Product]='"+sEM+"')");
ExecuteQuery(ForwardOnly);
while(FirstRecord())
{
DeleteRecord();
}
}
}
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally
{
oOrderItemBC = null;
oOrderBO = null;
}
}

CMI Add CD-EM Products-Order
GetDummyProduct
function GetDummyProduct(aDummyProduct)
{
/*******************************************************************************************
Created By : JW918
Created On : 15.09.2011
C&I Number : 4462 .Enhancement# S041
Functionality: This function gets the Customer Down & Economy products.
Enhancement#S041
**********************************************************************************************/
try
{
var sProductId:String = "";
var oProductBO:BusObject = TheApplication().GetBusObject("Admin ISS Product Definition");
var oProductBC:BusComp = oProductBO.GetBusComp("Internal Product - ISS Admin");
with(oProductBC)
{
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Name", aDummyProduct);
ExecuteQuery(ForwardOnly);
var PHasRecord = FirstRecord();
if(PHasRecord)
{
sProductId = GetFieldValue("Id");
}
}
}
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally
{
oProductBC = null;
oProductBO = null;
}
return(sProductId);
}

CMI Add CD-EM Products-Order
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if(MethodName == "AddCD_EMProducts")
{
TheApplication().ActiveBusObject().GetBusComp("Order Entry - Line Items").WriteRecord();
AddCD_EMProducts(Inputs, Outputs);
TheApplication().GetService("FINS Teller UI Navigation").InvokeMethod("RefreshCurrentApplet",TheApplication().NewPropertySet(), TheApplication().NewPropertySet());
return(CancelOperation);
}
}
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
return (ContinueOperation);
}

CMI Add Core Product
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
switch (MethodName) {
case "AddCoreQuote":
AddCore("Quote", Inputs, Outputs);
break;
case "AddCoreOrder":
AddCore("Order", Inputs, Outputs);
break;
case "FixTemplateFKs":
FixTemplateFKs(Inputs, Outputs);
break;
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
return (CancelOperation);
}

CMI Add Core Product
AddCore
function AddCore(hdrType, Inputs, Outputs)//asCoreProdId,asQuoteId,sQId,sSeq)
{
/*******************************************************************************************
Created By : Pravinkumar Parate (JX050)
Created On : 2011-2-23
C&I Number : 4761
Functionality: This business service gets triggers when recon product gets added on
Quote Line item. It fetches the Core Products from Product Recommendation view and
add the child core products in Quote Line Item.
**********************************************************************************************/
try
{
TheApplication().Utility.logStack("AddCore", this);
var skipRefresh = TheApplication().GetProfileAttr("SkipRefresh").toUpperCase();
var headerId = "";
var lineId = "";
var boObject:BusObject;
var bcHeader:BusComp;
var bcLine:BusComp;
var statusField, dueDateField, minQtyField, maxQtyField, sourceInvField, typeField
var nameRefreshBC, nameBO;
switch(hdrType) {
case "Quote":
nameBO = "Quote";
nameRefreshBC = "Quote Item";
headerId = TheApplication().GetProfileAttr("Quote Id");
lineId = TheApplication().GetProfileAttr("CMI Quote Item Id");
boObject = TheApplication().GetBusObject(nameBO);
bcHeader = boObject.GetBusComp("Quote");
bcLine = boObject.GetBusComp("Quote Item (Simple)");
dueDateField = "Requested Delivery Date";
minQtyField = "Minimum Quantity";
maxQtyField = "Maximum Quantity";
statusField = "CMI Status";
sourceInvField = "Source Inventory Location Id";
typeField = "CMI Quote Type";
break;
case "Order":
nameBO = "Order Entry (Sales)";
nameRefreshBC = "Order Entry - Line Items";
headerId = TheApplication().GetProfileAttr("Order Id");
lineId = TheApplication().GetProfileAttr("Order Line Item Id");
boObject = TheApplication().GetBusObject(nameBO);
bcHeader = boObject.GetBusComp("Order Entry - Orders");
bcLine = boObject.GetBusComp("Order Entry - Line Items (Simple)");
dueDateField = "Due Date";
minQtyField = "CMI Minimum Quantity";
maxQtyField = "CMI Maximum Quantity";
statusField = "Status";
sourceInvField = "Source Inventory Loc Id";
typeField = "CMI Order Type";
break;
}
var boProd:BusObject = TheApplication().GetBusObject("Admin ISS Product Definition");
var bcProdRec:BusComp = boProd.GetBusComp("Product Recommendation");
var dirtyCoreRtn = TheApplication().InvokeMethod("LookupValue", "RETURN_REASON", "Dirty Core Return");
var bcProduct:BusComp;
TheApplication().Utility.logVars("Header Id", headerId, "Line Id", lineId);
with(bcHeader) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", headerId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
with(bcLine) {
SetViewMode(AllView);
ClearToQuery();
ActivateField(minQtyField)
ActivateField(maxQtyField)
ActivateField("CMI Line Type")
ActivateField("Parent "+hdrType+" Item Id")
ActivateField("Root "+hdrType+" Item Id")
ActivateField("Covered Quote Item Id")
ActivateField("Extended Quantity Requested")
ActivateField("Product Id");
ActivateField("Line Number");
ActivateField("Item Price List Id");
ActivateField("CMI Unit of Measure");
ActivateField(typeField);
ActivateField(statusField);
ActivateField(dueDateField);
ActivateField(sourceInvField);
ActivateField("CMI Main Assembly Flag");
ActivateField("CMI Return Reason"); //JQ487: activated Return reason field for dirty core as per defect 4135 on 01/04/12
// ActivateField("Discount Amount"); //KW920 : Activated for CQ:3002 ; commented for updated CQ;3002
if(hdrType == "Quote") ActivateField("CMI Fulfillment Set Id"); //CQ: 2934 Dt.06/20/12
SetSearchSpec("Id", lineId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
var asCoreProdId = GetFieldValue("Product Id");
var sSeq = GetFieldValue("Line Number");
var sPriceList = GetFieldValue("Item Price List Id");
var sUOM = GetFieldValue("CMI Unit of Measure");
var sType = GetFieldValue(typeField);
var sStatus = GetFieldValue(statusField);
var sReqDelDt:String = GetFieldValue(dueDateField);
var sSrcInvId:String = GetFieldValue(sourceInvField);
var sMainAssembly = GetFieldValue("CMI Main Assembly Flag");
var sQtyReq = GetFieldValue("Quantity Requested");
var minQty = GetFieldValue(minQtyField);
var maxQty = GetFieldValue(maxQtyField);
TheApplication().Utility.logVars("Type", sType);
}
}
}//end if (quote bc first record)
}//end with bcHeader
with(bcProdRec) {
ActivateField("Recommended Product ID");
ActivateField("Parent Product ID");
ActivateField("Recommeded Product Name");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Parent Product ID", asCoreProdId);
SetSearchSpec("UMS Type", "Core");
ExecuteQuery(ForwardOnly);
var sRecord = FirstRecord();
TheApplication().Utility.logVars("Recommended Product Found?", sRecord);
var lsSequence = ToNumber(sSeq) + 1;
var negativeQty:Number = sQtyReq * -1;
while(sRecord) {
var sCoreId = GetFieldValue("Recommended Product ID");
bcLine.FirstRecord(); //Added to avoid the error on NewRecord which comes when context is on child Recon product by JW919 on 16/06/2011
with(bcLine) {
//Create or Update the Clean Core Line Item
TheApplication().Utility.logVars("Main Assembly", sMainAssembly);
if(hdrType == "Quote" || sType == TheApplication().InvokeMethod("LookupValue", "FS_ORDER_TYPE", "Sales Order")) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Parent "+hdrType+" Item Id", lineId);
SetSearchSpec("Product Id", sCoreId);
ExecuteQuery(ForwardBackward);
var sHasRecord = FirstRecord();
TheApplication().Utility.logVars("Clean Core Line Found?", sHasRecord);
if (!(sHasRecord)) {
NewRecord(NewAfter);
SetFieldValue("Line Number", lsSequence);
SetFieldValue("Item Price List Id", sPriceList);
SetFieldValue("CMI Unit of Measure", sUOM);
SetFieldValue(statusField, sStatus);
SetFieldValue(dueDateField, sReqDelDt);
SetFieldValue("Parent "+hdrType+" Item Id", lineId);
SetFieldValue("Root "+hdrType+" Item Id", lineId);
if (hdrType == "Quote")
SetFieldValue("CMI Fulfillment Set Id", lineId);//CQ: 2934 Dt.06/20/12
// SetFieldValue("Discount Amount",0);
}
if(sMainAssembly != "Y") {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type"));
SetFieldValue("Quantity Requested", sQtyReq);
SetFieldValue("Extended Quantity Requested", sQtyReq);
} else {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type"));
SetFieldValue(minQtyField, -9999999);
SetFieldValue(maxQtyField, -1);
SetFieldValue("Quantity Requested", negativeQty);
SetFieldValue("Extended Quantity Requested", negativeQty);
}
SetFieldValue(sourceInvField, sSrcInvId);
//CMI <Release# 1DBU>,C&I# 4455Enhancement# S154<Configuration>: <changed to picking product so that pick maps can be triggered> By JQ487 On 08/17/11
// This pick of product is for addition of clean core
bcProduct = bcLine.GetPicklistBusComp("Product");
with(bcProduct) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Product ID", sCoreId);
ExecuteQuery(ForwardOnly);
}//end of with bcProduct
//Possibility that the related products are not linked to the org of the user
if(bcProduct.FirstRecord()) {
bcProduct.Pick();
WriteRecord();
} else {
TheApplication().Utility.logStep(bcProdRec.GetFieldValue("Recommeded Product Name")+" not visible to this user.");
UndoRecord();
}
}
//Create the Dirty Core Line Item for Service Quotes or Sales Orders (as opposed to Parts
//Requests)
TheApplication().Utility.logVars("Type", sType);
if(sType == TheApplication().InvokeMethod("LookupValue", "QUOTE_TYPE", "Service Quote") ||
sType == TheApplication().InvokeMethod("LookupValue", "FS_ORDER_TYPE", "Sales Order")) {
ClearToQuery();
SetSearchSpec("Covered Quote Item Id", lineId);
SetSearchSpec("Product Id", sCoreId);
ExecuteQuery(ForwardBackward);
sHasRecord = FirstRecord();
TheApplication().Utility.logVars("Dirty Core Line Found?", sHasRecord);
if (!(sHasRecord)) {
bcLine.FirstRecord();
NewRecord(NewAfter);
lsSequence = lsSequence + 1;
SetFieldValue("Line Number", lsSequence);
SetFieldValue("Item Price List Id", sPriceList);
SetFieldValue("CMI Unit of Measure", sUOM);
SetFieldValue(statusField, sStatus);
SetFieldValue(dueDateField, sReqDelDt);
SetFieldValue("CMI Return Reason", dirtyCoreRtn); //JQ487: setting Return reason for dirty core as per defect 4135 on 01/04/12
SetFieldValue("Covered Quote Item Id", lineId);
}
if(sMainAssembly != "Y") {
//Make association b/w Dirty core and Recon product
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type"));
SetFieldValue(minQtyField, -9999999);
SetFieldValue(maxQtyField, -1);
SetFieldValue("Quantity Requested", negativeQty);
} else {
SetFieldValue(minQtyField, minQty);
SetFieldValue(maxQtyField, maxQty);
SetFieldValue("CMI Line Type", "");
SetFieldValue("Quantity Requested", sQtyReq);
SetFieldValue("Extended Quantity Requested", sQtyReq);
}
SetFieldValue(sourceInvField, sSrcInvId);
//The below pick is for adding dirty core product.
bcProduct = bcLine.GetPicklistBusComp("Product");
with(bcProduct) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Product ID", sCoreId);
ExecuteQuery(ForwardOnly);
}//end of with bcProduct
//Possibility that the related products are not linked to the org of the user
if(bcProduct.FirstRecord()) {
bcProduct.Pick();
WriteRecord();
} else {
TheApplication().Utility.logStep(bcProdRec.GetFieldValue("Recommeded Product Name")+" not visible to this user.");
UndoRecord();
}
} //end of if sType
}//end of with bcLine
lsSequence = lsSequence + 1;
sRecord = bcProdRec.NextRecord();
}// end of while
}//end of with bcProdRec
if (skipRefresh == "") {
var oBS = TheApplication().GetService("SIS OM PMT Service");
var psIO = TheApplication().NewPropertySet();
var psOP = TheApplication().NewPropertySet();
psIO.SetProperty("Business Object Name", nameBO);
psIO.SetProperty("Business Component Name", nameRefreshBC);
oBS.InvokeMethod("Refresh Business Component",psIO,psOP);
TheApplication().ActiveBusObject().GetBusComp("Quote Item").InvokeMethod("SetRefreshRollups");
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
psOP = null;
psIO = null;
oBS = null;
bcProdRec = null;
boProd = null;
bcProduct = null;
bcLine = null;
bcHeader = null;
boObject = null;
//Making profile attribute Null as it is used in RTE just for triggering this BS.
TheApplication().SetProfileAttr("CMICoreProductFlag", "");
TheApplication().Utility.logUnstack();
}
}

CMI Add Core Product
FixTemplateFKs
function FixTemplateFKs(Inputs, Outputs) {
// update the foreign keys of copied template quote item records that used to point to the parent core quote item of the template quote
// to the new parent core quote item of the txn quote
try {
TheApplication().Utility.logStack("FixTemplateFKs", this);
var quoteId = Inputs.GetProperty("Quote Id");
var parentItemId = Inputs.GetProperty("Parent Quote Item Id");
var coveredItemId = Inputs.GetProperty("Covered Quote Item Id");
var boQuote = TheApplication().GetBusObject("Quote");
var bcLine = boQuote.GetBusComp("Quote Item (Simple)");
var quoteItemId = (coveredItemId != "" ? coveredItemId : parentItemId);
var productId = "";
//Find the Template quote item line using the covered or parent FK from the copied txn line
with (bcLine) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("Product Id");
SetSearchSpec("Id", quoteItemId);
ExecuteQuery(ForwardOnly);
var found = FirstRecord();
TheApplication().Utility.logVars("Template Parent Line ("+quoteItemId+") found?", found);
if (found) {
productId = GetFieldValue("Product Id");
//Now find the corresponding parent txn quote item line using the product id from the template line
ClearToQuery();
SetSearchSpec("Quote Id", quoteId);
SetSearchSpec("Product Id", productId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Txn Line for Product ("+productId+") found?", found);
if (found) {
parentItemId = GetFieldValue("Id");
Outputs.SetProperty("Parent Quote Item Id", parentItemId);
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcLine = null;
boQuote = null;
TheApplication().Utility.logUnstack(parentItemId);
}
}

CMI Add Labor to Order
GetActivityDetails
function GetActivityDetails(sQuoteId,sOwnerId)
{
try{
var oboAction:BusObject = TheApplication().GetBusObject("Action");
var obcAction:BusComp = oboAction.GetBusComp("Action");
with(obcAction)
{
SetViewMode(AllView);
ActivateField("Quote Id");
ClearToQuery();
SetSearchSpec("Quote Id", sQuoteId);//changed from order id to quote id
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Service Labor"));
SetSearchSpec("Primary Owner Id", sOwnerId);
ExecuteQuery();
var isRec2 = FirstRecord();
while(isRec2)
{
var sSerLabId:String = GetFieldValue("Id");
TimeTrackerCheck(sSerLabId);
isRec2 = NextRecord();
}
}
}
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally
{
obcAction = null;
oboAction = null;
}
}

CMI Add Labor to Order
(declarations)
/*Global Variables*/
var sCost:Number = 0;
var sDurHr:Number = 0;
var sTotalCost:Number = 0;
var sTotalDurHr:Number = 0;
//var sCount = 0;
var sProdId = "";
//Added by KM326 for C&I 4657 on 08-12-2011
var sCostListCost = 0;

CMI Add Labor to Order
CheckPosition
function CheckPosition(sOwnerId, sRateListId)
{
/*******************************************************************************************
Created By :<JQ487>
Created On : <08/02/2011>
Method Name:AddLabor
C&I Number: 4657
Requirement #: Enhancement S138
Functionality: This BS will query for Billable product associated with Technician.
****************************************************************************************** */
try{
TheApplication().Utility.logStack("CheckPosition", this);
var boPosition:BusObject = TheApplication().GetBusObject("Position");
var bcPosition:BusComp = boPosition.GetBusComp("Position");
var boRateList:BusObject = TheApplication().GetBusObject("PS Rate List");
var bcRateList:BusComp = boRateList.GetBusComp("PS Rate List");
var boCostList:BusObject = TheApplication().GetBusObject("Cost List");
var bcCostList:BusComp = boCostList.GetBusComp("Cost List");
var bcCostListItem:BusComp = boCostList.GetBusComp("Cost List Item");
var sCostListId = "";
var product;
// TheApplication("Test Active Position", TheApplication().PositionName()+" ("+TheApplication().PositionId()+")");
with(bcPosition) {
SetViewMode(AllView);
ActivateField("Billing Product Id");
ActivateField("Billing Product");
ClearToQuery();
SetSearchSpec("Employee Id", sOwnerId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Position for Employee("+sOwnerId+") found?", FirstRecord());
if(FirstRecord()) {
//modified by km326 for C&I 4657 on 08-12-2011
product = GetFieldValue("Billing Product");
sProdId = GetFieldValue("Billing Product Id");
//commented by km326 for C&I 4657 on 08-12-2011
}
}//end (bcPosition)
TheApplication().Utility.logVars("Product (Id)", product+" ("+sProdId+")");
if(sProdId != null && sProdId != "") {
with(bcRateList) {
SetViewMode(AllView);
ActivateField("Cost List Id");
ClearToQuery();
SetSearchSpec("Id", sRateListId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Rate List ("+sRateListId+") found?", FirstRecord());
if(FirstRecord()) {
sCostListId = GetFieldValue("Cost List Id");
with(bcCostList) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sCostListId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Cost List ("+sCostListId+") found?", FirstRecord());
if(FirstRecord()) {
with(bcCostListItem) {
SetViewMode(AllView);
ActivateField("Product Id");
ActivateField("Standard Cost");
ClearToQuery();
SetSearchSpec("Price List Id", sCostListId);
SetSearchSpec("Product Id", sProdId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("First Cost Item found?", FirstRecord());
if(FirstRecord()) {
sCostListCost = GetFieldValue("Standard Cost");
}
}
}
}
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPosition = null;
boPosition = null;
bcCostListItem = null;
bcRateList = null;
bcCostList = null;
boRateList = null;
boCostList = null;
TheApplication().Utility.logUnstack(sCostListCost);
}
}

CMI Add Labor to Order
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if(MethodName == "AddLabor") {
UpdateOrderLine(Inputs,Outputs);
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Add Labor to Order
TimeTrackerCheck
function TimeTrackerCheck(sSerLabId)
{
/*******************************************************************************************
Created By :<JQ487>
Created On : <08/02/2011>
Method Name:AddLabor
C&I Number: 4657
Requirement #: Enhancement S138
Functionality: This BS will query for Time Tracker records in Service labor activity
Input:
****************************************************************************************** */
try{
TheApplication().Utility.logStack("TimeTrackerCheck", this);
var boAction:BusObject = TheApplication().GetBusObject("Action");
var bcTimeSheetHrs:BusComp = boAction.GetBusComp("Time Sheet Daily Hours");
with(bcTimeSheetHrs) {
SetViewMode(AllView);
ActivateField("Time Cost");
ActivateField("CMI Time Cost - Calc");
ActivateField("Elasped Time in Hours");
ActivateField("Elasped Time in Time");
ClearToQuery();
SetSearchSpec("Activity Id", sSerLabId);
ExecuteQuery(ForwardBackward);
var isRec = FirstRecord();
while(isRec) {//this loop will sum the Duration and Cost on Time tracker record and will update it on Labor record on order item
sCost = GetFieldValue("Time Cost");
sDurHr = GetFieldValue("Elasped Time in Hours");
TheApplication().Utility.logVars("Elasped Hours / Time / Cost / Converted", GetFieldValue("Elasped Time in Hours")+" / "+
GetFieldValue("Elasped Time in Time")+" / "+GetFieldValue("Time Cost")+" / "+GetFieldValue("CMI Time Cost - Calc"));
sTotalCost = ToNumber(sTotalCost) + ToNumber(sCost);
sTotalDurHr = ToNumber(sTotalDurHr) + ToNumber(sDurHr);
isRec = NextRecord();
}
}//end (bcOrder)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
boAction = null;
bcTimeSheetHrs = null;
TheApplication().Utility.logUnstack(sTotalDurHr+" / "+sTotalCost);
}
}

CMI Add Labor to Order
UpdateOrderLine
function UpdateOrderLine(Inputs,Outputs)
{
/*******************************************************************************************
Created By :<JQ487>
Created On : <08/02/2011>
Method Name:AddLabor
C&I Number: 4657
Requirement #: Enhancement S138
Functionality: This BS will query for Time Tracker records in Service labor activity and based on
technicians billable product will create a new labor record with product same as billable product
from technician. also it queries the quote, from which order is generated, for labor line items
and adds the sum of their Requested Quantity to "Quoted Quantity" of first labor record in Order.
Input:
Output:
****************************************************************************************** */
try{
TheApplication().Utility.logStack("UpdateOrderLine", this);
var sOrderId = Inputs.GetProperty("OrderId");
var sQuoteId = Inputs.GetProperty("QuoteId");
var boQuote = TheApplication().GetBusObject("Quote");
var bcQuote = boQuote.GetBusComp("Quote");
var bcQuoteItem = boQuote.GetBusComp("Quote Item");
var boOrder:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var bcOrder:BusComp = boOrder.GetBusComp("Order Entry - Orders");
var bcOrderItem:BusComp = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
var bcAction:BusComp = boQuote.GetBusComp("Action");
var bcProduct:BusComp;
var sSRId:String = "";
var sActionId:String = "";
var sQtySum:Number = 0;
var sProdType:String = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
var sRbtResource = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Rebuild Resource");
//Adde by KM326 to fix 721/651 on 02-12-2011
var sPrevTotalDurHr = 0;
var sPrevTotalCost = 0;
var prevOwnerId = "";
var sOwnerId:String = "";
//Querying Quote Item BC to Sum the total of the Requested Quantity for all labor lines on the quote and storing in a variable
with(bcQuote){
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Id", sQuoteId);
ExecuteQuery(ForwardOnly);
var qisRec = FirstRecord();
TheApplication().Utility.logVars("Quote ("+sQuoteId+") found?", qisRec);
if (qisRec) {
with(bcQuoteItem) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("Product");
SetSearchSpec("Product Type", sProdType);
ExecuteQuery(ForwardBackward);
var isRec = FirstRecord();
TheApplication().Utility.logVars("First Labor Item found?", isRec);
while(isRec) {
var sQty = GetFieldValue("Quantity Requested");
TheApplication().Utility.logStep("Add "+GetFieldValue("Product")+" Hours: "+sQty+" + "+sQtySum);
sQtySum = sQtySum + ToNumber(sQty);
isRec = NextRecord();
}//end while(isRec)
}//end with(bcQuoteItem)
//Find the Service Labor activity based on Quote ID
with(bcAction) {
SetViewMode(AllView);
ActivateField("Quote Id");
ActivateField("Rate List Id");
ActivateField("CMI Owner FullName");
ClearToQuery();
SetSortSpec("Primary Owner Id(ASCENDING)"); //KM326 to fix bug 721/651 on 02-12-2011
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Service Labor"));
ExecuteQuery(ForwardBackward);
var isRec1 = FirstRecord();
while(isRec1) {
TheApplication().Utility.logStep("Service Labor Activity ("+GetFieldValue("Id")+") Owner: "+GetFieldValue("CMI Owner FullName"));
sOwnerId = GetFieldValue("Primary Owner Id");
if (prevOwnerId != sOwnerId && sOwnerId != "") {
prevOwnerId = sOwnerId;
CheckPosition(sOwnerId, GetFieldValue("Rate List Id"));
}
if(sProdId == null || sProdId == "") {
isRec1 = bcAction.NextRecord();
} else {
TimeTrackerCheck(GetFieldValue("Id"));
with(bcOrder) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
var oisRec = FirstRecord();
TheApplication().Utility.logVars("Order ("+sOrderId+") found?", oisRec);
if(oisRec) {
with(bcOrderItem) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("Product");
ActivateField("CMI Price Override");
ActivateField("Quantity Requested");
ActivateField("Extended Quantity Requested");
ActivateField("Cost");
ActivateField("Net Price");
ActivateField("Product Id");
ActivateField("CMI Line Type");
ActivateField("CMI Actual Quantity");
ActivateField("Unit Price");
SetSearchSpec("Product Id", sProdId);
ExecuteQuery(ForwardOnly);
var olisRec = FirstRecord();
TheApplication().Utility.logVars("Order Line found?", olisRec);
if(olisRec) {
sPrevTotalDurHr = sPrevTotalDurHr + sTotalDurHr;
sPrevTotalCost = sPrevTotalCost + sTotalCost;
//Updating the quantity field on the labor item with the sum of
//the duration field from the time tracker record
SetFieldValue("CMI Actual Quantity", ToNumber(sPrevTotalDurHr));
SetFieldValue("Quantity Requested", ToNumber(sPrevTotalDurHr));
SetFieldValue("Extended Quantity Requested", ToNumber(sPrevTotalDurHr));
//Updating the cost and Manual Price Override on the labor item
//with the cost field from the time tracker record
SetFieldValue("CMI Price Override", ToNumber(sPrevTotalCost));
SetFieldValue("Cost", ToNumber(sCostListCost));
SetFieldValue("Net Price", ToNumber(sCostListCost));
SetFieldValue("Unit Price", ToNumber(sCostListCost));
sCost = 0;
sDurHr = 0;
sTotalCost = 0;
sTotalDurHr = 0;
sProdId = "";
isRec1 = bcAction.NextRecord();
} else {
NewRecord(NewAfter);
bcProduct = GetPicklistBusComp("Product");
with(bcProduct) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sProdId);
ExecuteQuery(ForwardOnly);
var isPickBCRec = FirstRecord();
if(isPickBCRec) Pick();
}//end with(sProd)
//Updating the quantity field on the labor item with the sum of
//the duration field from the time tracker record
SetFieldValue("CMI Actual Quantity", ToNumber(sTotalDurHr));
SetFieldValue("Quantity Requested", ToNumber(sTotalDurHr));
SetFieldValue("Extended Quantity Requested", ToNumber(sTotalDurHr));
//Updating the cost and Manual Price Override on the labor item
//with the cost field from the time tracker record
SetFieldValue("CMI Price Override", sTotalCost);
SetFieldValue("Cost", ToNumber(sCostListCost));
SetFieldValue("Net Price",ToNumber(sCostListCost));//added by km330 for defect 651,on 30/11/2011
SetFieldValue("Unit Price", ToNumber(sCostListCost));
SetFieldValue("CMI Line Type", sRbtResource);
WriteRecord();
sPrevTotalDurHr = sTotalDurHr;
sPrevTotalCost = sTotalCost;
sCost = 0;
sDurHr = 0;
sTotalCost = 0;
sTotalDurHr = 0;
sProdId = "";
isRec1 = bcAction.NextRecord();
}//end else
}//end with(bcOrderItem)
}//end if
}//end with(bcOrder)
}
}//end While
}//end (bcAction)
//Querying Order Item BC again to Update the field Quoted
//Quantity on first labor line that was added via the previous
//step with the total of the requested quantity
with(bcOrderItem) {
SetViewMode(AllView);
ActivateField("Order Header Id");
ActivateField("CMI Quantity Quoted");
ActivateField("CMI Order Status");
ClearToQuery();
SetSearchSpec("Order Header Id", sOrderId);
SetSearchSpec("Product Type", TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor"));
ExecuteQuery(ForwardBackward);
TheApplication().Utility.logVars("Labor Line found?", FirstRecord());
if(FirstRecord()) {
SetFieldValue("CMI Quantity Quoted", sQtySum);
WriteRecord();
}
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcProduct = null;
bcAction = null;
bcQuote = null;
bcQuoteItem = null;
bcOrder = null;
bcOrderItem = null;
boQuote = null;
boOrder = null;
TheApplication().Utility.logUnstack();
}
}

CMI Add Order Id to Tracker Activity BS
AddOrderId
function AddOrderId(sQuoteNumber, sOrderId)
{
try{//added try..catch..finally by woody for code review on 20110817
var oBOAction = TheApplication().GetBusObject("Action");
var oBCAction = oBOAction.GetBusComp("Action");
with(oBCAction)
{
var sPartsTracker = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Parts Tracker");
var sTimeTracker = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Service Labor");
SetViewMode(AllView);
ActivateField("Order Id");
ActivateField("CMI Quote Number");
ClearToQuery();
var searchst = "[CMI Quote Number] = '" + sQuoteNumber + "' AND ([Type] = '" + sPartsTracker + "' OR [Type] = '" + sTimeTracker + "')";
SetSearchExpr(searchst);
//SetSearchSpec("Quote Id", sQuoteNumber); //should be Quote Number, this field is not created yet.
ExecuteQuery(ForwardOnly);
var HasRecord = FirstRecord()
while(HasRecord)
{
SetFieldValue("Order Id",sOrderId);
WriteRecord();
HasRecord = NextRecord();
}
}//end with(oBCAction)
}
catch(e)
{
throw(e);
}
finally
{
oBCAction = null;
oBOAction = null;
}
}

CMI Add Order Id to Tracker Activity BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : ix964
Created On : 09 Dec 2010
Method Name:
Functionality:
Input: Quote Number, Order Id
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//try catch added by shanmukh for code clean up 08/21/2011
try
{
if (MethodName == "AddOrderId")
{
var sQuoteNumber = Inputs.GetProperty("QuoteNumber");
var sOrderId = Inputs.GetProperty("OrderId");
AddOrderId(sQuoteNumber, sOrderId);
return (CancelOperation);
}
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}//end of catch
return (ContinueOperation);
}

CMI Approval Admin Data Load
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if(MethodName == "f_Process_File")
{
//if (Inputs.GetChildCount() > 0)
{
f_Process_File(Inputs);
}
return (CancelOperation);
}
}
catch(e)
{
throw e;
}
//Finally block ramoved by ko981 on <06/12/2011>
return (ContinueOperation);
}

CMI Approval Admin Data Load
f_Process_File
///////////////////////////////////////////////////////////
//
//Script: SDA Load App Admin
//Author(s): Shawn Abadie, eVerge Group, Inc.
//
//Desc: Open the CSV of Approval Admin data
//
//File layout:
// Data BC Field
//
// #FINS Approval Level_Approval Hierarchy Type
// FINS Approval Level_Approval Level
// FINS Approval Level_Type
// FINS Approval Stage_Stage Number
// FINS Approval Stage_Approval Type
// FINS Approval Stage_Type
// FINS Approval Stage_Position Name
function f_Process_File(Inputs)
{
var boFINSApproval;
var bcApprLevel;
var bcApprStage;
//var bcPostn;
var bcPostnAssoc;
var boPosition;
var bcPosition;
var ApprLevelFields;
var ApprStageFields;
var apprbcname;
var isRec = false;
var psErrorRecords = TheApplication().NewPropertySet();
var nError = 1;
var propName = "";
var propValue = "";
var oFile;
var ApprLevelId = "";
try
{
var fp = Clib.fopen("D:\\Approval_Item_Data.csv","rt");
if ( fp == null )
{
TheApplication().RaiseErrorText("\aError opening file for reading.\n")
}
else
{
var line = Clib.fgets(fp);
if (line != null)
{
var HdrLine = 0;
var RecCount = 0;
if (line.charAt(0) == "#") // first line
{
HdrLine = HdrLine + 1;
line = Clib.fgets(fp);
}
// Setup BCs
boFINSApproval = TheApplication().GetBusObject("FINS Approval");
bcApprLevel = boFINSApproval.GetBusComp("FINS Approval Level");
bcApprStage = boFINSApproval.GetBusComp("FINS Approval Stage");
while (line != null)
{
try
{
var ApprFields = line.split(",");
var len = ApprFields.length;
RecCount++;
ApprLevelFields = TheApplication().NewPropertySet();
ApprLevelFields.SetProperty("Approval Level",ApprFields[1]);
ApprLevelFields.SetProperty("Approval Hierarchy Type",ApprFields[0]);
ApprLevelFields.SetProperty("Type",ApprFields[2]);
ApprStageFields = TheApplication().NewPropertySet();
ApprStageFields.SetProperty("Stage Number",ApprFields[3]);
ApprStageFields.SetProperty("Approval Type",ApprFields[4]);
ApprStageFields.SetProperty("Type",ApprFields[5]);
/*ApprStageFields.SetProperty("Position Name",ApprFields[6]);*/
/*ApprStageFields.SetProperty("Parent Level Name",ApprFields[2]);*/
bcApprLevel.ActivateMultipleFields(ApprLevelFields);
bcApprLevel.ClearToQuery();
bcApprLevel.SetViewMode(AllView);
bcApprLevel.SetSearchSpec("Approval Level",ApprFields[1]);
bcApprLevel.ExecuteQuery(ForwardOnly);
isRec = bcApprLevel.FirstRecord();
if (isRec)
{
//bcEmployee.DeleteRecord();
//bcApprLevel.SetMultipleFieldValues(ApprLevelFields);
//bcApprLevel.WriteRecord();
ApprLevelId = bcApprLevel.GetFieldValue("Id");
ApprStageFields.SetProperty("Approval Level Id", ApprLevelId);
}
else
{
bcApprLevel.NewRecord(NewBefore);
bcApprLevel.SetMultipleFieldValues(ApprLevelFields);
bcApprLevel.WriteRecord();
ApprLevelId = bcApprLevel.GetFieldValue("Id");
ApprStageFields.SetProperty("Approval Level Id", ApprLevelId);
}
var ThisApprLevel = ApprFields[1];
while (ThisApprLevel == ApprFields[1])
{
bcApprStage.NewRecord(NewBefore)
bcApprStage.SetMultipleFieldValues(ApprStageFields);
bcPostnAssoc = bcApprStage.GetMVGBusComp("Position Name").GetAssocBusComp();
bcPostnAssoc.ClearToQuery();
bcPostnAssoc.SetViewMode(AllView);
var PostnName = ApprFields[6];
bcPostnAssoc.SetSearchSpec("Name", PostnName);
bcPostnAssoc.ExecuteQuery(ForwardOnly);
if (bcPostnAssoc.FirstRecord())
{
bcPostnAssoc.Associate(NewBefore);
}
bcApprStage.WriteRecord();
line = Clib.fgets(fp);
ApprFields = line.split(",");
len = ApprFields.length;
RecCount++;
ApprLevelFields = TheApplication().NewPropertySet();
ApprLevelFields.SetProperty("Approval Level",ApprFields[1]);
ApprLevelFields.SetProperty("Approval Hierarchy Type",ApprFields[0]);
ApprLevelFields.SetProperty("Type",ApprFields[2]);
ApprStageFields = TheApplication().NewPropertySet();
ApprStageFields.SetProperty("Stage Number",ApprFields[3]);
ApprStageFields.SetProperty("Approval Type",ApprFields[4]);
ApprStageFields.SetProperty("Type",ApprFields[5]);
/*ApprStageFields.SetProperty("Position Name",ApprFields[6]);*/
ApprStageFields.SetProperty("Approval Level Id", ApprLevelId);
}
}
catch(e)
{
psErrorRecords.SetProperty("Error Record #: " + nError, "Login: " + ApprFields[2] + ", Error Code: " + e.errCode + ", Error Message: " + e.toString());
nError = nError + 1;
}
finally
{
/*line = Clib.fgets(fp);*/
}
}
}
}
Clib.fclose(fp);
//oFile = Clib.fopen("C:\\brs_customer_claims_errors.csv","w");
//Clib.fputs(psErrorRecords, oFile);
}
catch(e)
{
psErrorRecords.SetProperty("Error", "Code: " + e.errCode + ", Message: " + e.toString());
//oFile = Clib.fopen("C:\\brs_customer_claims_errors.csv","w");
//Clib.fputs(psErrorRecords, oFile);
}
finally
{
oFile = Clib.fopen("D:\\brs_customer_claims_errors.csv","w");
propName = psErrorRecords.GetFirstProperty();
// stay in loop if the property name is not an empty string
while (propName != "")
{
propValue = psErrorRecords.GetProperty(propName);
Clib.fputs(propName + "|" + propValue + "\n" , oFile);
propName = psErrorRecords.GetNextProperty();
}
Clib.fclose(oFile);
ApprLevelFields = null;
boFINSApproval = null;
ApprLevelFields = null;
}
}

CMI Batch Payment Process BS
BatchCloseProcess
/*************************************************************************************************************************
Created By :
Created On : 12th Feb 2011
Modified By: Dinesh,JQ486 for 285 Defect on 5 Oct 2011.
Method Name: function BusComp_PreInvokeMethod (MethodName) == "BatchCloseProcess"
Functionality: when the user change the field value "CMI Batch Status" from CMI Batch Payment List Applet,
the child Applet and the CMI Claims Payments List Applet will be change.
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function BatchCloseProcess() {
try {
TheApplication().Utility.logStack("BatchCloseProcess", this);
var oBO = TheApplication().ActiveBusObject();
var oBC = oBO.GetBusComp("CS HH Deposits");
var sBatchId = oBC.GetFieldValue("Id");
var oBOBatch = TheApplication().GetBusObject("HH CG Deposit Payments");
var oBCBatchPaymemt = oBOBatch.GetBusComp("CS HH FS Payments");
var oBOClaim = TheApplication().GetBusObject("CMI Claims");
var oBCClaim = oBOClaim.GetBusComp("INS Claims");
var oBCPayment = oBOClaim.GetBusComp("INS Claims Payments");
var sClaimNumber;
var sClaimId;
var balanceDue = 0;
var newBalanceDue = 0;
var currentPayment = 0;
var iVarToLevel;
var sEarlyCredit:String;//added by IY795 for enhancement S139
var sPayTo:String;//added by IY795 for enhancement S139
var sWarVarTotal;
var sCurcyCd;
var sPrevClaimId = "";//strong typing intentionally not used
var customerPayTo = TheApplication().InvokeMethod("LookupValue", "CMI_CLAIMS_PAYTO", "Customer");
var noEarlyCredit = TheApplication().InvokeMethod("LookupValue", "CMI_EARLY_CREDIT", "No Early Credit");
var issuedEarlyCredit = TheApplication().InvokeMethod("LookupValue", "CMI_EARLY_CREDIT", "Issued");
var claimStatusClosed = TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Closed");
var claimStatusRcvd = TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Payment Received");
var payStatusPending = TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Pending");
var payStatusVerified = TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Verified");
var Inputs = TheApplication().NewPropertySet();
var Outputs = TheApplication().NewPropertySet();
var txnService = TheApplication().GetService("EAI Transaction Service");
var found = false;
TheApplication().Utility.logId("CS HH Deposits", sBatchId);
TheApplication().Utility.logVars("Batch Id", sBatchId);
with(oBCBatchPaymemt) {
InvokeMethod("SetAdminMode", "TRUE");
SetViewMode(AllView);
ActivateField("Payment Status");
ActivateField("Amount");
ActivateField("Claim #");
ClearToQuery();
//Added SortSpec by km326 to fix C&I 4609 Defect on 10/08/2011
SetSortSpec("Claim Id(ASCENDING)");
SetSearchSpec("Deposit Id", sBatchId);
SetSearchSpec("Payment Status", payStatusPending);
ExecuteQuery(ForwardOnly);
var HasRecord = FirstRecord();
TheApplication().Utility.logVars("Pending Payment found?", HasRecord);
while (HasRecord) {
//Create a commit point so that if there is a validation error, the batch
//can be reprocessed
try {
txnService.InvokeMethod("BeginTransaction", Inputs, Outputs);
//Commit the payment verification so the newly processed payment will be included in calculations
SetFieldValue("Payment Status", payStatusVerified);
WriteRecord();
sClaimId = GetFieldValue("Claim Id");
currentPayment = GetFieldValue("Amount");
oBCClaim.InvokeMethod("SetAdminMode", "TRUE");
oBCClaim.SetViewMode(AllView);
oBCClaim.ActivateField("CMI Warranty Variance Total - All");
oBCClaim.ActivateField("CMI Balance with Pending Payments");
oBCClaim.ActivateField("CMI Payment Variance Sum");
oBCClaim.ActivateField("CMI Variance Tolerance Level");
oBCClaim.ActivateField("Status Code");
oBCClaim.ActivateField("CMI Pay To");//added by IY795 for enhancement S139
oBCClaim.ActivateField("CMI Early Credit");//added by IY795 for enhancement S139
oBCClaim.ClearToQuery();
oBCClaim.SetSearchSpec("Id", sClaimId);
oBCClaim.ExecuteQuery(ForwardOnly);
TheApplication().Utility.logStep("Process Payment ("+GetFieldValue("Id")+") for "+currentPayment+" - Claim ("+sClaimId+") - Claim found? "+oBCClaim.FirstRecord());
if (oBCClaim.FirstRecord()) {
balanceDue = oBCClaim.GetFieldValue("CMI Balance with Pending Payments");
newBalanceDue = oBCClaim.GetFieldValue("CMI Payment Variance Sum");
iVarToLevel = oBCClaim.GetFieldValue("CMI Variance Tolerance Level");
sPayTo = oBCClaim.GetFieldValue("CMI Pay To");//added by IY795 for S139
sEarlyCredit = oBCClaim.GetFieldValue("CMI Early Credit");//added by IY795 for S139
// sWarVarTotal = oBCClaim.GetFieldValue("CMI Warranty Variance Total");
sWarVarTotal = oBCClaim.GetFieldValue("CMI Warranty Variance Total - All"); //MJB cq8565 Switch to calculation including unverified payments
sCurcyCd = oBCClaim.GetFieldValue("Currency Code");
//added by IY795 for S139 to bypass this logic for PayTo = Customer
TheApplication().Utility.logVars("Pay To", sPayTo, "Early Credit", sEarlyCredit);
if(sPayTo.valueOf() != customerPayTo) {
//Distributor
TheApplication().Utility.logVars("Variance Tolerance Level", iVarToLevel, "Balance - New/All Payments", newBalanceDue+" / "+balanceDue);
if (ToNumber(iVarToLevel) < (-1 * ToNumber(newBalanceDue))) {
//If Balance including this payment is greater than tolerance, just update
//the claim that a payment has been received
TheApplication().SetProfileAttr("ClaimNextStatus", claimStatusRcvd);
oBCClaim.InvokeMethod("ProgressStatus");
} else if (ToNumber(newBalanceDue) == 0) {
//If the Balance including this payment is 0, close the claim
//Check if there are remaining payments in this batch
found = CheckRemainingBatchPayments(oBCPayment, sBatchId, payStatusPending)
TheApplication().Utility.logVars("Close - Remaining Payments?", found);
if (!found) {
TheApplication().SetProfileAttr("ClaimNextStatus", claimStatusClosed);
oBCClaim.InvokeMethod("ProgressStatus");
} else {
TheApplication().SetProfileAttr("ClaimNextStatus", claimStatusRcvd);
oBCClaim.InvokeMethod("ProgressStatus");
}
} else if (ToNumber(iVarToLevel) >= (-1 * ToNumber(newBalanceDue))) {
//If Balance including this payment is under the tolerance or an overpayment
//create a variance for the balance (including unverified payments) and close the claim
//Check if there are remaining payments in this batch
found = CheckRemainingBatchPayments(oBCPayment, sBatchId, payStatusPending)
TheApplication().Utility.logVars("Variance - Remaining Payments?", found);
if (!found) {
oBCPayment.NewRecord(NewAfter);//Changed the value 1 to NewAfter from oracle review <added by> <k0981> on <09-11-2011>
oBCPayment.SetFieldValue("Payment Amount", newBalanceDue);
oBCPayment.SetFieldValue("Payment Type Code", TheApplication().InvokeMethod("LookupValue","CMI_PAYMENT_TYPE","Variance"));
oBCPayment.SetFieldValue("CMI Payment Credit Type", TheApplication().InvokeMethod("LookupValue","CMI_PAY_CDT_TYPE","Consolidate"));//added by Jacky
oBCPayment.SetFieldValue("Payment Status", payStatusVerified);
oBCPayment.WriteRecord();
//Refresh the Claim so the new payment is included in the calculated rollups
//used for validation
oBCClaim.InvokeMethod("RefreshBusComp");
newBalanceDue = oBCClaim.GetFieldValue("CMI Payment Variance Sum");
TheApplication().Utility.logVars("New Balance Due w/ this Variance", newBalanceDue);
TheApplication().SetProfileAttr("ClaimNextStatus", claimStatusClosed);
oBCClaim.InvokeMethod("ProgressStatus");
} else {
TheApplication().SetProfileAttr("ClaimNextStatus", claimStatusRcvd);
oBCClaim.InvokeMethod("ProgressStatus");
}
} else {
//If this is not the last payment for a claim that brings the final balance to 0, just update
//the claim that a payment has been received
TheApplication().SetProfileAttr("ClaimNextStatus", claimStatusRcvd);
oBCClaim.InvokeMethod("ProgressStatus");
}
} else if(sPayTo.valueOf()== customerPayTo && sEarlyCredit.valueOf()== noEarlyCredit) {
// Customer: Invoke the Order creation process from a Claim. Added by KL968 for defect 147
//Added if loop by km326 to fix C&I 4609 Defect on 10/08/2011
TheApplication().Utility.logVars("Previous Claim Id", sPrevClaimId, "Currenct Claim Id", oBCBatchPaymemt.GetFieldValue("Claim Id"));
if(sPrevClaimId != oBCBatchPaymemt.GetFieldValue("Claim Id")) {
var oWFInps = TheApplication().NewPropertySet();
var oWFOutps = TheApplication().NewPropertySet();
var oWFBS = TheApplication().GetService("Workflow Process Manager");
TheApplication().SetProfileAttr("CMIClaimId", sClaimId);
oWFInps.SetProperty("Object Id", sClaimId);
oWFInps.SetProperty("No Early Credit", "Y");
oWFInps.SetProperty("ProcessName", "CMI Warranty Credit Order Creation");
oWFBS.InvokeMethod("RunProcess", oWFInps, oWFOutps);
oWFInps = null;
oWFOutps = null;
oWFBS = null;
}
sPrevClaimId = oBCBatchPaymemt.GetFieldValue("Claim Id");
} else if(sPayTo.valueOf()== customerPayTo && sEarlyCredit.valueOf()== issuedEarlyCredit) {
//Customer - Issue Early Credit
TheApplication().Utility.logVars("Warranty Varriance Total", sWarVarTotal);
if(sWarVarTotal != 0 && sWarVarTotal != null && sWarVarTotal != "") {
//Check if there are remaining payments in this batch. Only create variance when processing last
//payment so Balance Due will be 0 at that time
found = CheckRemainingBatchPayments(oBCPayment, sBatchId, payStatusPending)
TheApplication().Utility.logVars("Customer - Remaining Payments?", found);
if (!found) {
oBCPayment.ActivateField("Payment Amount");
oBCPayment.ActivateField("Payment Type Code");
oBCPayment.ActivateField("Payment Status");
oBCPayment.ActivateField("CMI Payment Credit Type");
oBCPayment.NewRecord(NewAfter);
oBCPayment.SetFieldValue("Payment Type Code", TheApplication().InvokeMethod("LookupValue","CMI_PAYMENT_TYPE","Warranty Credit Variance"));
oBCPayment.SetFieldValue("CMI Payment Credit Type", TheApplication().InvokeMethod("LookupValue","CMI_PAY_CDT_TYPE","Consolidate"));
oBCPayment.SetFieldValue("Payment Amount", sWarVarTotal);
oBCPayment.SetFieldValue("Currency Code", sCurcyCd);
oBCPayment.SetFieldValue("Payment Status", payStatusVerified);
oBCPayment.WriteRecord();
//Claim closure will occur in the GL service triggered by the RT Event commit of the record above
}
} else if(sWarVarTotal == 0) {
TheApplication().SetProfileAttr("ClaimNextStatus", claimStatusClosed);
oBCClaim.InvokeMethod("ProgressStatus");
}
}//else if
}//if
} catch(e) {
Inputs.SetProperty("Is Abort", "True");
txnService.InvokeMethod("EndTransaction", Inputs, Outputs);
throw(e);
}
Inputs.SetProperty("Is Abort", "False");
txnService.InvokeMethod("EndTransaction", Inputs, Outputs);
HasRecord = NextRecord();
}//Loop of payments for a batch
}//with (oBCBatchPaymemt)
oBC.InvokeMethod("RefreshBusComp");
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCPayment = null;
oBCClaim = null;
oBOClaim = null;
oBCBatchPaymemt = null;
oBOBatch = null;
oBC = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Batch Payment Process BS
BatchPaymentCheck
/*************************************************************************************************************************
Created By :
Created On : 12th Feb 2011
Method Name: function BusComp_PreInvokeMethod (MethodName) == "PaymentVarianceCheck"
Functionality: when the user save the record from CMI Claims Payments List Applet,
CMI Claims Payments List Applet will be change,and the Filed Value "Status Code" from the parent Applet will be change.
MJB I do not think this method is called anymore
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function BatchPaymentCheck() {
try {
TheApplication().Utility.logStack("BatchPaymentCheck", this);
var oBO = TheApplication().ActiveBusObject();
var oBCBatch = oBO.GetBusComp("CS HH Deposits");
var sBatchId = oBCBatch.GetFieldValue("Id");
var oBOBatch = TheApplication().GetBusObject("HH CG Deposit Payments");
var oBCBatchPaymemt = oBOBatch.GetBusComp("CS HH FS Payments");
var oBOClaim = TheApplication().GetBusObject("CMI Claims");
var oBCClaim = oBOClaim.GetBusComp("INS Claims");
var oBCClaimPayment = oBOClaim.GetBusComp("INS Claims Payments");
var customerPayTo = TheApplication().InvokeMethod("LookupValue", "CMI_CLAIMS_PAYTO", "Customer");
var noEarlyCredit = TheApplication().InvokeMethod("LookupValue", "CMI_EARLY_CREDIT", "No Early Credit");
var issuedEarlyCredit = TheApplication().InvokeMethod("LookupValue", "CMI_EARLY_CREDIT", "Issued");
var claimStatusClosed = TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Closed");
var claimStatusRcvd = TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Payment Received");
var payStatusPending = TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Pending");
var payStatusVerified = TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Verified");
var payStatusClosed = TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Closed");
var payTypeWarrCrdVar = TheApplication().InvokeMethod("LookupValue","CMI_PAYMENT_TYPE","Warranty Credit Variance");
var payTypeVariance = TheApplication().InvokeMethod("LookupValue","CMI_PAYMENT_TYPE","Variance");
var payCdtTypeConsolidate = TheApplication().InvokeMethod("LookupValue","CMI_PAY_CDT_TYPE","Consolidate");
var iClaimNumber;
var iClaimId;
var balanceDue = 0;
var sVarToLevel;
var sEarlyCredit:String; //added by IY795 for S139
var sPayTo:String; //added by IY795 for S139
var sWarVarTotal;
var sCurcyCd;
with(oBCBatchPaymemt) {
InvokeMethod("SetAdminMode", "TRUE");
SetViewMode(AllView);
ActivateField("Payment Status");
ActivateField("Claim #");
ClearToQuery();
SetSearchSpec("Deposit Id", sBatchId);
ExecuteQuery(ForwardOnly);
var HasRecord = FirstRecord();
while (HasRecord) {
iClaimId = GetFieldValue("Claim Id");
oBCClaim.InvokeMethod("SetAdminMode", "TRUE");
oBCClaim.SetViewMode(AllView);
oBCClaim.ActivateField("CMI Payment Variance Sum");
oBCClaim.ActivateField("CMI Variance Tolerance Level");
oBCClaim.ActivateField("Status Code");
oBCClaim.ActivateField("CMI Pay To"); //added by IY795 for S139
oBCClaim.ActivateField("CMI Early Credit"); //added by IY795 for S139
oBCClaim.ClearToQuery();
oBCClaim.SetSearchSpec("Id", iClaimId);
oBCClaim.ExecuteQuery(ForwardOnly);
if (oBCClaim.FirstRecord()) {
balanceDue = oBCClaim.GetFieldValue("CMI Payment Variance Sum");
sVarToLevel = oBCClaim.GetFieldValue("CMI Variance Tolerance Level");
sPayTo = oBCClaim.GetFieldValue("CMI Pay To"); //added by IY795 for S139
sEarlyCredit = oBCClaim.GetFieldValue("CMI Early Credit");//added by IY795 for S139
sWarVarTotal = oBCClaim.GetFieldValue("CMI Warranty Variance Total");
sCurcyCd = oBCClaim.GetFieldValue("Currency Code");
//added by IY795 for S139 to bypass this logic for PayTo = Customer
if(sPayTo.valueOf() != customerPayTo) {
if (ToNumber(sVarToLevel) < ToNumber(balanceDue)) {
TheApplication().SetProfileAttr("ClaimNextStatus", claimStatusRcvd);
oBCClaim.InvokeMethod("ProgressStatus");
} else if (ToNumber(sVarToLevel) >= ToNumber(balanceDue) &&
ToNumber(balanceDue) > 0) {
oBCClaimPayment.ActivateField("Payment Amount");
oBCClaimPayment.ActivateField("Payment Type Code");
oBCClaimPayment.ActivateField("Payment Status");
oBCClaimPayment.ActivateField("CMI Payment Credit Type");
oBCClaimPayment.NewRecord(NewAfter);//Changed the value 1 to NewAfter from oracle review <added by> <k0981> on <09-11-2011>
oBCClaimPayment.SetFieldValue("Payment Amount", balanceDue);
oBCClaimPayment.SetFieldValue("Payment Type Code", payTypeVariance);
oBCClaimPayment.SetFieldValue("CMI Payment Credit Type", payCdtTypeConsolidate);
oBCClaimPayment.SetFieldValue("Payment Status", payStatusVerified);
oBCClaimPayment.WriteRecord();
TheApplication().SetProfileAttr("ClaimNextStatus", claimStatusClosed);
oBCClaim.InvokeMethod("ProgressStatus");
} else if (ToNumber(balanceDue) == 0) {
TheApplication().SetProfileAttr("ClaimNextStatus", claimStatusClosed);
oBCClaim.InvokeMethod("ProgressStatus");
}
} else if(sPayTo.valueOf()== customerPayTo &&
sEarlyCredit.valueOf()== noEarlyCredit) {
// Invoke the Order creation process from a Claim. Added by KL968 for defect 147
TheApplication().SetProfileAttr("CMIClaimId",iClaimId);
var oWFInps = TheApplication().NewPropertySet();
var oWFOutps = TheApplication().NewPropertySet();
var oWFBS = TheApplication().GetService("Workflow Process Manager");
oWFInps.SetProperty("No Early Credit", "Y");
oWFInps.SetProperty("Object Id", iClaimId);
oWFInps.SetProperty("ProcessName", "CMI Warranty Credit Order Creation");
oWFBS.InvokeMethod("RunProcess", oWFInps, oWFOutps);
} else if(sPayTo.valueOf()== customerPayTo &&
sEarlyCredit.valueOf()== issuedEarlyCredit) {
oBCClaimPayment.ActivateField("Payment Amount");
oBCClaimPayment.ActivateField("Payment Type Code");
oBCClaimPayment.ActivateField("Payment Status");
oBCClaimPayment.ActivateField("CMI Payment Credit Type");
oBCClaimPayment.NewRecord(NewAfter);
oBCClaimPayment.SetFieldValue("Payment Type Code", payTypeWarrCrdVar);
oBCClaimPayment.SetFieldValue("CMI Payment Credit Type", payCdtTypeConsolidate);
oBCClaimPayment.SetFieldValue("Payment Amount", sWarVarTotal);
oBCClaimPayment.SetFieldValue("Currency Code", sCurcyCd);
oBCClaimPayment.SetFieldValue("Payment Status", payStatusVerified);
oBCClaimPayment.WriteRecord();
}//else if
}//if (FirstRecord())
SetFieldValue("Status Code", payStatusClosed);
WriteRecord();
HasRecord = NextRecord();
}// while (HasRecord)
}// with(oBCBatchPaymemt)
oBCBatch.InvokeMethod("RefreshBusComp");
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oWFInps = null;
oWFOutps = null;
oWFBS = null;
oBCClaimPayment = null;
oBCClaim = null;
oBOClaim = null;
oBCBatchPaymemt = null;
oBOBatch = null;
oBCBatch = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Batch Payment Process BS
CheckRemainingBatchPayments
function CheckRemainingBatchPayments(oBCPayment, sBatchId, payStatusPending)
{
try {
TheApplication().Utility.logStack("CheckRemainingBatchPayments", this);
with (oBCPayment) {
oBCPayment.ActivateField("CMI Batch Id");
oBCPayment.ActivateField("Payment Amount");
oBCPayment.ActivateField("Payment Type Code");
oBCPayment.ActivateField("Payment Status");
oBCPayment.ClearToQuery();
oBCPayment.SetSearchSpec("CMI Batch Id", sBatchId);
oBCPayment.SetSearchSpec("Payment Status", payStatusPending);
oBCPayment.ExecuteQuery(ForwardOnly);
var found = oBCPayment.FirstRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(found);
}
return(found);
}

CMI Batch Payment Process BS
PaymentVarianceCheck
function PaymentVarianceCheck() {
try {
TheApplication().Utility.logStack("PaymentVarianceCheck", this);
var boClaim = TheApplication().ActiveBusObject();
var bcClaim = boClaim.GetBusComp("INS Claims");
var bcClaimPayment = boClaim.GetBusComp("INS Claims Payments");
var iClaimTotal;
var balanceDue;
var iVarToLevel;
var sPayTo:String; //added by IY795 for S139
var iPaymentType = bcClaimPayment.GetFieldValue("Payment Type Code");
var customerPayTo = TheApplication().InvokeMethod("LookupValue", "CMI_CLAIMS_PAYTO", "Customer");
var payTypeVariance = TheApplication().InvokeMethod("LookupValue","CMI_PAYMENT_TYPE","Variance");
var claimStatusVariance = TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Variance Created");
var claimStatusClosed = TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Closed");
with(bcClaim) {
balanceDue = GetFieldValue("CMI Payment Variance Sum");
iVarToLevel = GetFieldValue("CMI Variance Tolerance Level");
sPayTo = GetFieldValue("CMI Pay To"); //added by IY795 for S139
if(sPayTo.valueOf() != customerPayTo) {
if (ToNumber(balanceDue)!= 0) {
if(iPaymentType == payTypeVariance) {
TheApplication().SetProfileAttr("ClaimNextStatus", claimStatusVariance);
InvokeMethod("ProgressStatus");
}
} else {
TheApplication().SetProfileAttr("ClaimNextStatus", claimStatusClosed);
InvokeMethod("ProgressStatus");
}
}//end of if(sPayTo.valueOf() != customerPayTo
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcClaimPayment = null;
bcClaim = null;
boClaim = null;
TheApplication().Utility.logUnstack();
}
}

CMI Batch Payment Process BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By :
Created On : 12th Feb 2011
Method Name: function Service_PreInvokeMethod (MethodName) == "BatchCloseProcess"
function Service_PreInvokeMethod (MethodName) == "PaymentVarianceCheck"
function Service_PreInvokeMethod (MethodName) == "RefileCheck"
Functionality: BatchCloseProcess method will be triggered when the user change the field value "CMI Batch Status" from CMI Batch Payment List Applet
PaymentVarianceCheck method will be triggered when the user save the record from CMI Claims Payments List Applet
RefileCheck method will be triggered when the user change the field value "Status Code" from CMI Claims Summary Form Applet
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//try catch added by shanmukh for code clean up 08/21/2011
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if (MethodName == "BatchCloseProcess")
{
BatchCloseProcess();
}
if (MethodName == "PaymentVarianceCheck")
{
PaymentVarianceCheck();
}
if (MethodName == "BatchPaymentCheck")
{
BatchPaymentCheck();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI CTI
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : Dongcheng Gai
Created On : 11th May 2010
Method Name: Transfer
Functionality: Transfer: This method is for change owner
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if (MethodName == "Transfer")
{
//For transfer
var sActivityID;
var boAction;
var bcAction;
var sFullName;
//Get Activity ID
sActivityID = Inputs.GetProperty("ActivityID");
boAction = TheApplication().GetBusObject("Action");
bcAction = boAction.GetBusComp("Action");
with (bcAction)
{
//Query by Activity ID
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sActivityID);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
//Update the CMI Owner FullName field
ActivateField("CMI Owner FullName");
sFullName = TheApplication().GetProfileAttr("Full Name");
SetFieldValue("CMI Owner FullName", sFullName);
WriteRecord();
Outputs.SetProperty("Result","1");
}
}
return(CancelOperation);
}
}// end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " +"ERROR: " + e.errText +"STACK: " + e.toString());
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "ERROR: " + e.errText +"STACK: " + e.toString());
}
}// end of catch
finally
{
//For transfer
sActivityID = null;
boAction = null;
bcAction = null;
sFullName = null;
}
return (ContinueOperation);
}

CMI CTI BS
SaveActivity
/*************************************************************************************************************************
Created By : Leon Qin (JR633)
Created On : 2011-02-26
CMI Rel# : 2
Enhancement No.:
Method Name: SaveActivity
Functionality: Save Activity Id and Start Time in profile
Input: Activity Id, Start Time
Output: Result
************************************************************************************************************************/
function SaveActivity (Inputs, Outputs)
{
try
{
var sActivityId = Inputs.GetProperty("Activity Id");
var sStartTime = Inputs.GetProperty("Start Time");
TheApplication().SetProfileAttr("ActivityId", sActivityId );
TheApplication().SetProfileAttr("StartTime", sStartTime );
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the CTI.SaveActivity\n"+e.errText+"\n"+e.errCode);
}
finally
{
sActivityId =null;
sStartTime =null;
TheApplication().TraceOff();
}
}

CMI CTI BS
SearchContact
/*************************************************************************************************************************
Created By : Leon Qin (JR633)
Created On : 2011-02-22
Updated On : 2011-02-26
CMI Rel# : 2
Enhancement No.:
Method Name: SearchContact
Functionality: Search contact according to work phone number
Input: WorkPhoneNum
Output: Result
************************************************************************************************************************/
function SearchContact (Inputs, Outputs)
{
var ContactBO = TheApplication().GetBusObject("Contact");
var ContactBC = ContactBO.GetBusComp("Contact");
var sWorkPhone = Inputs.GetProperty("WorkPhoneNum");
try
{
ContactBC.ActivateField("Work Phone #");
var sNewWorkPhone = sWorkPhone.substring(0, 7);
var sQuery = "[Work Phone #] LIKE '" +sNewWorkPhone+"*'";
//Query out the contact with initial first 7 digits
with(ContactBC)
{
ClearToQuery();
SetViewMode(AllView);
SetSearchExpr(sQuery);
ExecuteQuery(ForwardBackward);
var iCount = CountRecords();
if(iCount >0)
{
//if find the matched record, then go to matched contact list view
TheApplication().GotoView("Contact List View", ContactBO);
Outputs.SetProperty("Result", "1");
TheApplication().Trace("Count is ="+iCount);
}
else
{
Outputs.SetProperty("Result", "0");
TheApplication().Trace("Count is 0");
}
}
}
catch (e)
{
TheApplication().RaiseErrorText("An exception occurred in the CTI.SearchContact\n"+e.errText+"\n"+e.errCode);
}
finally
{
sWorkPhone = null;
sQuery = null;
ContactBO = null;
ContactBC = null;
iCount = null;
sNewWorkPhone = null;
TheApplication().TraceOff();
}
}

CMI CTI BS
Service_PreCanInvokeMethod
function Service_PreCanInvokeMethod (MethodName, &CanInvoke)
{
//try catch added by shanmukh for code clean up 08/22/2011
try
{
if(MethodName == "SearchContact")
{
CanInvoke = "TRUE";
return (CancelOperation);
}
if(MethodName == "UpdateCallDuration")
{
CanInvoke = "TRUE";
return (CancelOperation);
}
if(MethodName == "SaveActivity")
{
CanInvoke = "TRUE";
return (CancelOperation);
}
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}//end of catch
return (ContinueOperation);
}

CMI CTI BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : Leon Qin (JR633)
Created On : 2011-02-22
Updated On : 2011-03-01
CMI Rel# : 2
Enhancement No.:
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//try catch added by shanmukh for code clean up 08/22/2011
try
{
if(MethodName == "SearchContact")
{
SearchContact (Inputs, Outputs);
return (CancelOperation);
}
if(MethodName == "UpdateCallDuration")
{
UpdateCallDuration (Inputs, Outputs);
return (CancelOperation);
}
if(MethodName == "SaveActivity")
{
SaveActivity (Inputs, Outputs);
return (CancelOperation);
}
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}//end of catch
return (ContinueOperation);
}

CMI CTI BS
UpdateCallDuration
/*************************************************************************************************************************
Created By : Leon Qin (JR633)
Created On : 2011-02-22
Updated On : 2011-02-25
CMI Rel# : 2
Enhancement No.:
Method Name: UpdateCallDuration
Functionality: Update call duration field after release call
Input: TimeOffset
Output: Result
************************************************************************************************************************/
function UpdateCallDuration (Inputs, Outputs)
{
var sActivityId = TheApplication().GetProfileAttr("ActivityId");
var sStartTime = TheApplication().GetProfileAttr("StartTime");
var nTimeOffset = Inputs.GetProperty("TimeOffset");
var BOActivity = TheApplication().GetBusObject("Action");
var BCActivity = BOActivity.GetBusComp("CMI_CTI_BC");
BCActivity.ActivateField("PAR_ROW_ID");
BCActivity.ActivateField("Attrib 14");
var sQuery = "[PAR_ROW_ID] = '" + sActivityId + "'";
if(sActivityId != "" || sActivityId != 0 || sActivityId != null)
{
try
{
//Query out the activity
with(BCActivity)
{
ClearToQuery();
SetViewMode(AllView);
SetSearchExpr(sQuery);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
//var sStartTime = ActionBC.GetFieldValue("Planned");
//Get the end time of call
var sEndDate = new Date();
var sEndTime = Date.parse(new Date());
//Calculate the call duration
var nCallDuration = (sEndTime - Date.parse(sStartTime))/1000;
//Update the call duration field
SetFieldValue("Attrib 14", nCallDuration - nTimeOffset);
WriteRecord();
Outputs.SetProperty("Result", "1");
}
}
}
catch(e)
{
Outputs.SetProperty("Result", "0");
TheApplication().RaiseErrorText("An exception occurred in the CTI.UpdateCallDuration\n"+e.errText+"\n"+e.errCode);
}
finally
{
sActivityId = null;
nCallDuration = null;
BOActivity = null;
BCActivity = null;
TheApplication().TraceOff();
}
}
}

CMI CZ ShellService
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var ret= CancelOperation;
var svc = TheApplication().GetService("CZSessionManagement");
svc.InvokeMethod(MethodName, Inputs, Outputs);
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
svc = null;
TheApplication().Utility.logUnstack(ret);
}
return ret;
}

CMI Cache PropertySet Integration
(declarations)
var psTemp;

CMI Cache PropertySet Integration
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : Pankaj Sinha
Created On : 17th February 2010
Method Name: function Service_PreInvokeMethod
C&I Number : NA
Requirement # : NA
Functionality: This Business Service has methods to Store, Recall and Clear a Property Set. This is useful in case we have
cache a Property Set at the application level.
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if(MethodName == "StorePS")
{
//if (Inputs.GetChildCount() > 0)
{
psTemp = Inputs.Copy();
}
return (CancelOperation);
}
if(MethodName == "RecallPS")
{
Outputs.AddChild(psTemp.Copy());
return (CancelOperation);
}
if(MethodName == "ClearPS")
{
psTemp = null;
return (CancelOperation);
}
}
catch(e)
{
throw e;
}
//Finally block ramoved by ko981 on <06/12/2011>
return (ContinueOperation);
}

CMI Calculate CD EM Charges
CMICurrencyConversion
function CMICurrencyConversion(sSourceCurrCode,sDestCurrCode)
{
/*******************************************************************************************
Created By : Deepak Nanda Kumar (JW919)
Created On : 2011-09-17
C&I Number : req#S041, C&I 4462
Functionality: This Business Service Method is to find the latest currency conversion factor
**********************************************************************************************/
try
{
var oBO:BusObject = TheApplication().GetBusObject("Currency");
var oBC:BusComp = oBO.GetBusComp("Exchange Rate");
var ldcurrtm = Clib.localtime(Clib.time());
var lsmonth = ldcurrtm.tm_mon + 1;
var lsyear = ldcurrtm.tm_year + 1900;
var lsday = ldcurrtm.tm_mday;
var lsCurrentDate = lsmonth + "/" + lsday + "/" + lsyear;
with(oBC)
{
ActivateField("Exchange Rate");
SetViewMode(AllView);
ClearToQuery()
SetSearchSpec("From Currency",sSourceCurrCode);
SetSearchSpec("To Currency",sDestCurrCode);
SetSearchSpec("Exchange Date","<= '" + lsCurrentDate + "'");
SetSortSpec("Exchange Date(DESCENDING)");
ExecuteQuery(ForwardOnly);
while(FirstRecord())
{
return(GetFieldValue("Exchange Rate"));
}
}
}
catch(e)
{
throw(e);
}
finally
{
oBC = null;
oBO = null;
}
}

CMI Calculate CD EM Charges
UpdateSpecialCharges
function UpdateSpecialCharges(sParentQuoteItemId)
{
/*******************************************************************************************
Created By : JW919 - Deepak
Created On : 09/17/2011
C&I Number : C&I 4462. Enhancement# S041
Functionality: This function updates the Special charges field once child CD/EM line item gets deleted.
*******************************************************************************************/
try
{
var oBO:BusObject = TheApplication().GetBusObject("Quote");
var oBC:BusComp = oBO.GetBusComp("Quote Item");
var sParentQuoteItemId = TheApplication().GetProfileAttr("CMI Parent Quote Item Id");
with(oBC)
{
SetViewMode(AllView);
ActivateField("CMI Special Charges");
ClearToQuery()
SetSearchSpec("Id", sParentQuoteItemId);
ExecuteQuery(ForwardOnly)
if(FirstRecord())
{
SetFieldValue("CMI Special Charges", "");
WriteRecord();
}
}
}
catch(e)
{
throw(e);
}
finally
{
oBC = null;
oBO = null;
}
}

CMI Calculate CD EM Charges
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*******************************************************************************************
Created By : JW919 - Deepak
Created On : 16-Sept-2011
C&I Number : 4462.Enhancement# S041
Functionality: This business service gets triggered when triggers the pricecall. Enhancement#S041
**********************************************************************************************/
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if(MethodName == "CalculateCDEMCharges") {
Outputs.SetProperty("CMI Special Charges Error", "");
CMIAddFreight(Inputs, Outputs);
CMIPriceCDEM(Inputs, Outputs);
}
//following method updates the special charges field once Child CD/EM line item gets deleted by user.
else if(MethodName == "UpdateSpecialCharges") {
var sParQuoteItemId = TheApplication().GetProfileAttr("CMI Parent Quote Item Id");
UpdateSpecialCharges(sParQuoteItemId);
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Calculate CD EM Charges
CMIAddFreight
function CMIAddFreight(Inputs,Outputs)
{
/*******************************************************************************************
Created By : Deepak Nanda Kumar (JW919)
Created On : 09/17/2011
C&I Number : C&I 4462. Enhancement# S041
Functionality: This Business Service Method is triggered to add Freight Charges
on Quote Line Items
**********************************************************************************************/
try
{
TheApplication().Utility.logStack("CMIAddFreight", this);
var sQuoteId:String= Inputs.GetProperty("Quote Id");
var psUOMConversionFactor = TheApplication().NewPropertySet();
var sSubType:String= TheApplication().InvokeMethod("LookupValue", "CMI_SUB_TYPE_LOV", "Freight");
var sMtxType:String= TheApplication().InvokeMethod("LookupValue", "CMI_CD_EM", "Freight");
var sReconReturnLineType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type");
var sDropShipLineType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Drop Ship");
var sFreightItemName:String = "Freight Charges";
var iSumWeight:Number = 0;
var iFrieghtCharge:Number = 0;
var sOrgId:String = Inputs.GetProperty("SalesRepOrgId");
var sQHCurrency = Inputs.GetProperty("QHCurrency");
var sOrgCurrency: String = "";
var sOrgWtUOM:String = "Kilogram";
var strCurrQuoteItemId = "";
var strPrevQuoteItemId = "";
var oQuoteO:BusObject = TheApplication().GetBusObject("Quote");
var oQuoteItemBC:BusComp = oQuoteO.GetBusComp("Quote Item (Simple)");
with(oQuoteItemBC) {
//Check if Freight is there
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Line Type");
ActivateField("CMI Weight");
ActivateField("Adjusted List Price");
//CMI DBU Rel#1, Defect#4088, Script: Activated the field so as to avoid nullifying the value in MPO and Net Price by KL968 on 01/06/2011
ActivateField("Unit Price");
SetSearchSpec("Quote Id", sQuoteId);
// SetSearchSpec("CMI Product Sub Type", sSubType);
SetSearchSpec("CMI Calculate Freight Flag", "Y"); //MJB cq4660 switch to non interfaced flag
ExecuteQuery(ForwardBackward);
var QHasRecord = FirstRecord();
TheApplication().Utility.logVars(sSubType+" for Quote ("+sQuoteId+") Found?", QHasRecord);
if(QHasRecord) {
//CMI DBU Release#1, C&I#4462 Script : Block to fetch the Organization Currency only if Freight is there By KL968 On 02/01/2012
//Begin
var oOrgBO = TheApplication().GetBusObject("Internal Division");
var oOrgBC = oOrgBO.GetBusComp("Internal Division");
with(oOrgBC) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Freight Currency Code");
SetSearchSpec("Id", sOrgId);
ExecuteQuery(ForwardBackward);
TheApplication().Utility.logVars("Organization ("+sOrgId+") Found?", FirstRecord());
if(FirstRecord())
{
sOrgCurrency = GetFieldValue("CMI Freight Currency Code");
if(sOrgCurrency == null || sOrgCurrency == "")
{
TheApplication().RaiseError("CMI Currency Check");
}
}
}
//End
//Querying all line items to find sum of weight
//CMI DBU Rel#1, Defect#4088, Script: Got the value of the field to avoid nullifying the value in MPO and Net Price by KL968 on 01/06/2011
var iUnitPrice = GetFieldValue("Unit Price");
var sExpr = "[Quote Id] = '"+sQuoteId+"' AND (([CMI Line Type] <> '"+sReconReturnLineType+"' AND [CMI Line Type] <> '"+sDropShipLineType+"') OR [CMI Line Type] IS NULL)";
var oQuoteO2:BusObject = TheApplication().GetBusObject("Quote");
var oQuoteItemBC2:BusComp = oQuoteO2.GetBusComp("Quote Item");
with(oQuoteItemBC2) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Weight");
ActivateField("Quantity Requested");
ActivateField("CMI Weight UOM");
// SetSearchSpec("Quote Id", sQuoteId);
SetSearchExpr(sExpr);
// SetSearchSpec("CMI Line Type", "<>'"+sReconReturnLineType+"' AND [CMI Line Type]<>'Drop Ship'")//"+sDropShipLineType+"'");
SetSortSpec("Id");
ExecuteQuery(ForwardOnly);
var QHasRecord2 = FirstRecord();
strCurrQuoteItemId = "";
strPrevQuoteItemId = "";
while(QHasRecord2) {
var iProdQuant = ToNumber(GetFieldValue("Quantity Requested"));
var iProdWeight = ToNumber(GetFieldValue("CMI Weight"));
var iProdWtUOM = GetFieldValue("CMI Weight UOM");
strCurrQuoteItemId = GetFieldValue("Id");
if ( strCurrQuoteItemId != strPrevQuoteItemId) {
if(iProdWeight !=null && iProdWeight !="" && iProdWtUOM != null && iProdWtUOM !="") {
var iConvFactor = 0;
if(iProdWtUOM == sOrgWtUOM) {
iConvFactor = 1;
} else {
if(psUOMConversionFactor.PropertyExists("iProdWtUOM")) {
iConvFactor = ToNumber(psUOMConversionFactor.GetProperty("iProdWtUOM"));
} else {
var psIP = TheApplication().NewPropertySet();
var psOP = TheApplication().NewPropertySet();
psIP.SetProperty("FromUOM", iProdWtUOM);
psIP.SetProperty("ToUOM", sOrgWtUOM);
CMIConvertWeight(psIP, psOP);
iConvFactor = ToNumber(psOP.GetProperty("ConversionFactor"));
psUOMConversionFactor.SetProperty("iProdWtUOM", iConvFactor);
}
}
if(iConvFactor == 0)
TheApplication().RaiseErrorText("Weight conversion from '"+iProdWtUOM+"' to '"+ sOrgWtUOM+"' not defined.");
else
iSumWeight = iSumWeight + (iProdWeight * iProdQuant * iConvFactor);
}
}
strPrevQuoteItemId = strCurrQuoteItemId;
QHasRecord2 = NextRecord();
}
}
//Fetch the Freight matrix from New view- Freight Matrix by Querying with Org Id.
//Block to fetch the Freight charge as per matrix
//start
//CMI DBU Rel#1, Defect#4481 Script: Changed the BO so as to base special charges on internal division rather than organization by KL968 on 01/09/2011
//var oFrghtBO = TheApplication().GetBusObject("Organizations");
var oFrghtBO = TheApplication().GetBusObject("Internal Division");
var oFrghtBC = oFrghtBO.GetBusComp("CMI Freight Matrix");
var sVal = 0;
//CMI DBU Rel#1, Defect# DBUNG00004201, Script: Condition added to fetch the frieght matrix only if Sum of Weight is not ZERO by JW919 on 12/22/2011
//CMI DBU Rel#1, Defect# DBUNG00004694, Script: Condition changed from "iSumWeight != 0" to "iSumWeight >= 0" as freight calculation needs to be done for the products having ZERO weight also by KL968 on 02/03/2012
TheApplication().Utility.logVars("Sum Weight", iSumWeight);
if(iSumWeight >= 0 ) {
with(oFrghtBC) {
ActivateField("CMI Value");
ActivateField("CMI Category");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("CMI Organization Id", sOrgId);
SetSearchSpec("CMI Category", sMtxType);
//CMI DBU Rel#1, Defect# DBUNG00004694, Script: Added the below condition so that freight calculation happens for the products having ZERO weight also by KL968 on 02/03/2012
if(iSumWeight == 0) {
SetSearchSpec("CMI Low", "=0");
} else {
SetSearchSpec("CMI Low", "<"+iSumWeight);
}
SetSearchSpec("CMI High", ">="+iSumWeight);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Freight Matrix found?", FirstRecord());
if(FirstRecord()) {
sVal = GetFieldValue("CMI Value");
if(sVal == null || sVal == "") {
TheApplication().RaiseError("CMI Freight Pricing Check");
}
} else {
TheApplication().RaiseError("CMI Freight Pricing Check");
}
}
}
TheApplication().Utility.logVars("Quote Currency", sQHCurrency);
if(sQHCurrency != sOrgCurrency) {
var sCurrConv = CMICurrencyConversion(sOrgCurrency, sQHCurrency);
iFrieghtCharge = ToNumber(sVal) * ToNumber(sCurrConv);
} else {
iFrieghtCharge = ToNumber(sVal);
}
//CMI DBU Rel#1, Defect#4088, Script: Added the condition to avoid nullifying the value in MPO and Net Price by KL968 on 01/06/2011
//Begin
TheApplication().Utility.logVars("Unit Price", iUnitPrice);
if(iUnitPrice == null || iUnitPrice == ""){
SetFieldValue("Unit Price", "");
SetFieldValue("Net Price", iFrieghtCharge);
}
//End
SetFieldValue("CMI EBS Net Price", iFrieghtCharge);
SetFieldValue("Adjusted List Price", iFrieghtCharge);
WriteRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oQuoteItemBC2 = null;
oQuoteO2 = null;
psUOMConversionFactor = null;
oOrgBC = null;
oOrgBO = null;
oFrghtBC = null;
oFrghtBO = null;
oQuoteO= null;
oQuoteItemBC= null;
psIP = null;
psOP = null;
TheApplication().Utility.logUnstack();
}
}

CMI Calculate CD EM Charges
CMIPriceCDEM
function CMIPriceCDEM(Inputs,Outputs)
{
/*******************************************************************************************
Created By : Deepak Nanda Kumar (JW919)
Created On : 09/16/2011
C&I Number : Enhancement# S041, C&I4462.
Functionality: This Function calculates the CD/EM Charges on update the Respective Quote Line items.
**********************************************************************************************/
try
{
TheApplication().Utility.logStack("CMIPriceCDEM", this);
var sQuoteId:String=Inputs.GetProperty("Quote Id");
var sCDEMId:String;
var sCDEMType:String;
var sErrorMsg:String = "";
var oQuoteBO:BusObject=TheApplication().GetBusObject("Quote");
var oQuoteItemBC:BusComp=oQuoteBO.GetBusComp("Quote Item (Simple)");
var sSalesRepOrg:String = Inputs.GetProperty("SalesRepOrgId");
var iCDChargePercent:Number = 0;
var iEMChargePercent:Number = 0;
var strCurrQuoteItemId = "";
var strPrevQuoteItemId = "";
var iSumNetPrice:Number;
var sCDType = TheApplication().InvokeMethod("LookupValue","CMI_CD_EM", "Customer Down");
var sEMType = TheApplication().InvokeMethod("LookupValue","CMI_CD_EM", "Economy");
var sFreightType= TheApplication().InvokeMethod("LookupValue", "CMI_SUB_TYPE_LOV", "Freight");
var sReconLineType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type");
var sReconReturnLineType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type");
//Block to fetch the CD / EM percentages as per matrix
var oFrghtBO = TheApplication().GetBusObject("Internal Division");
var oFrghtBC = oFrghtBO.GetBusComp("CMI Freight Matrix");
with(oFrghtBC) {
ActivateField("CMI Value");
ActivateField("CMI Category");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("CMI Organization Id", sSalesRepOrg);
SetSearchSpec("CMI Category", "='"+sCDType+"' OR [CMI Category] = '"+sEMType+"'");
ExecuteQuery(ForwardOnly);
var HasRecord = FirstRecord();
TheApplication().Utility.logVars("Freight found?", HasRecord);
while(HasRecord)
{
var sCategory = GetFieldValue("CMI Category");
if(sCategory == sCDType)
{
iCDChargePercent = ToNumber(GetFieldValue("CMI Value"));
iCDChargePercent = iCDChargePercent / 100;
}
else if(sCategory == sEMType)
{
iEMChargePercent = ToNumber(GetFieldValue("CMI Value"));
iEMChargePercent = iEMChargePercent / 100;
}
HasRecord = NextRecord();
}
}
//end
//Query wih line item id and find the CD/EMs
var iNetPrice = 0;
var sProdType;
with(oQuoteItemBC)
{
//iSumNetPrice = 0;
ActivateField("Product");
//CMI DBU Rel#1, Script: Activated the field so as to avoid nullifying the value in MPO and Net Price by KL968 on 01/06/2011
ActivateField("Unit Price");
ActivateField("Parent Product Id");
ActivateField("Root Product Id");
ActivateField("Adjusted List Price");
ActivateField("Cost");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Quote Id", sQuoteId);
SetSearchSpec("Product", "='"+sCDType+"' OR [Product] = '"+sEMType+"'");
ExecuteQuery(ForwardOnly);
var HasRecord = FirstRecord();
while(HasRecord)
{
iSumNetPrice = 0;
//CMI DBU Rel#1, Script: Got the value of the field so as to avoid nullifying the value in MPO and Net Price by KL968 on 01/06/2011
var iUnitPrice = GetFieldValue("Unit Price");
var sProdName = GetFieldValue("Product");
var sParProdId = GetFieldValue("Parent Quote Item Id");
//To query all the parent records of current CD/EM records and fetch the Net price from it
//Start
var oQuoteBO2 = TheApplication().GetBusObject("Quote");
var oQuoteItemBC2 = oQuoteBO2.GetBusComp("Quote Item");
if(sParProdId == null || sParProdId == "")
{
// if it is a special charge to be applied on all Quote Items
with(oQuoteItemBC2)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Extended Line Total - Display");
SetSearchSpec("Quote Id", sQuoteId);
SetSearchSpec("CMI Product Sub Type", "<>'"+sFreightType+"' OR [CMI Product Sub Type] IS NULL");
SetSearchSpec("CMI Line Type", "<>'"+sReconReturnLineType+"' OR [CMI Line Type] IS NULL");
SetSearchSpec("Product", "<>'"+sCDType+"' AND [Product] <> '"+sEMType+"'");
ExecuteQuery(ForwardOnly);
var HasRecord2 = oQuoteItemBC2.FirstRecord();
strCurrQuoteItemId = "";
strPrevQuoteItemId = "";
while(HasRecord2)
{
strCurrQuoteItemId = GetFieldValue("Id");
if ( strCurrQuoteItemId != strPrevQuoteItemId)
{
iNetPrice = GetFieldValue("Extended Line Total - Display");
if(iNetPrice == null || iNetPrice == "")
{
//CMI DBU Release#1, Defect#: 3976: raise error commented and the parameter is set to identify by JW919 on 12/20/2011
//TheApplication().RaiseErrorText("Special Charges: Net price is empty for some products. Click Price all and try again");
sErrorMsg = "Error in Special charges";
}
iNetPrice = ToNumber(GetFieldValue("Extended Line Total - Display"));
iSumNetPrice = iSumNetPrice + iNetPrice;
}
strPrevQuoteItemId = strCurrQuoteItemId;
HasRecord2 = oQuoteItemBC2.NextRecord();
}
}
}
else
{
//if it is special charge on selective Item
with(oQuoteItemBC2)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Extended Line Total - Display");
SetSearchSpec("Quote Id", sQuoteId);
SetSearchSpec("CMI Product Sub Type", "<>'"+sFreightType+"' OR [CMI Product Sub Type] IS NULL");
SetSearchSpec("CMI Line Type", "<>'"+sReconReturnLineType+"' OR [CMI Line Type] IS NULL");
SetSearchSpec("Product", "<>'"+sCDType+"' AND [Product] <>'"+sEMType+"'");
SetSearchSpec("Id", "='"+sParProdId+"' OR [Parent Quote Item Id] ='"+sParProdId+"' OR [Root Quote Item Id] ='"+sParProdId+"'");
ExecuteQuery(ForwardOnly);
var HasRecord2 = oQuoteItemBC2.FirstRecord();
strCurrQuoteItemId = "";
strPrevQuoteItemId = "";
while(HasRecord2)
{
strCurrQuoteItemId = GetFieldValue("Id");
if ( strCurrQuoteItemId != strPrevQuoteItemId)
{
iNetPrice = GetFieldValue("Extended Line Total - Display");
if(iNetPrice == null || iNetPrice == "")
{
//CMI DBU Release#1, Defect#: 3976: raise error commented and the parameter is set to identify by JW919 on 12/20/2011
//TheApplication().RaiseErrorText("Special Charges: Net price is empty for some products. Click Price all and try again");
sErrorMsg = "Error in Special charges";
}
iNetPrice = ToNumber(GetFieldValue("Extended Line Total - Display"));
iSumNetPrice = iSumNetPrice + iNetPrice;
}
strPrevQuoteItemId = strCurrQuoteItemId;
HasRecord2 = oQuoteItemBC2.NextRecord();
}
}
}
//end
//update the current CD/EM net price according to the calculated net price from parent
if(sProdName == sCDType)
{
iSumNetPrice = iSumNetPrice * iCDChargePercent;
}
else if (sProdName == sEMType)
{
iSumNetPrice = iSumNetPrice * iEMChargePercent;
}
//Will populate the Prices only if Net price of all the required parent products are populated
if(sErrorMsg == "")
{
SetFieldValue("CMI EBS Net Price", iSumNetPrice);
SetFieldValue("Adjusted List Price", iSumNetPrice);
//CMI DBU Rel#1, Script: Added the condition to avoid nullifying the value in MPO and Net Price by KL968 on 01/06/2011
//Begin
if(iUnitPrice == null || iUnitPrice == "")
{
SetFieldValue("Unit Price", "");
SetFieldValue("Net Price", iSumNetPrice);
}
//End
//CQ Defect 4084 : to get Cost on Price All for Special charges by km101 on 12/15/2011
//CQ Defect 8273 : Commented the changes made for 4084 By kw920 on 06/06/2012.
//SetFieldValue("Cost", iSumNetPrice);
WriteRecord();
}
else
{
Outputs.SetProperty("CMI Special Charges Error", sErrorMsg);
sErrorMsg = "";
SetFieldValue("CMI EBS Net Price", "");
SetFieldValue("Adjusted List Price", "");
//CMI DBU Rel#1, Script: Added the condition to avoid nullifying the value in MPO and Net Price by KL968 on 01/06/2011
//Begin
if(iUnitPrice == null || iUnitPrice == "")
{
SetFieldValue("Unit Price", "");
SetFieldValue("Net Price", iSumNetPrice);
}
//End
//CQ Defect 4084 : to get Cost on Price All for Special charges by km101 on 12/15/2011
SetFieldValue("Cost", "");
WriteRecord();
}
HasRecord = oQuoteItemBC.NextRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oFrghtBC = null;
oFrghtBO = null;
oQuoteItemBC2 = null;
oQuoteBO2 = null;
oQuoteBO= null;
oQuoteItemBC= null;
TheApplication().Utility.logUnstack();
}
}

CMI Calculate CD EM Charges
CMIConvertWeight
function CMIConvertWeight(Inputs, Outputs)
{
/*******************************************************************************************
Created By : Deepak Nanda Kumar (JW919)
Created On : 2011-09-17
C&I Number : Req#S041, C&I 4462
Functionality: This Business Service Method is to find conversion factor for
Weight UOM on line items from LOVs.
**********************************************************************************************/
try
{
var iFromUOM = Inputs.GetProperty("FromUOM");
var iToUOM = Inputs.GetProperty("ToUOM");
var oLOVBO:BusObject = TheApplication().GetBusObject("List Of Values");
var oLOVBC:BusComp = oLOVBO.GetBusComp("List Of Values");
var iConversionFactor:Number = 0;
var sLang = TheApplication().InvokeMethod("Language");
with(oLOVBC)
{
ClearToQuery();
ActivateField("High");
SetSearchSpec("Name", ""+iFromUOM+"_"+iToUOM+"");
SetSearchSpec("Type", "CMI_WEIGHT_CONVERSION");
SetSearchSpec("Language", sLang);
SetViewMode(AllView);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
iConversionFactor = ToNumber(GetFieldValue("High"));
}
else
{
iConversionFactor = 0;
}
Outputs.SetProperty("ConversionFactor", iConversionFactor);
}
}
catch(e)
{
throw(e);
}
finally
{
oLOVBO = null;
oLOVBC = null
}
}

CMI Calculate CD EM Charges - Order
CMIAddFreight
function CMIAddFreight(Inputs,Outputs)
{
/*******************************************************************************************
Created By : Deepak Nanda Kumar (JW919)
Created On : 09/17/2011
C&I Number : C&I 4462. Enhancement# S041
Functionality: This Business Service Method is triggered to add Freight Charges
on Order Line Items
**********************************************************************************************/
try
{
var sOrderId:String= Inputs.GetProperty("Order Id");
var psUOMConversionFactor = TheApplication().NewPropertySet();
var sSubType:String= TheApplication().InvokeMethod("LookupValue", "CMI_SUB_TYPE_LOV", "Freight");
var sMtxType:String= TheApplication().InvokeMethod("LookupValue", "CMI_CD_EM", "Freight");
var sReconReturnLineType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type");
var sFreightItemName:String= "Freight Charges";
var sProductId:String="";
var iSumWeight:Number = 0;
var iFrieghtCharge:Number = 0;
var sOrgId:String = Inputs.GetProperty("SalesRepOrgId");
var sQHCurrency = Inputs.GetProperty("QHCurrency");
var sOrgCurrency: String = "";
var sOrgWtUOM:String = "Kilogram";
var oOrderBO:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var oOrderItemBC:BusComp = oOrderBO.GetBusComp("Order Entry - Line Items (Simple)");
with(oOrderItemBC) {
//Check if Freight is there
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Line Type");
ActivateField("CMI Weight");
ActivateField("Adjusted List Price");
ActivateField("Unit Price");
ActivateField("Unit Price");
SetSearchSpec("Order Header Id", sOrderId);
// SetSearchSpec("CMI Product Sub Type", sSubType);
SetSearchSpec("CMI Calculate Freight Flag", "Y"); //MJB cq4660 switch to non interfaced flag
ExecuteQuery(ForwardOnly);
var QHasRecord = FirstRecord();
if(QHasRecord) {
//CMI DBU Release#1, C&I#4462 Script : Block to fetch the Organization Currency only if Freight is there By KL968 On 02/01/2012
//Begin
var oOrgBO = TheApplication().GetBusObject("Internal Division");
var oOrgBC = oOrgBO.GetBusComp("Internal Division");
with(oOrgBC) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Freight Currency Code");
SetSearchSpec("Id", sOrgId);
ExecuteQuery(ForwardBackward);
if(FirstRecord())
{
sOrgCurrency = GetFieldValue("CMI Freight Currency Code");
if(sOrgCurrency == null || sOrgCurrency == "")
{
TheApplication().RaiseError("CMI Currency Check");
}
}
}
//End
//Querying all line items to find sum of weight
//CMI DBU Rel#1, Script: Got the value of the field so as to avoid nullifying the value in MPO and Net Price by KL968 on 01/06/2011
var iUnitPrice = GetFieldValue("Unit Price");
var oOrderBO2:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var oOrderItemBC2:BusComp = oOrderBO2.GetBusComp("Order Entry - Line Items");
with(oOrderItemBC2)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Unit Weight");
ActivateField("Quantity Requested");
ActivateField("CMI Weight UOM");
SetSearchSpec("Order Header Id", sOrderId);
SetSearchSpec("CMI Line Type", "<>'"+sReconReturnLineType+"' OR [CMI Line Type] IS NULL");
//SetSortSpec("Created");
ExecuteQuery(ForwardOnly);
var QHasRecord2 = FirstRecord();
while(QHasRecord2)
{
var iProdQuant = ToNumber(GetFieldValue("Quantity Requested"));
var iProdWeight = ToNumber(GetFieldValue("CMI Unit Weight"));
var iProdWtUOM = GetFieldValue("CMI Weight UOM");
if(iProdWeight !=null && iProdWeight !="" && iProdWtUOM != null && iProdWtUOM !="")
{
var iConvFactor = 0;
if(iProdWtUOM == sOrgWtUOM)
{
iConvFactor = 1;
}
else
{
if(psUOMConversionFactor.PropertyExists("iProdWtUOM"))
{
iConvFactor = ToNumber(psUOMConversionFactor.GetProperty("iProdWtUOM"));
}
else
{
var psIP = TheApplication().NewPropertySet();
var psOP = TheApplication().NewPropertySet();
psIP.SetProperty("FromUOM", iProdWtUOM);
psIP.SetProperty("ToUOM", sOrgWtUOM);
CMIConvertWeight(psIP, psOP);
iConvFactor = ToNumber(psOP.GetProperty("ConversionFactor"));
psUOMConversionFactor.SetProperty("iProdWtUOM", iConvFactor);
}
}
if(iConvFactor == 0)
TheApplication().RaiseErrorText("Weight conversion from '"+iProdWtUOM+"' to '"+ sOrgWtUOM+"' not defined.");
else
iSumWeight = iSumWeight + (iProdWeight * iProdQuant * iConvFactor);
}
QHasRecord2 = NextRecord();
}
}
//Fetch the Freight matrix from New view- Freight Matrix by Querying with Org Id.
//Block to fetch the Freight charge as per matrix
//start
//CMI DBU Rel#1, Defect#4481 Script: Changed the BO so as to base special charges on internal division rather than organization by KL968 on 01/09/2011
//var oFrghtBO = TheApplication().GetBusObject("Organizations");
var oFrghtBO = TheApplication().GetBusObject("Internal Division");
var oFrghtBC = oFrghtBO.GetBusComp("CMI Freight Matrix");
var sVal = 0;
//CMI DBU Rel#1, Defect# DBUNG00004201, Script: Condition added to fetch the frieght matrix only if Sum of Weight is not ZERO by JW919 on 12/22/2011
//CMI DBU Rel#1, Defect# DBUNG00004694, Script: Condition changed from "iSumWeight != 0" to "iSumWeight >= 0" as freight calculation needs to be done for the products having ZERO weight also by KL968 on 02/03/2012
if(iSumWeight >= 0 )
{
with(oFrghtBC)
{
ActivateField("CMI Value");
ActivateField("CMI Category");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("CMI Organization Id", sOrgId);
SetSearchSpec("CMI Category", sMtxType);
//CMI DBU Rel#1, Defect# DBUNG00004694, Script: added the condition so that the freight calculation happens for the products having ZERO weight also by KL968 on 02/03/2012
//Begin
if(iSumWeight == 0)
{
SetSearchSpec("CMI Low", "=0");
}
else
{
SetSearchSpec("CMI Low", "<"+iSumWeight);
}
//End
SetSearchSpec("CMI High", ">="+iSumWeight);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sVal = GetFieldValue("CMI Value");
if(sVal == null || sVal == "")
{
//CMI DBU Rel#1, Defect#4481 Script: Using RaiseError instead of RaiseErorrText by KL968 on 01/09/2011
//Begin
//TheApplication().RaiseErrorText("The Freight matrix does not contain equivalent Price for Total weight. Kindly contact the Administrator to setup the values and try again.");
TheApplication().RaiseError("CMI Freight Pricing Check");
//End
}
}
else
{
//CMI DBU Rel#1, Defect#4481 Script: Using RaiseError instead of RaiseErorrText by KL968 on 01/09/2011
//Begin
//TheApplication().RaiseErrorText("The Freight matrix does not contain equivalent Price for Total weight. Kindly contact the Administrator to setup the values and try again.");
TheApplication().RaiseError("CMI Freight Pricing Check");
//End
}
}
}
//end
if(sQHCurrency != sOrgCurrency)
{
var sCurrConv = CMICurrencyConversion(sOrgCurrency, sQHCurrency);
iFrieghtCharge = ToNumber(sVal) * ToNumber(sCurrConv);
}
else
{
iFrieghtCharge = ToNumber(sVal);
}
//CMI DBU Rel#1, Script: Added the condition to avoid nullifying the value in MPO and Net Price by KL968 on 01/06/2011
//Begin
if(iUnitPrice == null || iUnitPrice == "")
{
SetFieldValue("Unit Price", "");
SetFieldValue("Net Price", iFrieghtCharge);
}
//End
SetFieldValue("CMI EBS Net Price", iFrieghtCharge);
SetFieldValue("Adjusted List Price", iFrieghtCharge);
WriteRecord();
}
}
}
catch(e)
{
throw e;
}
finally
{
oOrderItemBC2 = null;
oOrderBO2 = null;
oFrghtBC = null;
oFrghtBO = null;
oOrgBC = null;
oOrgBO = null;
psUOMConversionFactor = null;
oOrderBO= null;
oOrderItemBC= null;
psIP = null;
psOP = null;
}
}

CMI Calculate CD EM Charges - Order
CMIConvertWeight
function CMIConvertWeight(Inputs, Outputs)
{
/*******************************************************************************************
Created By : Deepak Nanda Kumar (JW919)
Created On : 2011-09-17
C&I Number : Req#S041, C&I 4462
Functionality: This Business Service Method is to find conversion factor for
Weight UOM on line items from LOVs.
**********************************************************************************************/
try
{
var iFromUOM = Inputs.GetProperty("FromUOM");
var iToUOM = Inputs.GetProperty("ToUOM");
var oLOVBO:BusObject = TheApplication().GetBusObject("List Of Values");
var oLOVBC:BusComp = oLOVBO.GetBusComp("List Of Values");
var iConversionFactor:Number = 0;
var sLang = TheApplication().InvokeMethod("Language");
with(oLOVBC)
{
ClearToQuery();
ActivateField("High");
SetSearchSpec("Name", ""+iFromUOM+"_"+iToUOM+"");
SetSearchSpec("Type", "CMI_WEIGHT_CONVERSION");
SetSearchSpec("Language", sLang);
SetViewMode(AllView);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
iConversionFactor = ToNumber(GetFieldValue("High"));
}
else
{
iConversionFactor = 0;
}
Outputs.SetProperty("ConversionFactor", iConversionFactor);
}
}
catch(e)
{
throw(e);
}
finally
{
oLOVBO = null;
oLOVBC = null
}
}

CMI Calculate CD EM Charges - Order
CMICurrencyConversion
function CMICurrencyConversion(sSourceCurrCode,sDestCurrCode)
{
/*******************************************************************************************
Created By : Deepak Nanda Kumar (JW919)
Created On : 2011-09-17
C&I Number : req#S041, C&I 4462
Functionality: This Business Service Method is to find the latest currency conversion factor
**********************************************************************************************/
try
{
var oBO:BusObject = TheApplication().GetBusObject("Currency");
var oBC:BusComp = oBO.GetBusComp("Exchange Rate");
var ldcurrtm = Clib.localtime(Clib.time());
var lsmonth = ldcurrtm.tm_mon + 1;
var lsyear = ldcurrtm.tm_year + 1900;
var lsday = ldcurrtm.tm_mday;
var lsCurrentDate = lsmonth + "/" + lsday + "/" + lsyear;
with(oBC)
{
ActivateField("Exchange Rate");
SetViewMode(AllView);
ClearToQuery()
SetSearchSpec("From Currency",sSourceCurrCode);
SetSearchSpec("To Currency",sDestCurrCode);
SetSearchSpec("Exchange Date","<= '" + lsCurrentDate + "'");
SetSortSpec("Exchange Date(DESCENDING)");
ExecuteQuery(ForwardOnly);
while(FirstRecord())
{
return(GetFieldValue("Exchange Rate"));
}
}
}
catch(e)
{
throw(e);
}
finally
{
oBC = null;
oBO = null;
}
}

CMI Calculate CD EM Charges - Order
CMIPriceCDEM
function CMIPriceCDEM(Inputs,Outputs)
{
/*******************************************************************************************
Created By : Deepak Nanda Kumar (JW919)
Created On : 09/16/2011
C&I Number : Enhancement# S041, C&I4462.
Functionality: This Function calculates the CD/EM Charges on update the Respective Order Line items.
**********************************************************************************************/
try {
var sOrderId:String=Inputs.GetProperty("Order Id");
var sCDEMId:String;
var sCDEMType:String;
var sErrorMsg:String = "";
var oOrderBO:BusObject=TheApplication().GetBusObject("Order Entry (Sales)");
var oOrderItemBC:BusComp = oOrderBO.GetBusComp("Order Entry - Line Items");
var sSalesRepOrg:String = Inputs.GetProperty("SalesRepOrgId");
var iCDChargePercent:Number = 0;
var iEMChargePercent:Number = 0;
var iSumNetPrice:Number;
var sCDType = TheApplication().InvokeMethod("LookupValue","CMI_CD_EM", "Customer Down");
var sEMType = TheApplication().InvokeMethod("LookupValue","CMI_CD_EM", "Economy");
var sFreightType:String= TheApplication().InvokeMethod("LookupValue", "CMI_SUB_TYPE_LOV", "Freight");
var sReconLineType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type");
var sReconReturnLineType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type");
//Block to fetch the CD / EM percentages as per matrix
var oFrghtBO = TheApplication().GetBusObject("Internal Division");
var oFrghtBC = oFrghtBO.GetBusComp("CMI Freight Matrix");
with(oFrghtBC)
{
ActivateField("CMI Value");
ActivateField("CMI Category");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("CMI Organization Id", sSalesRepOrg);
SetSearchSpec("CMI Category", "='"+sCDType+"' OR [CMI Category] = '"+sEMType+"'");
ExecuteQuery(ForwardOnly);
var HasRecord = FirstRecord();
while(HasRecord)
{
var sCategory = GetFieldValue("CMI Category");
if(sCategory == sCDType)
{
iCDChargePercent = ToNumber(GetFieldValue("CMI Value"));
iCDChargePercent = iCDChargePercent / 100;
}
else if(sCategory == sEMType)
{
iEMChargePercent = ToNumber(GetFieldValue("CMI Value"));
iEMChargePercent = iEMChargePercent / 100;
}
HasRecord = NextRecord();
}
}
//end
//Query wih line item id and find the CD/EMs
var iNetPrice = 0;
var sProdType;
with(oOrderItemBC)
{
iSumNetPrice = 0;
ActivateField("Product");
ActivateField("Parent Product Id");
ActivateField("Root Product Id");
//CMI DBU Rel#1, Script: Activated the field so as to avoid nullifying the value in MPO and Net Price by KL968 on 01/06/2011
ActivateField("Unit Price");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Order Header Id", sOrderId);
SetSearchSpec("Product", "='"+sCDType+"' OR [Product] = '"+sEMType+"'");
ExecuteQuery(ForwardOnly);
var HasRecord = FirstRecord();
while(HasRecord)
{
//CMI DBU Rel#1, Script: Got the value of the field so as to avoid nullifying the value in MPO and Net Price by KL968 on 01/06/2011
var iUnitPrice = GetFieldValue("Unit Price");
var sProdName = GetFieldValue("Product");
var sParProdId = GetFieldValue("Parent Order Item Id");
//To query all the parent records of current CD/EM records and fetch the Net price from it
//Start
var oOrderBO2 = TheApplication().GetBusObject("Order Entry (Sales)");
var oOrderItemBC2 = oOrderBO2.GetBusComp("Order Entry - Line Items");
if(sParProdId == null || sParProdId == "")
{
// if it is a special charge to be applied on all Order Items
with(oOrderItemBC2)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Extended Line Total - Display");
SetSearchSpec("Order Header Id", sOrderId);
SetSearchSpec("CMI Product Sub Type", "<>'"+sFreightType+"' OR [CMI Product Sub Type] IS NULL");
SetSearchSpec("CMI Line Type", "<>'"+sReconReturnLineType+"' OR [CMI Line Type] IS NULL");
SetSearchSpec("Product", "<>'"+sCDType+"' AND [Product] <> '"+sEMType+"'");
ExecuteQuery(ForwardOnly);
var HasRecord2 = oOrderItemBC2.FirstRecord();
while(HasRecord2)
{
iNetPrice = GetFieldValue("Extended Line Total - Display");
if(iNetPrice == null || iNetPrice == "")
{
//CMI DBU Release#1, Defect#: 3976: raise error commented and the parameter is set to identify by JW919 on 12/20/2011
//TheApplication().RaiseErrorText("Special Charges: Net price is empty for some products. Click Price all and try again");
sErrorMsg = "Error in Special charges";
}
iNetPrice = ToNumber(GetFieldValue("Extended Line Total - Display"));
iSumNetPrice = iSumNetPrice + iNetPrice;
HasRecord2 = oOrderItemBC2.NextRecord();
}
}
}
else
{
//if it is special charge on selective Item
with(oOrderItemBC2)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Extended Line Total - Display");
SetSearchSpec("Order Header Id", sOrderId);
SetSearchSpec("CMI Product Sub Type", "<>'"+sFreightType+"' OR [CMI Product Sub Type] IS NULL");
SetSearchSpec("CMI Line Type", "<>'"+sReconReturnLineType+"' OR [CMI Line Type] IS NULL");
SetSearchSpec("Product", "<>'"+sCDType+"' AND [Product] <>'"+sEMType+"'");
SetSearchSpec("Id", "='"+sParProdId+"' OR [Parent Order Item Id] ='"+sParProdId+"' OR [Root Order Item Id] ='"+sParProdId+"'");
ExecuteQuery(ForwardOnly);
var HasRecord2 = oOrderItemBC2.FirstRecord();
while(HasRecord2)
{
iNetPrice = GetFieldValue("Extended Line Total - Display");
if(iNetPrice == null || iNetPrice == "")
{
//CMI DBU Release#1, Defect#: 3976: raise error commented and the parameter is set to identify by JW919 on 12/20/2011
//TheApplication().RaiseErrorText("Special Charges: Net price is empty for some products. Click Price all and try again");
sErrorMsg = "Error in Special charges";
}
iNetPrice = ToNumber(GetFieldValue("Extended Line Total - Display"));
iSumNetPrice = iSumNetPrice + iNetPrice;
HasRecord2 = oOrderItemBC2.NextRecord();
}
}
}
//end
//update the current CD/EM net price according to the calculated net price from parent
if(sProdName == sCDType)
{
iSumNetPrice = iSumNetPrice * iCDChargePercent;
}
else if (sProdName == sEMType)
{
iSumNetPrice = iSumNetPrice * iEMChargePercent;
}
//Will populate the Prices only if Net price of all the required parent products are populated
if(sErrorMsg == "")
{
SetFieldValue("CMI EBS Net Price", iSumNetPrice);
SetFieldValue("Adjusted List Price", iSumNetPrice);
//CMI DBU Rel#1, Script: Added the condition to avoid nullifying the value in MPO and Net Price by KL968 on 01/06/2011
//Begin
if(iUnitPrice == null || iUnitPrice == "")
{
SetFieldValue("Unit Price", "");
SetFieldValue("Net Price", iSumNetPrice);
}
//End
WriteRecord();
}
else
{
Outputs.SetProperty("CMI Special Charges Error", sErrorMsg);
sErrorMsg = "";
SetFieldValue("CMI EBS Net Price", "");
SetFieldValue("Adjusted List Price", "");
//CMI DBU Rel#1, Script: Added the condition to avoid nullifying the value in MPO and Net Price by KL968 on 01/06/2011
//Begin
if(iUnitPrice == null || iUnitPrice == "")
{
SetFieldValue("Unit Price", "");
SetFieldValue("Net Price", iSumNetPrice);
}
//End
WriteRecord();
}
HasRecord = oOrderItemBC.NextRecord();
}
}
}
catch(e)
{
throw(e);
}
finally
{
oFrghtBC = null;
oFrghtBO = null;
oOrderItemBC2 = null;
oOrderBO2 = null;
oOrderBO= null;
oOrderItemBC= null;
}
}

CMI Calculate CD EM Charges - Order
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*******************************************************************************************
Created By : JW919 - Deepak
Created On : 16-Sept-2011
C&I Number : 4462.Enhancement# S041
Functionality: This business service gets triggered when triggers the pricecall. Enhancement#S041
**********************************************************************************************/
try
{
if(MethodName == "CalculateCDEMCharges")
{
CMIAddFreight(Inputs, Outputs);
CMIPriceCDEM(Inputs, Outputs);
return(CancelOperation);
}
//following method updates the special charges field once Child CD/EM line item gets deleted by user.
if(MethodName == "UpdateSpecialCharges")
{
var sParQuoteItemId = TheApplication().GetProfileAttr("CMI Parent Order Item Id");
UpdateSpecialCharges(sParQuoteItemId);
return(CancelOperation);
}
return (ContinueOperation);
}
catch(e)
{
throw e;
}
}

CMI Calculate CD EM Charges - Order
UpdateSpecialCharges
function UpdateSpecialCharges(sParentQuoteItemId)
{
/*******************************************************************************************
Created By : JW919 - Deepak
Created On : 09/17/2011
C&I Number : C&I 4462. Enhancement# S041
Functionality: This function updates the Special charges field once child CD/EM line item gets deleted.
*******************************************************************************************/
try
{
var oBO:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var oBC:BusComp = oBO.GetBusComp("Order Entry - Line Items");
var sParentQuoteItemId = TheApplication().GetProfileAttr("CMI Parent Quote Item Id");
with(oBC)
{
SetViewMode(AllView);
ActivateField("CMI Special Charges");
ClearToQuery()
SetSearchSpec("Id", sParentQuoteItemId);
ExecuteQuery(ForwardOnly)
if(FirstRecord())
{
SetFieldValue("CMI Special Charges", "");
WriteRecord();
}
}
}
catch(e)
{
throw(e);
}
finally
{
oBC = null;
oBO = null;
}
}

CMI Calculate Price BS
CalculatePrice
/*************************************************************************************************************************
Created By : Pankaj Kide
Created On : 30th July 2010
Method Name: function CalculatePrice
Functionality: This method set the Net Price on Quote Line Item.
************************************************************************************************************************/
function CalculatePrice(Inputs) {
try {
TheApplication().Utility.logStack("CalculatePrice", this);
var sBO = TheApplication().GetBusObject("Quote");
var sId = Inputs.GetProperty("RowId");
var sInputMargin= Inputs.GetProperty("InputMargin");
var sItemBC = sBO.GetBusComp("Quote Item (Simple)");
var isRecord, isItemRecord;
var sCost, sDisAmt, unitPrice;
var sProdType;
var sRetainListPrice, sCostCalc;
var sSSAField;//Added:JQ486
var sEBSPrice; // Added : To consider EBS Net Price instead of Start Price when 'Retain PRicelist' flag set.
TheApplication().Utility.logId("Quote", sId);
TheApplication().Utility.logVars("Input Margin", sInputMargin);
//The Quote Item (Simple) BC is used to avoid triggering pricing logic. This means that all pricing fields
//must be set manually. The quote is not instantiated to avoid extra queries caused by header level MV Sums
with(sItemBC) {
SetViewMode(AllView);
ActivateField("Cost");
ActivateField("CMI Write In Identifier");
ActivateField("CMI Retain List Price Flag");
ActivateField("Unit Price");
ActivateField("Net Price");
ActivateField("Pricing Adjustment Amount");
ActivateField("CMI SSA Amount");//Added:JQ486
ActivateField("CMI EBS Net Price"); //Added on Mar03
ClearToQuery();
SetSearchSpec("Quote Id", sId);
ExecuteQuery(ForwardBackward);
isItemRecord = FirstRecord();
while(isItemRecord) {
sProdType = GetFieldValue("Product Type");
sRetainListPrice = GetFieldValue("CMI Retain List Price Flag");
sCost = GetFieldValue("Cost");
sCostCalc = (GetFieldValue("CMI Write In Identifier") == "Yes" ? "N" : "Y") ;
sSSAField = GetFieldValue("CMI SSA Amount");
sEBSPrice = GetFieldValue("CMI EBS Net Price");
unitPrice = GetFieldValue("Unit Price");
TheApplication().Utility.logStep("Process Line "+GetFieldValue("Line Number")+" ("+GetFieldValue("Id")+") - Retain List Price / Write In Product: "+sRetainListPrice+" / "+sCostCalc, 4);
if(sRetainListPrice == "N" || sRetainListPrice == "" || sRetainListPrice == null) {
sDisAmt = SetLIPrice(sInputMargin,sCost,sSSAField);
TheApplication().Utility.logStep(" Set Unit Price to "+sDisAmt+" from "+unitPrice, 4);
SetFieldValue("Unit Price",sDisAmt);
//since using Simple BC, must set these fields explicitly, since Pricing WF will not be triggered
SetFieldValue("Net Price", sDisAmt);
SetFieldValue("Pricing Adjustment Amount", -1 * sDisAmt);
//CMI DBU RElease#1, Config: the condition changed to ='N' from ='Y' by JW919 on 11/21/2011
if(sCostCalc == "N") {
SetFieldValue("Cost",sCost);
}
} else {
TheApplication().Utility.logStep(" Set Unit Price to "+sEBSPrice+" from "+unitPrice, 4);
SetFieldValue("Unit Price", sEBSPrice); //Added Mar03
//since using Simple BC, must set these fields explicitly, since Pricing WF will not be triggered
SetFieldValue("Net Price", sEBSPrice);
SetFieldValue("Pricing Adjustment Amount", -1 * sEBSPrice);
//CMI DBU RElease#1, Config: the condition changed to ='N' from ='Y' by JW919 on 11/21/2011
if(sCostCalc == "N") {
SetFieldValue("Cost",sCost);
}
}
WriteRecord();
isItemRecord = NextRecord();
}//end of isItemRecord
}//end of Quote Item BC query
// TheApplication().ActiveBusObject().GetBusComp("Quote").InvokeMethod("RefreshBusComp");
//This service.method is triggered via button click on the quote view so the active bus object will always work
//Trigger the pricing refresh totals signal so total matches the new rollup of unit prices
if (TheApplication().GetProfileAttr("sPriceRollUp") == "Y")// RR 08/17/2013:: Added for CQ 12063
{
with (TheApplication().ActiveBusObject().GetBusComp("Quote")) {
ClearToQuery();
if (sId != "") {
SetSearchSpec("Id", sId);
}
ExecuteQuery();
}
}
else{
with (TheApplication().ActiveBusObject().GetBusComp("Quote")) {
SetFieldValue("CMI Refresh Rollups", GetFieldValue("TimeStamp"));
WriteRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sItemBC = null;
sBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Calculate Price BS
OptionPricing
/*************************************************************************************************************************
Created By : Marco Wang
Created On : 10th December 2010
Method Name: function OptionPricing
Functionality: This method set the Option Quote Total, Option Total Cost
Input: Quote Id
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function OptionPricing(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("OptionPricing", this);
var sQuoteId = Inputs.GetProperty("Quote Id");
var sOption;
var sOptionPrice = 0;
var sOptionCost = 0;
var sOptionSSAAmount = 0;
var sOptionPriceTotal = 0;
var sOptionCostTotal = 0;
var sOptionSSAAmountTotal = 0;
var sQty;
var sParentQty;
var sParentQuoteItemId;
var oBO = TheApplication().ActiveBusObject();
var oBC = oBO.GetBusComp("Quote");
var oBCItem = oBO.GetBusComp("Quote Item");
var oBOQuote = TheApplication().GetBusObject("Quote");
var oBCQuoteItem = oBOQuote.GetBusComp("Quote Item");
var oBOQuoteCal = TheApplication().GetBusObject("Quote");
var oBCQuoteItemCal = oBOQuoteCal.GetBusComp("Quote Item");
with(oBCQuoteItem) {
SetViewMode(AllView);
ActivateField("Product Type");//JQ486:Changing Code. Product Type Def Code is replaced.
ActivateField("Quote Id");
ActivateField("CMI Option");
ActivateField("CMI Total Cost");
ActivateField("CMI Quote Total");
ActivateField("CMI SSA Amount Option Total");
ClearToQuery();
SetSearchSpec("Product Type", "Wholegoods");//JQ486:Changing Code. Product Type Def Code is replaced.
SetSearchSpec("Quote Id", sQuoteId);
ExecuteQuery(ForwardOnly);
// var iCount = CountRecords();//Commented by ko981 on 10/11/11 to improve performance
var HasRecord = FirstRecord();
while (HasRecord)
{
sOptionPriceTotal = 0;
sOptionCostTotal = 0;
sOptionSSAAmountTotal = 0;
sOption = GetFieldValue("CMI Option");
sParentQuoteItemId = GetFieldValue("Parent Quote Item Id");
with(oBCQuoteItemCal)
{
sOptionPrice = 0;
sOptionCost = 0;
sOptionSSAAmount = 0;
SetViewMode(AllView);
ActivateField("Quote Id");
ActivateField("CMI Option");
ActivateField("Net Price");
ActivateField("Extended Quantity Requested");
ActivateField("Cost");
ActivateField("Parent Quote Item Id");
ActivateField("Root Quote Item Id");
ActivateField("CMI SSA Amount");
ClearToQuery();
SetSearchSpec("Quote Id", sQuoteId);
SetSearchSpec("CMI Option", sOption);
ExecuteQuery(ForwardOnly);
var HasOptionRecord = FirstRecord();
while (HasOptionRecord)
{
sQty = GetFieldValue("Extended Quantity Requested");
sOptionPrice = GetFieldValue("Net Price");
sOptionCost = GetFieldValue("Cost");
sOptionSSAAmount = GetFieldValue("CMI SSA Amount");
sOptionSSAAmount = ToNumber(sOptionSSAAmount); //*ToNumber(sQty); CQ 7241 KPK
sOptionPrice = ToNumber(sOptionPrice)*ToNumber(sQty);
sOptionCost = ToNumber(sOptionCost)*ToNumber(sQty);
sOptionPriceTotal = ToNumber(sOptionPriceTotal)+ToNumber(sOptionPrice);
sOptionCostTotal = ToNumber(sOptionCostTotal)+ToNumber(sOptionCost);
sOptionSSAAmountTotal = ToNumber(sOptionSSAAmountTotal)+ToNumber(sOptionSSAAmount);
HasOptionRecord = NextRecord();
}
}
if (sOptionSSAAmountTotal == "" || sOptionSSAAmountTotal == null)
sOptionSSAAmountTotal = 0;
if (sParentQuoteItemId == "" || sParentQuoteItemId == null)
{
sOptionCostTotal = sOptionCostTotal - sOptionSSAAmountTotal; //CQ 7241 KPK
SetFieldValue("CMI Quote Total", sOptionPriceTotal);
SetFieldValue("CMI Total Cost", sOptionCostTotal);
SetFieldValue("CMI SSA Amount Option Total", sOptionSSAAmountTotal);
WriteRecord();
}
HasRecord = NextRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCItem.InvokeMethod("RefreshBusComp");
oBC.InvokeMethod("RefreshBusComp");
oBCItem.InvokeMethod("ExpandAll");
oBC = null;
oBCItem = null;
oBO = null;
oBCQuoteItemCal = null;
oBOQuoteCal = null;
oBCQuoteItem = null;
oBOQuote = null;
TheApplication().Utility.logUnstack();
}
}

CMI Calculate Price BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : Pankaj Kide
Created On : 30th July 2010
Method Name: function BusComp_PreInvokeMethod (MethodName) == "CalculatePrice"
Functionality: This method will be triggered when the user clicks the "Calculate Price button from Quote Form Applet
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if(MethodName == "CalculatePrice") {
CalculatePrice(Inputs);
}
if(MethodName == "WholegoodsItemPrice") { //added by Elen Yu
WholegoodsItemPrice(Inputs, Outputs);
}
if(MethodName == "OptionPricing") {
OptionPricing(Inputs, Outputs);
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Calculate Price BS
SetLIPrice
/*************************************************************************************************************************
Created By : Pankaj Kide
Created On : 30th July 2010
Method Name: function SetLIPrice
Functionality: This method calculates the value for net Price based on the formaula.
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function SetLIPrice(sInputMargin,sCost,sSSAField)
{
try
{
TheApplication().Utility.logStack("SetLIPrice", this, 4);
var sMargin = ToNumber(sInputMargin);
var sItemCost = ToNumber(sCost);
var sSSA = ToNumber(sSSAField);
//JQ486: For Calculating ManualPriceOveride in case of SSA
if(sSSA == "" || sSSA == null) {
sSSA = 0;
}
var sManualPriceOveride;
//building the formula --
//Manual Price Override : [(Cost for each product)/(1-(input margin percentage/100))]
var temp = sMargin/100;
var temp2 = 1 - temp;
//JQ486: Including SSA
TheApplication().Utility.logVars("(Item Cost - SSA Amount)/ (1 - Margin%)", "("+sItemCost+" - "+sSSA+")/ "+temp2, 4);
sManualPriceOveride = (sItemCost - sSSA)/temp2;
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(sManualPriceOveride, 4);
}
return(sManualPriceOveride);
}

CMI Calculate Price BS
WholegoodsItemPrice
/*************************************************************************************************************************
Created By : Elen Yu
Created On : 10th November 2010
Method Name: function WholegoodsItemPrice
Functionality: This method set the CMI Quote Total on Quote Item.
Input: Quote Item Id
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function WholegoodsItemPrice(Inputs, Outputs)
{
try
{
Outputs.SetProperty("Error Code", "0");
Outputs.SetProperty("Error Message", "");
var sItemId = Inputs.GetProperty("Item Id");
var sQuoteId = Inputs.GetProperty("Quote Id");
var sInputMargin = Inputs.GetProperty("CMI Input Margin");
//CMI DBU Rel#1, defect# 290, Config: Activebusobject changed to getbusobject by JW919 on 11/25/2011
//var oBOQuote = TheApplication().ActiveBusObject();
var oBOQuote = TheApplication().GetBusObject("Quote");
var oBCQuote = oBOQuote.GetBusComp("Quote");
var oBCQuoteItem = oBOQuote.GetBusComp("Quote Item");
var sTotalCost;
var sQuoteTotal;
var sCost;
var sDisAmt;
var isRecord;
var isItemRecord;
var sSearchString;
var sRetainListPrice;
var ParentQuoteItemId;
var sSSAField;//Added:JQ486
with(oBCQuote)
{
SetViewMode(AllView);
ClearToQuery()
SetSearchSpec("Id", sQuoteId);
ExecuteQuery(ForwardBackward);
isRecord = FirstRecord();
with(oBCQuoteItem)
{
SetViewMode(AllView);
ActivateField("Cost");
ActivateField("CMI Retain List Price Flag");
ActivateField("Unit Price");
ActivateField("CMI Total Cost");
ActivateField("CMI SSA Amount");//Added:JQ486
ActivateField("CMI SSA Amount Option Total");
ClearToQuery();
sSearchString = "[Quote Id] = '" + sQuoteId + "' AND ([Root Quote Item Id] = '" + sItemId + "' OR [Parent Quote Item Id] = '" + sItemId + "')";
SetSearchExpr(sSearchString);
ExecuteQuery(ForwardBackward);
isItemRecord = FirstRecord();
while(isItemRecord)
{
ParentQuoteItemId = GetFieldValue("Parent Quote Item Id");
sTotalCost = GetFieldValue("CMI Total Cost");
sCost = GetFieldValue("Cost");
sRetainListPrice = GetFieldValue("CMI Retain List Price Flag");
sSSAField = GetFieldValue("CMI SSA Amount");//Added:JQ486
if(sRetainListPrice == "N" || sRetainListPrice == "" || sRetainListPrice == null)
{
sDisAmt = SetLIPrice(sInputMargin,sCost,sSSAField);//Passing sSSAField:JQ486
SetFieldValue("Unit Price",sDisAmt);
WriteRecord();
}
//--START--Commented out the following code for defect#6123 as per confirmation from FCs by KM331
/*if (ParentQuoteItemId == "" || ParentQuoteItemId == null)
{
if (sTotalCost != "" && sTotalCost != null)
{
sQuoteTotal = SetLIPrice(sInputMargin, sTotalCost,sSSAField); //invoke the SetLIPrice function to calculate the value
SetFieldValue("CMI Quote Total", sQuoteTotal); //set the value of CMI Total Cost
WriteRecord();
}
}*/
//--END
isItemRecord = NextRecord();
}//end of isItemRecord
}
}
with(oBCQuoteItem)
{
SetViewMode(AllView);
ClearToQuery()
SetSearchSpec("Quote Id", sQuoteId);
ExecuteQuery(ForwardBackward);
}
var oBOQuote2 = TheApplication().ActiveBusObject();
var oBCQuote2 = oBOQuote2.GetBusComp("Quote");
with(oBCQuote2)
{
SetViewMode(AllView);
ClearToQuery()
SetSearchSpec("Id", sQuoteId);
ExecuteQuery(ForwardBackward);
}
//TheApplication().GetService("FINS Teller UI Navigation").InvokeMethod("RefreshCurrentApplet",TheApplication().NewPropertySet(), TheApplication().NewPropertySet());
}// end try
catch(e)
{
Outputs.SetProperty("Error Code", "-99");
Outputs.SetProperty("Error Message", "Error: "+e.toString());
throw(e);
}
finally
{
//CMI DBU Release#1, Defect# CQ# 2676, Config: commented the code as the expansion is not needed by JW919 on 11/09/2011
//oBCQuoteItem.InvokeMethod("ExpandAll");
oBCQuote2 = null;
oBOQuote2 = null;
oBCQuoteItem = null;
oBCQuote = null;
oBOQuote = null;
}
}

CMI Call UCM BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
// Added/Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
switch (MethodName)
{
case "Launch UCM":
//Modified By KL968 for Req. Ref. 2481 on 08/27/2011 to use profile attribute instead of Application method name as part of the Code Clean Up Activity
//Begin
//TheApplication().SetProfileAttr("CMI_UCM_CURRENT_VIEW",TheApplication().ActiveViewName);
TheApplication().SetProfileAttr("CMI_UCM_CURRENT_VIEW",TheApplication().GetProfileAttr("ActiveViewName"));
//End
TheApplication().SetProfileAttr("CMI_UCM_CURRENT_BO",TheApplication().ActiveBusObject);
TheApplication().GotoView("CMI UCM Account View","Account");
return (CancelOperation);
//break, Commented by shanmukh for code clean up 08/29/2011
//break;
case "Return to View":
TheApplication().GotoView(TheApplication().GetProfileAttr("CMI_UCM_CURRENT_VIEW"),TheApplication().GetProfileAttr("CMI_UCM_CURRENT_BO"));
break;
}
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
/*Commented by shanmukh for code clean up 08/26/2011
finally
{
}*/
//<End>
return (ContinueOperation);
}

CMI Change Invoice Group Number To 1
ChangeQuoteInvoiceGroupNum
/*************************************************************************************************************************
Created By : ix964
Created On : 04 Nov 2010
Method Name:
Functionality:
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function ChangeQuoteInvoiceGroupNum()
{
//try catch added by shanmukh for code clean up 08/26/2011
try{
TheApplication().Utility.logStack("ChangeQuoteInvoiceGroupNum", this);
var sServiceRequestBO = TheApplication().ActiveBusObject();
if (sServiceRequestBO != null && sServiceRequestBO.Name() == "Service Request") {
var sServiceRequestBC = sServiceRequestBO.GetBusComp("Service Request");
var sQuoteBC = sServiceRequestBO.GetBusComp("Quote");
var sInvoiceConsolidation = sServiceRequestBC.GetFieldValue("CMI SR Invoice Consolidation");
with(sQuoteBC) {
var sInvCons = TheApplication().InvokeMethod("LookupValue", "CMI_SR_INVOICE_CONSOLIDATION", "Consolidated");
if(sInvoiceConsolidation == sInvCons) {
SetFieldValue("CMI Quote Inv Group Num", 1);
WriteRecord();
}//end if
}// end with(sRelatedSR)
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sServiceRequestBC = null;
sServiceRequestBO = null;
sQuoteBC = null;
TheApplication().Utility.logUnstack();
}
}

CMI Change Invoice Group Number To 1
ChangeSRInvoiceGroupNum
/*************************************************************************************************************************
Created By : ix964
Created On : 04 Nov 2010
Method Name:
Functionality:
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function ChangeSRInvoiceGroupNum()
{
//try catch added by shanmukh for code clean up 08/26/2011
try{
TheApplication().Utility.logStack("ChangeSRInvoiceGroupNum", this);
var sServiceRequestBO = TheApplication().ActiveBusObject();
if (sServiceRequestBO != null && sServiceRequestBO.Name() == "Service Request") {
var sServiceRequestBC = sServiceRequestBO.GetBusComp("Service Request");
var sRelatedSR = sServiceRequestBO.GetBusComp("Related Service Request");
var sInvoiceConsolidation = sServiceRequestBC.GetFieldValue("CMI SR Invoice Consolidation");
with(sRelatedSR) {
var sInvCons = TheApplication().InvokeMethod("LookupValue", "CMI_SR_INVOICE_CONSOLIDATION", "Consolidated");
if(sInvoiceConsolidation == sInvCons) {
SetFieldValue("CMI SR Inv Group Num", 1);
WriteRecord();
}//end if
}// end with(sRelatedSR)
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sServiceRequestBC = null;
sServiceRequestBO = null;
sRelatedSR = null;
TheApplication().Utility.logUnstack();
}
}//end function

CMI Change Invoice Group Number To 1
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : ix964
Created On : 04 Nov 2010
Method Name:
Functionality: when create quote or related service request under Service Request, Invoice Group Number should
be set according to Invoice Consolidation of parent Service Request.
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//try catch added by shanmukh for code clean up 08/19/2011
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
switch(MethodName) {
case "ChangeQuoteInvoiceGroupNum":
ChangeQuoteInvoiceGroupNum();
break;
case "ChangeSRInvoiceGroupNum":
ChangeSRInvoiceGroupNum();
break;
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Change Order Requested Date BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : ix964
Created On : 04 Nov 2010
Updated By : Peter(jj954)
Updated Date : 31 May 2011
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try{
if(MethodName == "Update")
{
var boOrder = TheApplication().ActiveBusObject();
var bcOrder = boOrder.GetBusComp("Order Entry - Orders");
var oBO = TheApplication().GetBusObject("PDS Simplified Order");
var bcOrderLI = boOrder.GetBusComp("Order Entry - Line Items");
var oBC = oBO.GetBusComp("PDS Simplified Order Entry - Line Items");
var sOrderId ;
with(bcOrder)
{
ActivateField("Requested Ship Date");
var sDate = new Date;
var sCurrentMonth = sDate.getMonth() + 1;
var sCurrentYear = sDate.getYear() + 1900;
var sCurrentDay = sDate.getDate();
var sDatefirst = ToString(sCurrentMonth) + "/" + ToString(sCurrentDay) + "/" + ToString(sCurrentYear);
SetFieldValue("Requested Ship Date", sDatefirst);
sOrderId = GetFieldValue("Id");
//Update Due Date on PDS Simplified Order Entry - Line Items
with(oBC)
{
ActivateField("Due Date");
ClearToQuery();
SetViewMode(AllView);
SetSearchExpr("[Order Header Id] = '" + sOrderId + "'");
ExecuteQuery(ForwardOnly);
var iRecord = FirstRecord();
while(iRecord)
{
SetFieldValue("Due Date", sDatefirst);
WriteRecord();
iRecord = NextRecord();
}
}
}//end with(bcOrder)
bcOrderLI.ExecuteQuery(ForwardOnly);//refresh Order Entry - Line Items to get updated due date
return (CancelOperation);
}
return (ContinueOperation);
}
catch(e)
{
throw(e);
}
finally
{
boOrder = null;
bcOrder = null;
oBO = null;
bcOrderLI = null;
oBC = null;
sOrderId = null;
sDate = null;
sCurrentMonth = null;
sCurrentYear = null;
sCurrentDay = null;
sDatefirst = null;
iRecord = null;
}
}

CMI Change Quote Status BS
(declarations)
/*function QuoteValidation(sQuoteId)
{
//CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: Commenting the 'QuoteValidation' function as this is not needed as part of ADSC review comments on 09/19/11
/*********************************************************
AUTHOR: JQ487,C&I#4467 DBU, Enhancement#S131 <Configuration>: added new function call By JQ487 On 06/23/11
DESCRIPTION: This Script will be triggered for checking the status
of activities associated with a quote, before changing the status of
quote to LOST. If any aCtivity is in status other than In progress or unscheduled
the quote status will not change.
DATE CREATED: 23 Jun 2011
*********************************************************/
/* try
{
var oBO:BusObject = TheApplication().ActiveBusObject();
var oBCQuote:BusComp = oBO.GetBusComp("Quote");
var oBOAction:BusObject = TheApplication().GetBusObject("Action");
var oBCAction:BusComp = oBOAction.GetBusComp("CMI Action");
var sCan = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Cancelled");
var sUnsch = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Unscheduled");
var sInpr = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "In Progress");
var sType1 = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Service Labor");
var sType2 = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Parts Tracker");
var sCount:Number = 0;
var sFlg:bool = "N";
var sRev;
with(oBCQuote)
{
SetViewMode(AllView);
//ClearToQuery();
ActivateField("Revision");
//SetSearchSpec("Id", sQuoteId);
//ExecuteQuery(ForwardOnly);
sRev = GetFieldValue("Revision");
if(sRev > 1)
{
sFlg = "Y";
}//end if(sRev > 1)
}
with(oBCAction)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("Type");
SetSearchSpec("Quote Id", sQuoteId);
ExecuteQuery(ForwardOnly);
var sType = GetFieldValue("Type");
var sStatus = GetFieldValue("Status");
var isRecord:bool = FirstRecord();
while(isRecord)
{
sType = GetFieldValue("Type");
sStatus = GetFieldValue("Status");
if(sFlg == "Y")// Checking for Activity Type and Activity status based on certain conditions
{
if((sType == sType1) || (sType == sType2))
{
if(((sStatus != sUnsch) && (sStatus != sCan)) && (sStatus != sInpr))
{
sCount = 1;
}
}//end if((sType == sType1) || (sType == sType2))
}//end if(sFlg == "Y")
else
{
if(sType == sType1)
{
if((sStatus == sUnsch) || (sStatus == sCan))
{
sCount = 1;
}
}//end if(sType == sType1)
}//end else
isRecord =NextRecord();
}//end while(isRecord)
}//end with(oActionBC)
if(sCount == 1)
{
TheApplication().RaiseError("CMI QUOTE STATUS");
return(CancelOperation);
}
}
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally
{
oBCAction = null;
oBOAction = null;
oBCQuote = null;
oBO = null;
}
}*/

CMI Change Quote Status BS
ChangeStatus
/*************************************************************************************************************************
Created By : Zero Zhou
Created On : 18 Mar 2011
Method Name: ShellUIExit
Functionality: ShellUIExit: This method is for If quote status is set to Lost, that quote revision would be set to active = N
and need to set prior quote revision (the one the quote was revised from) back to active=Y so the work from the prior quote can be invoiced.
New Service Labor record that was created for the revision should have status set to Done to close it out.
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function ChangeStatus(Inputs, Outputs)
{
try
{
var oQuoteBO = TheApplication().GetBusObject("Quote");
var oQuoteBC = oQuoteBO.GetBusComp("Quote");
var oAction = TheApplication().GetBusObject("Action");
var oActionBC = oAction.GetBusComp("CMI Action");
var boActiveQuote = TheApplication().ActiveBusObject();
var bcActiveQuote = boActiveQuote.GetBusComp("Quote");
var sQuoteID = bcActiveQuote.GetFieldValue("Id");
var sCan = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Cancelled"); //CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: added new variable By JQ487 On 06/23/11
var sUnsch = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Unscheduled"); //CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: added new variable By JQ487 On 06/23/11
var sInpr = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "In Progress"); //CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: added new variable By JQ487 On 06/23/11
var sType1 = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Service Labor"); //CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: added new variable By JQ487 On 06/23/11
var sType2 = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Parts Tracker"); //CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: added new variable By JQ487 On 06/23/11
if(sQuoteID == "") return;
with(bcActiveQuote)
{
ActivateField("CMI Period Revise Quote Id");
var sPeriodID = GetFieldValue("CMI Period Revise Quote Id");
var sRev = GetFieldValue("Revision"); //CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: added new variable By JQ487 On 06/23/11
var sQuoteStatus = GetFieldValue("Status");
if (sQuoteStatus != TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS","Lost"))
{
SetFieldValue("Active","N");
WriteRecord();
}
}
with(oActionBC)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("Type");
SetSearchSpec("Quote Id", sQuoteID);
ExecuteQuery(ForwardOnly);
var sType = "";
var sStat = "";
var hHasRecord = FirstRecord();
while(hHasRecord)
{
sType = GetFieldValue("Type");
sStat = GetFieldValue("Status");
if(sRev == 1)//CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: added new condition By JQ487 On 06/23/11
{
if((sType == sType1) || (sType == sType2))//CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: added new condition By JQ487 On 06/23/11
{
if((sStat == sUnsch) || (sStat == sInpr))//CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: added new condition By JQ487 On 06/23/11
{
SetFieldValue("Status", sCan);
WriteRecord();
}
}
}
else
{
if(sType == sType1)//CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: added new condition By JQ487 On 06/23/11
{
if(sStat == sUnsch)//CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: added new condition By JQ487 On 06/23/11
{
SetFieldValue("Status", sCan);
WriteRecord();
}
}
}
hHasRecord=NextRecord();
}
}
with(oQuoteBC)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("Active");
SetSearchSpec("Id", sPeriodID);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
oQuoteBC.SetFieldValue("Active", "Y");
WriteRecord();
}
}
}
catch(e)
{
var Error =e.toString();
TheApplication().RaiseErrorText(Error);
}
finally{
oQuoteBC = null;
oQuoteBO = null;
bcActiveQuote= null;
boActiveQuote= null;
oActionBC =null;
oAction = null;
//sDone = null;//CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: Commenting the variable as it's not used anywhere by jq486 on 19 sep 2011>
}
}

CMI Change Quote Status BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if(MethodName == "ChangeStatus")
{
ChangeStatus(Inputs, Outputs);
return (CancelOperation);
}
//CMI <Release# 1DBU>,FT Defect 99 <Configuration>: Commenting below code where redundant status check is done and keeping the above code instead by jq486 on 09/20/11.
/*if (MethodName == "ChangeStatus")
{
var oBO = TheApplication().ActiveBusObject();
var oBCQuote = oBO.GetBusComp("Quote");
with (oBCQuote)
{
var sQuoteId = GetFieldValue("Id");
SetViewMode(AllView);
ActivateField("Status");
//ClearToQuery();
//SetSearchSpec("Id",sQuoteId);
//ExecuteQuery(ForwardOnly);
var sStatus = GetFieldValue("Status");
if (sStatus == TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Lost"))
{
//CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: Commenting the 'QuoteValidation' function as this is not needed as part of ADSC review comments on 09/19/11
//QuoteValidation(sQuoteId);
//CMI <Release# 1DBU>,C&I# 4467Enhancement#S131 <Configuration>: added new function call By JQ487 On 06/23/11
ChangeStatus(Inputs, Outputs);
}
}
return(CancelOperation);
}*/
}
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
//CMI DBU: Commented finally block as no objects declared above to nullify. For code review comments, by jq486, 19 Oct 2011.
/*finally
{
}*/
return(ContinueOperation);
}

CMI Check Discount Percent
Service_PreInvokeMethod
//JX050
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//try catch added by shanmukh for code clean up 08/26/2011
try
{
if (MethodName == "Check Discount Percent")
{
var oBO;
var oBCQIW;
var PercentAll;
var Percent;
var TotPercent=0;
//Modified By KL968 for Req. Ref. 2687 on 08/27/2011 to use profile attribute instead of Application method name as part of the Code Clean Up Activity
//if(((TheApplication().ActiveViewName() == "CMI Parts Quote Line Item View")||(TheApplication().ActiveViewName() == "CMI Labor Quote Line Item View")||(TheApplication().ActiveViewName() == "CMI Misc Quote Line Item View")) && (TheApplication().GetProfileAttr("NewWarrantyRecord") == "Y"))
if(((TheApplication().GetProfileAttr("ActiveViewName") == "CMI Parts Quote Line Item View")||(TheApplication().GetProfileAttr("ActiveViewName") == "CMI Labor Quote Line Item View")||(TheApplication().GetProfileAttr("ActiveViewName") == "CMI Misc Quote Line Item View")) && (TheApplication().GetProfileAttr("NewWarrantyRecord") == "Y"))
{
oBO = TheApplication().ActiveBusObject();
oBCQIW = oBO.GetBusComp("CMI Quote Item Warranty");
PercentAll = oBCQIW.GetFieldValue("CMI Total Discount Percent");
Percent = TheApplication().GetProfileAttr("percentcovered");
TotPercent = ToNumber(Percent) + ToNumber(PercentAll);
if(TotPercent > 100)
{
TheApplication().RaiseErrorText("Total Percent of all warranties cannot be greater than 100");
}
TheApplication().SetProfileAttr("NewWarrantyRecord","");
}
else
//Modified By KL968 for Req. Ref. 2687 on 08/27/2011 to use profile attribute instead of Application method name as part of the Code Clean Up Activity
//if(((TheApplication().ActiveViewName() == "CMI Parts Quote Line Item View")||(TheApplication().ActiveViewName() == "CMI Labor Quote Line Item View")||(TheApplication().ActiveViewName() == "CMI Misc Quote Line Item View")) && (TheApplication().GetProfileAttr("NewWarrantyRecord") != "Y"))
if(((TheApplication().GetProfileAttr("ActiveViewName") == "CMI Parts Quote Line Item View")||(TheApplication().GetProfileAttr("ActiveViewName") == "CMI Labor Quote Line Item View")||(TheApplication().GetProfileAttr("ActiveViewName") == "CMI Misc Quote Line Item View")) && (TheApplication().GetProfileAttr("NewWarrantyRecord") != "Y"))
{
oBO = TheApplication().ActiveBusObject();
oBCQIW = oBO.GetBusComp("CMI Quote Item Warranty");
PercentAll = oBCQIW.GetFieldValue("CMI Total Discount Percent");
Percent = TheApplication().GetProfileAttr("percentcovered");
var Oldpercent = TheApplication().GetProfileAttr("OldPercentCovered");
TotPercent = ToNumber(Percent) + ToNumber(PercentAll) - ToNumber(Oldpercent);
if(TotPercent > 100)
{
TheApplication().RaiseErrorText("Total Percent of all warranties cannot be greater than 100");
}
}
return (CancelOperation);
}
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}//end of catch
finally
{
oBCQIW = null;
oBO = null;
}//end of finally
return (ContinueOperation);
}

CMI Check Order Parts Not Used BS
CheckOrderParts
function CheckOrderParts(sOrderId)
{
try
{
TheApplication().Utility.logStack("CheckOrderParts", this);
var boOrder = TheApplication().GetBusObject("Order Item");
var bcOrderItem = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
var sMisc = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Misc");
var sLabor = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
with(bcOrderItem) {
SetViewMode(AllView);
ActivateField("Product");
ActivateField("CMI Actual Quantity");
ActivateField("Line Number");
ClearToQuery();
var searchst = "[Order Header Id] = '" + sOrderId + "' AND [CMI Main Assembly Flag] <> 'Y' AND "+
"[CMI Actual Quantity] = 0 AND [Product Type] <> '" + sMisc + "' AND [Product Type] <> '" + sLabor + "'";
SetSearchExpr(searchst);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Empty Lines ("+sOrderId+") found?", FirstRecord());
while(FirstRecord()) {
TheApplication().Utility.logVars("Delete #/Line/Product", GetFieldValue("Id")+"/"+GetFieldValue("Line Number")+"/"+GetFieldValue("Product"));
DeleteRecord();
}
}//end with(bcOrderItem)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcOrderItem=null;
boOrder=null;
TheApplication().Utility.logUnstack();
}
}

CMI Check Order Parts Not Used BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : ix964
Created On : 09 Dec 2010
Method Name:
Functionality:
Input: Quote Number, Order Id
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if (MethodName == "CheckOrderParts") {
var sOrderId = Inputs.GetProperty("OrderId");
CheckOrderParts(sOrderId);
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Check Price List
CheckPriceList
/*************************************************************************************************************************
Created By : jr426
Created On : 26th February 2011
Method Name: function CheckPriceList()
Functionality: This function check a Qute's Price List and Modify a Quote Item's Price List
Customization Approval #: NA
************************************************************************************************************************/
function CheckPriceList(sEntityId) {
try {
//TheApplication().Utility.logStack("CheckPriceList", this);
var sPriceList = TheApplication().GetProfileAttr("CMIPriceList");
var activeBOName = TheApplication().ActiveBusObject().Name();
var boHeader:BusObject;
var bcItem:BusComp;
//Defect# 23, C&I# 4466, change: Service Request BO added as change in price list should be cascaded from Service Request as well - JW919 on 05/25/2011
// TheApplication().Utility.logVars("Active BO", activeBOName);
if(activeBOName == "Quote" || activeBOName == "Service Request") {
boHeader = TheApplication().GetBusObject("Quote");
bcItem = boHeader.GetBusComp("Quote Item (Simple)");
} else {
boHeader = TheApplication().GetBusObject("Order Entry (Sales)");
bcItem = boHeader.GetBusComp("Order Entry - Line Items");
}
with(bcItem) {
ActivateField("Item Price List");
ClearToQuery();
SetViewMode(AllView);
//Defect# 23, C&I# 4466, change: Service Request BO added as change in price list should be cascaded from Service Request as well - JW919 on 05/25/2011
if(activeBOName == "Quote" || activeBOName == "Service Request")
SetSearchSpec("Quote Id", sEntityId);
else
SetSearchSpec("Order Header Id", sEntityId);
ExecuteQuery(ForwardBackward);
var HasRecord = FirstRecord();
while(HasRecord) {
SetFieldValue("Item Price List",sPriceList);
SetFieldValue("CMI Price As Of Date",""); //END
WriteRecord();
HasRecord = NextRecord();
}
}
} catch(e){
//TheApplication().Utility.RaiseError(e);
} finally {
bcItem = null;
boHeader = null;
//TheApplication().Utility.logUnstack();
}
}

CMI Check Price List
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
//TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if(MethodName == "CheckPriceList") {
var sEntityId = TheApplication().GetProfileAttr("CMIEntityId");
if(sEntityId != "") {
CheckPriceList(sEntityId);
//CMI DBU Release#, defect# 3961, Config: Refresh commented in CheckprceList method and added in Pre-invoke by jw919 on 12/12/2011
var oBO = TheApplication().ActiveBusObject();
var oBC = oBO.GetBusComp("Quote Item");
oBC.ClearToQuery();
oBC.ExecuteQuery();
}
}
} catch(e){
//TheApplication().Utility.RaiseError(e);
} finally {
oBC = null
oBO = null;
//TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Check Related SR Service
CheckRelateSRActivity
/*************************************************************************************************************************
Created By : ix964
Created On : 12th December 2010
Method Name: function CheckRelateSRActivity(Inputs,Outputs)
C&I Number : 3924
Requirement # : CO 120.01
Functionality: This function check all related SR's Activity status
Input: SR Id
Output: Error Code,Error Message
Customization Approval #: NA
************************************************************************************************************************/
function CheckRelateSRActivity(Inputs, Outputs)
{
try
{
var boSR = TheApplication().GetBusObject("Service Request");
var bcSR = boSR.GetBusComp("Service Request");
var bcRelSR = boSR.GetBusComp("Related Service Request");
var sSRId = Inputs.GetProperty("SR Id");
var sMessage = "";
with(bcSR)
{
ClearToQuery();
SetViewMode(AllView);
SetSearchExpr("[Id] = '" + sSRId + "'");
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
// with(bcRelSR) // Commented by JW227 for TAM review comment#1 on 02/07/2012
// {
bcRelSR.ClearToQuery();
bcRelSR.ExecuteQuery(ForwardOnly);
var bHasRelateSR = bcRelSR.FirstRecord();
while(bHasRelateSR)
{
Inputs.SetProperty("SR Id",bcRelSR.GetFieldValue("Id"));
CheckSRActivity(Inputs, Outputs);
bHasRelateSR = bcRelSR.NextRecord();
}
// }
}
}
Inputs.SetProperty("SR Id",sSRId);// set back the SR Id for the Inputs
}
catch(e)
{
Outputs.SetProperty("Error Code", "1");
Outputs.SetProperty("Error Message", "Error in 'CheckRelateSRActivity' function 'CheckRelateSRActivity',Error Detail:" +e.message);
}
finally
{
bcRelSR = null;
bcSR = null;
boSR = null;
}
}

CMI Check Related SR Service
CheckSRActivity
/*************************************************************************************************************************
Created By : ix964
Created On : 12th December 2010
Method Name: function CheckSRActivity(Inputs,Outputs)
C&I Number : 3924
Requirement # : CO 120.01
Functionality: This function check a SR's Activity status
Input: SR Id
Output: Error Code,Error Message
Customization Approval #: NA
************************************************************************************************************************/
function CheckSRActivity(Inputs, Outputs)
{
try
{
var boAction = TheApplication().GetBusObject("Action");
var bcAction = boAction.GetBusComp("Action");
var sSRId = Inputs.GetProperty("SR Id");
var LABORTYPE = TheApplication().InvokeMethod("LookupValue" ,"TODO_TYPE", "Service Labor");
//var DONE = TheApplication().InvokeMethod("LookupValue" ,"EVENT_STATUS", "Done");
//var CANCELLED = TheApplication().InvokeMethod("LookupValue" ,"EVENT_STATUS", "Cancelled");
//var COMPLATED = TheApplication().InvokeMethod("LookupValue" ,"EVENT_STATUS", "Completed");
//var UNSCHEDULED = TheApplication().InvokeMethod("LookupValue" ,"EVENT_STATUS", "Unscheduled");
//var DIAGCOMP = TheApplication().InvokeMethod("LookupValue" ,"EVENT_STATUS", "Diagnostics Complete");
var boLOV = TheApplication().GetBusObject("List Of Values");
var bcLOV = boLOV.GetBusComp("List Of Values");
var isRecord = "";
var sSearchst = "[Activity SR Id] = '" + sSRId + "' AND [Type] = '" + LABORTYPE + "' AND ";
with(bcLOV)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr("[Type] = 'CMI_LABOR_ACTIVITY_STATUS' AND [Active] = 'Y'");
ActivateField("Type");
ActivateField("Active");
ActivateField("Value");
ExecuteQuery(ForwardOnly);
isRecord = FirstRecord();
while(isRecord)
{
sSearchst = sSearchst + "[Status] <> '" + GetFieldValue("Value") + "'";
isRecord = NextRecord();
if(isRecord)
sSearchst = sSearchst + " AND ";
}
// sSearchst = sSearchst + ")";
}
with(bcAction)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("Status");
ActivateField("SR Number");
//SetSearchExpr("[Activity SR Id] = '" + sSRId + "' AND [Type] = '" + LABORTYPE + "' AND [Status] <> '"+ DONE +"' AND [Status] <> '"+ COMPLATED +"' AND [Status] <> '"+ CANCELLED +"' AND [Status] <> '"+ UNSCHEDULED +"' AND [Status] <> '"+ DIAGCOMP +"'");
SetSearchExpr(sSearchst);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
Outputs.SetProperty("Error Code", "2");
Outputs.SetProperty("Error Message", Outputs.GetProperty("Error Message") + "\n Labor Activity for SR: ["+ GetFieldValue("SR Number") + "] is not Completed or Done.\n");
}
}
}
catch(e)
{
Outputs.SetProperty("Error Code", "1");
Outputs.SetProperty("Error Message", "Error in 'CheckSRActivity' function 'CheckSRActivity',Error Detail:" +e.message);
}
finally
{
bcAction = null;
boAction = null;
//added by shanmukh for code clean up 08/22/2011
bcLOV = null;
boLOV = null;
}
}

CMI Check Related SR Service
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//try catch added by shanmukh for code clean up 08/26/2011
try
{
if(MethodName == "CheckSRActivity")
{
CheckSRActivity(Inputs, Outputs);
return (CancelOperation);
}
if(MethodName == "CheckRelateSRActivity")
{
CheckRelateSRActivity(Inputs, Outputs);
return (CancelOperation);
}
if(MethodName == "UpdateRelateSRParId")
{
if(TheApplication().ActiveBusObject().Name() == "Service Request")
{
UpdateRelateSRParId();
}
else
{
Outputs.SetProperty("Error Code","2");
Outputs.SetProperty("Error Message","This service can only invoke in 'Service Request' BO!");
}
return (CancelOperation);
}
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}//end of catch
return (ContinueOperation);
}

CMI Check Related SR Service
UpdateRelateSRParId
/*************************************************************************************************************************
Created By : James Jin
Created On : 28th December 2010
Method Name: function UpdateRelateSRParId()
C&I Number :
Requirement # :
Functionality: Update Relate SR ParId
Input:
Output:
Customization Approval #:
************************************************************************************************************************/
function UpdateRelateSRParId()
{
try{
var bothis = TheApplication().ActiveBusObject();
var bcthisparent = bothis.GetBusComp("Service Request");
var bcthis = bothis.GetBusComp("Related Service Request");
var sRelSRId = bcthis.GetFieldValue("Id");
var sParentSRId = bcthisparent.GetFieldValue("Id");
/* var boSR = TheApplication().GetBusObject("Service Request");
var bcSR = boSR.GetBusComp("Service Request");
with(bcSR)
{
SetViewMode(AllView);
ActivateField("Parent Service Request Id");
ClearToQuery();
SetSearchSpec("Id",sRelSRId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
SetFieldValue("Parent Service Request Id",sParentSRId);
WriteRecord();
}
}
*/
bcthis.ActivateField("Parent Service Request Id");
bcthis.SetFieldValue("Parent Service Request Id",sParentSRId);
bcthis.WriteRecord();
}
catch(e)
{
TheApplication().RaiseErrorText("Error in set parent SR Id, Error message is:"+ e.message);
}
finally
{
// bcSR = null;
// boSR = null;
//Added by shanmukh for code clean up 08/26/2011
bcthisparent = null;
bcthis = null;
bothis = null;
}
}

CMI CheckOverLap_NewRec
CheckOverLap_NewRec
function CheckOverLap_NewRec(Inputs,Outputs)
{
try{
var boTs = TheApplication().GetBusObject("Time Sheet") ;
var bcTs = boTs.GetBusComp("Time Sheet");
var bcTSItems = boTs.GetBusComp("Time Sheet Items");
var sTTId = Inputs.GetProperty("TTId");
var sTime= Inputs.GetProperty("Start Time");
var eTime= Inputs.GetProperty("End Time");
var iDate = Inputs.GetProperty("Item Date");
var TSId = Inputs.GetProperty("Id");
with(bcTs)
{
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Id", TSId) ;
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
with(bcTSItems)
{
var searchst = "" ;
if (eTime == null || eTime == "")
searchst = "[Item Date]= '"+ iDate +"' AND [Start Time] <= '" + sTime + "' AND [End Time] > '" + sTime + "'";
else
{
searchst = "[Item Date]= '"+ iDate +"' AND (([Start Time] <= '" + sTime + "' AND [End Time] > '" + sTime + "')";
searchst = searchst + " OR ([Start Time] < '" + eTime + "' AND [End Time] >= '" + eTime + "')";
searchst = searchst + " OR ([Start Time] >= '" + sTime + "' AND [End Time] <= '" + eTime + "'))";
searchst = searchst + " AND [Start Time] <> [End Time]" ;
}
searchst = searchst + " AND [Id] <> '" + sTTId + "'" ;
ClearToQuery();
SetViewMode(AllView);
SetSearchExpr(searchst);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
Outputs.SetProperty("OverlapFound", "Yes");
else
Outputs.SetProperty("OverlapFound", "No");
}//End of with(bcTSItems)
}//End of firstRec
}//end-with-bcTS
}//try
catch(e)
{
throw(e);
//Outputs.SetProperty("OverlapFound", "Yes");
}
finally
{
if(defined(bcTSItems)) bcTSItems = null;
if(defined(bcTs)) bcTs = null;
if(defined(boTs)) boTs = null;
}
}//function

CMI CheckOverLap_NewRec
CheckOverLap_NewRec_Action
function CheckOverLap_NewRec_Action(Inputs,Outputs)
{
try{
var boTimeSheet = TheApplication().GetBusObject("Time Sheet Item") ;
var bcTimeSheet = boTimeSheet.GetBusComp("Time Sheet Unassoc Daily Hours");
//var boAction = TheApplication().GetBusObject("Action");
//var bcTSItems = boAction.GetBusComp("Time Sheet Daily Hours");
var sTTId = Inputs.GetProperty("TTId");
var sTime= Inputs.GetProperty("Start Time");
var eTime= Inputs.GetProperty("End Time");
var iDate = Inputs.GetProperty("Item Date");
//var ActId = Inputs.GetProperty("Activity Id");
var sOwnerId = Inputs.GetProperty("OwnerId") ;
with(bcTimeSheet)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Adjusted Base Time Item Id");
var searchst = "" ;
if (eTime == null || eTime == "")
searchst = "[Item Date]= '"+ iDate +"' AND [Start Time] <= '" + sTime + "' AND [End Time] > '" + sTime + "'";
else
{
searchst = "[Item Date]= '"+ iDate +"' AND (([Start Time] <= '" + sTime + "' AND [End Time] > '" + sTime + "')";
searchst = searchst + " OR ([Start Time] < '" + eTime + "' AND [End Time] >= '" + eTime + "')";
searchst = searchst + " OR ([Start Time] >= '" + sTime + "' AND [End Time] <= '" + eTime + "'))";
searchst = searchst + " AND [Start Time] <> [End Time]" ;
}
searchst = searchst + " AND [Owner Id] = '" +sOwnerId+ "' AND [Id] <> '" + sTTId + "' AND [Adjusted Base Time Item Id] IS NULL";
ClearToQuery();
SetViewMode(AllView);
SetSearchExpr(searchst);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
Outputs.SetProperty("OverlapFound", "Yes");
else
Outputs.SetProperty("OverlapFound", "No");
}//End of with(bcTSItems)
// }//End of firstRec
//end-with-bcAction
}//try
catch(e)
{
throw(e);
//Outputs.SetProperty("OverlapFound", "Yes");
}
finally
{
if(defined(bcTimeSheet)) bcTimeSheet = null;
if(defined(boTimeSheet)) boTimeSheet = null;
}
}

CMI CheckOverLap_NewRec
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try{
switch(MethodName) {
case "CheckOverLap_NewRec":
CheckOverLap_NewRec(Inputs, Outputs);
return(CancelOperation);
break;
case "CheckOverLap_NewRec_Action":
CheckOverLap_NewRec_Action(Inputs, Outputs);
return(CancelOperation);
break;
/* case "CheckOverLap_NewRec_AnyAction":
CheckOverLap_NewRec_AnyAction(Inputs, Outputs);
return(CancelOperation);
break;*/
}
}
catch(e){
throw(e);
}
finally{
}
}

CMI Claim Items Validation BS
FailCodeValidation
function FailCodeValidation(Inputs, Outputs)
{
try
{
var oBO = TheApplication().ActiveBusObject();
//avoid to running the validation for SR Claims
if (oBO != null && oBO.Name() == "CMI Claims")
{
/* var oBC = oBO.GetBusComp("CMI Claims Failure Codes");
with(oBC)
{
ActivateField("CMI Count");
var sItemCount = ToNumber(GetFieldValue("CMI Count"));
}
//Inactived by jr418 on Mar 10,2011
//To solve defect
*/
var oBC = oBO.GetBusComp("INS Claims");
var sItemCount = "";
if(oBC != null)
{
with(oBC)
{
var sClaimsId = GetFieldValue("Id");
ClearToQuery();
ActivateField("CMI FailCode Count");
SetSearchSpec("Id", sClaimsId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sItemCount = GetFieldValue("CMI FailCode Count");
}
}
if (sItemCount >= 3)
{
TheApplication().RaiseErrorText("Number of Records should be less than or equal to 3");
}
}
}
}
catch(e)
{
throw(e);
}
finally
{
oBC = null;
oBO = null;
}
}

CMI Claim Items Validation BS
MultiEngValidation
function MultiEngValidation(Inputs, Outputs)
{
try
{
var oBO = TheApplication().ActiveBusObject();
var oBC = oBO.GetBusComp("INS Claims Insured Property");
if(oBC != null)
{
with(oBC)
{
ActivateField("CMI Count");
var sItemCount = ToNumber(GetFieldValue("CMI Count"));
}
if (sItemCount >= 70)
{
TheApplication().RaiseErrorText("Number of Records should be less than or equal to 70");
}
}
}
catch(e)
{
throw(e);
}
finally
{
oBC = null;
oBO = null;
}
}

CMI Claim Items Validation BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//try catch added by shanmukh for code clean up 08/22/2011
try
{
if(MethodName == "FailCodeValidation")
{
FailCodeValidation(Inputs, Outputs);
return(CancelOperation);
}
if(MethodName == "MultiEngValidation")
{
MultiEngValidation(Inputs, Outputs);
return(CancelOperation);
}
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}//end of catch
return (ContinueOperation);
}

CMI Claim Measurement BS
Service_PreInvokeMethod
/*CMI DBU Release#3, Defect#3543, Added by KM331 on 01/30/2012*/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if(MethodName = "SetMeasurement")
{
SetMeasurement();
return (CancelOperation);
}
}
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
return (ContinueOperation);
}

CMI Claim Measurement BS
SetMeasurement
/*CMI DBU Release#3, Defect#3543, Added by KM331 on 01/30/2012*/
function SetMeasurement()
{
var sAssetNum = TheApplication().GetProfileAttr("CMIAssetNum");
var sClaimId = TheApplication().GetProfileAttr("CMIClaimId");
var oAssetBO = TheApplication().GetBusObject("Asset Management");
var oClaimBO = TheApplication().GetBusObject("CMI Claims");
var oMeasureBC = oAssetBO.GetBusComp("FS Asset Measurement Characteristics");
var oReadBC = oAssetBO.GetBusComp("FS Asset Reading");
var oClaimBC = oClaimBO.GetBusComp("INS Claims");
var sAssetId = "";
var sMeasureId = "";
var sReadingId = "";
try
{
if(sAssetNum != null && sAssetNum != "")
{
with(oMeasureBC)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Asset Number");
SetSearchSpec("Asset Number", sAssetNum);
SetSortSpec("Created(DESCENDING)");
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sMeasureId = GetFieldValue("Id");
}
}
if(sMeasureId != null && sMeasureId != "")
{
with(oReadBC)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Asset Measurement Id");
SetSearchSpec("Asset Measurement Id", sMeasureId);
SetSortSpec("Created(DESCENDING)");
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sReadingId = GetFieldValue("Id");
}
}
}
}
with(oClaimBC)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Measurement Type Id");
ActivateField("CMI Reading Id");
SetSearchSpec("Id", sClaimId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
SetFieldValue("CMI Measurement Type Id", sMeasureId);
SetFieldValue("CMI Reading Id", sReadingId);
WriteRecord();
}
}
}
catch(e)
{
throw e;
}
finally
{
oReadBC = null;
oMeasureBC = null;
oClaimBC = null;
oAssetBO = null;
oClaimBO = null;
}
}

CMI Claim Refile BS
CMIRefile
/*************************************************************************************************************************
Created By : Zero Zhou (jj638)
Created On : 2011-july-19
Defect Number : DBUNG00001079
Functionality: When the user click Button Refile in CMI Claims Summary Form Applet,
Refile Flag is set True in Note, Fail Code, Part, SRT and Other Items View
************************************************************************************************************************/
function CMIRefile() {
try {
TheApplication().Utility.logStack("CMIRefile", this);
var sBO = TheApplication().ActiveBusObject();
TheApplication().Utility.logVars("Business Object", sBO.Name());
if (sBO.Name() == "CMI Claims") {
var ClaimId = sBO.GetBusComp("INS Claims").GetFieldValue("Id");
var sNoteBC = sBO.GetBusComp("INS Claims Note");
var sFaiCodBC = sBO.GetBusComp("CMI Claims Failure Codes");
var sPartBC = sBO.GetBusComp("CMI Claims Part Detail");
var sSRTBC = sBO.GetBusComp("CMI Claims SRT Details");
var sOthItBC = sBO.GetBusComp("CMI Claims Other Items");
TheApplication().Utility.logVars("Claim Id", ClaimId);
//Set Refile flag to "Y" in Note
with(sNoteBC) {
ActivateField("Claim Id");
ActivateField("CMI Claims Refile Flag");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Claim Id", ClaimId);
ExecuteQuery(ForwardBackward);
var iNTRec = FirstRecord();
TheApplication().Utility.logVars("Claim Note Found", iNTRec);
while(iNTRec) {
SetFieldValue("CMI Claims Refile Flag","Y");
WriteRecord();
iNTRec = NextRecord();
}
}
//Set Refile flag to "Y" in Fail Code
with(sFaiCodBC) {
ActivateField("CMI Claims Id");
ActivateField("CMI Claims Refile Flag");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Claims Id",ClaimId);
ExecuteQuery(ForwardBackward);
var iFCRec = FirstRecord();
TheApplication().Utility.logVars("Fail Code Found", iFCRec);
while(iFCRec) {
SetFieldValue("CMI Claims Refile Flag","Y");
WriteRecord();
iFCRec = NextRecord();
}
}
//Set Refile flag to "Y" in Part
with(sPartBC) {
ActivateField("CMI Claims Id");
ActivateField("CMI Claims Refile Flag");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Claims Id", ClaimId);
ExecuteQuery(ForwardBackward);
var iPARTRec = FirstRecord();
TheApplication().Utility.logVars("Claim Part Found", iPARTRec);
while(iPARTRec) {
SetFieldValue("CMI Claims Refile Flag",'Y');
WriteRecord();
iPARTRec = NextRecord();
}
}
//Set Refile flag to "Y" in SRT
with(sSRTBC) {
ActivateField("CMI Claims Id");
ActivateField("CMI Claims Refile Flag");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Claims Id",ClaimId);
ExecuteQuery(ForwardBackward);
var iSRTRec = FirstRecord();
TheApplication().Utility.logVars("Claim SRT Found", iSRTRec);
while(iSRTRec) {
SetFieldValue("CMI Claims Refile Flag",'Y');
WriteRecord();
iSRTRec = NextRecord();
}
}
//Set Refile flag to "Y" in Other Items
with(sOthItBC) {
ActivateField("CMI Claims Id");
ActivateField("CMI Claims Refile Flag");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Claims Id",ClaimId);
ExecuteQuery(ForwardBackward);
var iOthItRec = FirstRecord();
TheApplication().Utility.logVars("Other Item Found", iOthItRec);
while(iOthItRec) {
SetFieldValue("CMI Claims Refile Flag",'Y');
WriteRecord();
iOthItRec = NextRecord();
}
}
}//end if CMI Claims BO
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
sOthItBC = null;
sSRTBC = null;
sPartBC = null;
sFaiCodBC= null;
sNoteBC = null;
sBO = null;
//Added by shanmukh for code clean up 08/26/2011
ClaimId = null;
TheApplication().Utility.logUnstack();
}
}

CMI Claim Refile BS
RefileClaims
/*************************************************************************************************************************
Created By : Alvin Tuo (JR428)
Created On : 2011-2-19
C&I Number : 4607
Functionality: Refile claims and copy items which refile flag is Y.
Modification: 1. Removed Setfield value of Claims Refile Flag and set No Copy user property true in BCs
2. Created the new claim in new instance of CMI Claims BO.
************************************************************************************************************************/
function RefileClaims(Inputs, Outputs) {
try {
TheApplication().Utility.logStack("RefileClaims", this);
var sPending = TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Pending");
var sClosed = TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Closed");
var sVariance = TheApplication().InvokeMethod("LookupValue","CMI_PAYMENT_TYPE","Variance");
var sVerified = TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Verified");
var sVarianceReason = TheApplication().InvokeMethod("LookupValue","DEDUCT_TYPE","Below Tolerance");//new variable for DBUNG00004308 <by> ko981 on 12/29/2011
var sConsolidate = TheApplication().InvokeMethod("LookupValue","CMI_PAY_CDT_TYPE","Consolidate");
var sBO = TheApplication().ActiveBusObject();
var sBC = sBO.GetBusComp("INS Claims");
var InpId = sBC.GetFieldValue("Id");
var sNewBO = TheApplication().GetBusObject("CMI Claims");
var sNewBC = sNewBO.GetBusComp("INS Claims");
var sRefClaimID = "";
var found;
with (sNewBC) {
ActivateField("CMI Original Claim Id");
ActivateField("Status Code");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",InpId);
ExecuteQuery(ForwardBackward);
found = FirstRecord();
TheApplication().Utility.logVars("Original Claim ("+InpId+") found?", found);
if (FirstRecord()) {
NewRecord(NewAfterCopy);//Changed the value 3 to NewAfterCopy from oracle review <added by> <k0981> on <09-11-2011>
SetFieldValue("CMI Original Claim Id",InpId);
SetFieldValue("Status Code",sPending);
WriteRecord();
sRefClaimID = GetFieldValue("Id");
TheApplication().Utility.logVars("Refile Claim Id", sRefClaimID);
}
}
var sNoteBC = sBO.GetBusComp("INS Claims Note");//Chaned the bo from sNewBO to sBO on 31/01/12[Start]
var sFaiCodBC = sBO.GetBusComp("CMI Claims Failure Codes");
var sPartBC = sBO.GetBusComp("CMI Claims Part Detail");
var sSRTBC = sBO.GetBusComp("CMI Claims SRT Details");
var sOthItBC = sBO.GetBusComp("CMI Claims Other Items");
var oBCPayment = sBO.GetBusComp("INS Claims Payments");//Chaned the bo from sNewBO to sBO for defect 5176,by km330[End]
with(sBC) {
ActivateField("Status Code");
//var sPaymentVariance = Math.abs(ToNumber(GetFieldValue("CMI Payment Variance Sum")));//CMI DBU,CQ DBUNG00002917,Commented Code by JQ486 on 11 Nov 2011. This was not taking Negative Vaue
var sPaymentVariance = ToNumber(GetFieldValue("CMI Payment Variance Sum"));//CMI DBU,CQ DBUNG00002917,Added Code by JQ486 on 14 Nov 2011. This Considers Negative value.
var sVarianceToLevel = GetFieldValue("CMI Variance Tolerance Level");
TheApplication().Utility.logVars("Variance Tolerance Level", sVarianceToLevel, "Payment Variance", sPaymentVariance);
if (ToNumber(sVarianceToLevel) < sPaymentVariance) {
with(oBCPayment) {
ActivateField("Payment Amount");
ActivateField("Payment Type Code");
ActivateField("Claim Id");
ActivateField("Payment Status");
ActivateField("CMI Payment Credit Type");//Added by woody for fixing the defect 1506 on 20110824
ActivateField("CMI Variance Reason");//Added by ko981 for fixing the defect DBUNG00004308 on 12/29/2011
NewRecord(NewAfter);//Changed the value 1 to NewAfter from oracle review <added by> <k0981> on <09-11-2011>
SetFieldValue("Claim Id", InpId);
SetFieldValue("Payment Amount", sPaymentVariance);
SetFieldValue("Payment Type Code", sVariance);
SetFieldValue("Payment Status", sVerified);
SetFieldValue("CMI Payment Credit Type", sConsolidate);//Added by woody for fixing the defect 1506 on 20110824
SetFieldValue("CMI Variance Reason", sVarianceReason);//Added by ko981 for fixing the defect DBUNG00004308 on 12/29/2011
WriteRecord();
}
}
with(sNoteBC) {
ActivateField("Claim Id");
ActivateField("CMI Claims Refile Flag");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Claim Id",InpId);
SetSearchSpec("CMI Claims Refile Flag","Y");
ExecuteQuery(ForwardOnly);
var iNTRec = FirstRecord();
TheApplication().Utility.logVars("Claim Note found?", iNTRec);
while(iNTRec) {
NewRecord(NewAfterCopy);//Changed the value 3 to NewAfterCopy from oracle review <added by> <k0981> on <09-11-2011>
SetFieldValue("Claim Id",sRefClaimID);
WriteRecord();
iNTRec = NextRecord();
}
ClearToQuery();
}
with(sSRTBC) {
ActivateField("CMI Claims Id");
ActivateField("CMI Claims Refile Flag");
ActivateField("CMI SRT Description");
ActivateField("CMI Product Line");
ActivateField("CMI Vendor");
SetViewMode(AllView);//Changed the value 3 to AllView from oracle review <added by> <k0981> on <09-11-2011>
ClearToQuery();
SetSearchSpec("CMI Claims Id",InpId);
SetSearchSpec("CMI Claims Refile Flag","Y");
ExecuteQuery(ForwardOnly);
var iSRTRec = FirstRecord();
TheApplication().Utility.logVars("Claim SRT found?", iSRTRec);
while(iSRTRec) {
var sSRTId = GetFieldValue("CMI SRT Id");
var sProductLine = GetFieldValue("CMI Product Line");
var sVendor = GetFieldValue("CMI Vendor");
NewRecord(NewAfterCopy);//Changed the value 3 to NewAfterCopy from oracle review <added by> <k0981> on <09-11-2011>
SetFieldValue("CMI Claims Id",sRefClaimID);
SetFieldValue("CMI Product Line", sProductLine);
SetFieldValue("CMI Vendor", sVendor);
SetFieldValue("CMI SRT Id", sSRTId);
TheApplication().SetProfileAttr("CMIRefileSRTFlag" , "Y");
WriteRecord();
iSRTRec = NextRecord();
}
ClearToQuery();
}
with(sOthItBC) {
ActivateField("CMI Claims Id");
ActivateField("CMI Claims Refile Flag");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Claims Id",InpId);
SetSearchSpec("CMI Claims Refile Flag","Y");
ExecuteQuery(ForwardOnly);
var iOthItRec = FirstRecord();
TheApplication().Utility.logVars("Other Item found?", iOthItRec);
while(iOthItRec) {
NewRecord(NewAfterCopy);//Changed the value 3 to NewAfterCopy from oracle review <added by> <k0981> on <09-11-2011>
SetFieldValue("CMI Claims Id",sRefClaimID);
WriteRecord();
iOthItRec = NextRecord();
}
ClearToQuery();
}
with(sFaiCodBC) {
ActivateField("CMI Claims Id");
ActivateField("CMI Claims Refile Flag");
SetViewMode(AllView);//Changed the value 3 to AllView from oracle review <added by> <k0981> on <09-11-2011>
ClearToQuery();
SetSearchSpec("CMI Claims Id",InpId);
SetSearchSpec("CMI Claims Refile Flag","Y");
ExecuteQuery(ForwardOnly);
var iFCRec = FirstRecord();
TheApplication().Utility.logVars("Fail Code found?", iFCRec);
while(iFCRec) {
TheApplication().SetProfileAttr("RefileClaim", "True");
NewRecord(NewAfterCopy);//Changed the value 3 to NewAfterCopy from oracle review <added by> <k0981> on <09-11-2011>
SetFieldValue("CMI Claims Id",sRefClaimID);
WriteRecord();
iFCRec = NextRecord();
}
ClearToQuery();
TheApplication().SetProfileAttr("RefileClaim", "False");
}
with(sPartBC)
{
ActivateField("CMI Claims Id");
ActivateField("CMI Claims Refile Flag");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Claims Id",InpId);
SetSearchSpec("CMI Claims Refile Flag","Y");
ExecuteQuery(ForwardOnly);
var iPARTRec = FirstRecord();
TheApplication().Utility.logVars("Part Detail found?", iPARTRec);
while(iPARTRec)
{
NewRecord(NewAfterCopy);
SetFieldValue("CMI Claims Id",sRefClaimID);
WriteRecord();
iPARTRec = NextRecord();
}
ClearToQuery(); // Added by KM330 for defect 2359,on 31/01/12
}
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",InpId);
ExecuteQuery(ForwardBackward);
var iRec = FirstRecord();
TheApplication().Utility.logVars("Claim found?", iRec);
if(iRec) {
SetFieldValue("Status Code",sClosed);
WriteRecord();
}
SetViewMode(AllView);
ClearToQuery();
var sSearchSpec = "[Id] = '" + sRefClaimID +"' OR [Id] = '" + InpId + "'";
SetSortSpec("Updated(ASCENDING)");
SetSearchExpr(sSearchSpec);
ExecuteQuery(ForwardBackward);
if(FirstRecord()) {
with(sPartBC) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Claims Id",sRefClaimID);
ExecuteQuery(ForwardBackward);
}
}
}//end sBC
TheApplication().GotoView("CMI Distributor Detail Summary View", sNewBO);
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
sBC = null;
sNoteBC = null;
sFaiCodBC = null;
sPartBC = null;
sSRTBC = null;
sOthItBC = null;
sBO = null;
TheApplication().SetProfileAttr("RefileClaim", "False");
oBCPayment = null;
sNewBC = null;
sNewBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Claim Refile BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : Alvin Tuo (JR428)
Created On : 2011-2-19
C&I Number : 4607
Functionality: Refile claims and copy items which refile flag is Y.
RefileClaim method will be triggered when user click the Refile Button in CMI Claims Summary Form Applet
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retValue = CancelOperation;
switch (MethodName) {
case "RefileClaim":
RefileClaims(Inputs,Outputs);
break;
case "CMIRefile":
CMIRefile();
break;
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retValue);
}
return (retValue);
}

CMI Claim SRT Validate BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
// Added/Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
if (MethodName == "CMISRTValidate")
{
CMISRTValidate(Inputs, Outputs);
return(CancelOperation);
}
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
/* Commented the finally block ,by jw920 on 20/08/2011<code clean up Process>
finally
{
}*/
//<End>
return (ContinueOperation);
}

CMI Claim SRT Validate BS
CMISRTValidate
function CMISRTValidate(Inputs, Outputs){
/*************************************************************************************************************************
Created By : JR418
Created On : 04-Mar-2011
C&I Number :
Requirement # : To fix defect
Method Name: function CMISRTValidate(Inputs, Outputs)
Functionality: To make sure that user can add only one record with Quantity equal to 99 and Group equal to 999
Input: None
Output: None
Customization Approval #: NA
************************************************************************************************************************/
try{
if(TheApplication()==null){
return;
}
if (TheApplication().ActiveBusObject()==null){
return;
}
var flag = TheApplication().GetProfileAttr("CMIRefileSRTFlag");
if(flag == "Y"){
TheApplication().SetProfileAttr("CMIRefileSRTFlag","N");
return;
}
var BCname = TheApplication().ActiveBusObject().Name();
if(BCname != "CMI Claims"){
return;
}
var activeBC = TheApplication().ActiveBusObject().GetBusComp("CMI Claims SRT Details");
var ClaimBO = TheApplication().GetBusObject("CMI Claims");
var SRTBC = ClaimBO.GetBusComp("CMI Claims SRT Details");
var Claimsid = activeBC.GetFieldValue("CMI Claims Id");
var Rowid = activeBC.GetFieldValue("Id");
var Group = activeBC.GetFieldValue("CMI Group");
var Quantity = activeBC.GetFieldValue("CMI SRT Quantity");
if(Quantity!=99 && Group!='999'){
return;
}
with(SRTBC){
ActivateField("CMI Claims Id");
ActivateField("CMI Group");
ActivateField("CMI SRT Quantity");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("CMI Claims Id","='"+Claimsid+"' AND [Id] <> '"+Rowid+"' AND [CMI Group] ='999' AND [CMI SRT Quantity] = '99'");
ExecuteQuery(ForwardOnly);
var firstrecord = FirstRecord();
if(firstrecord){
TheApplication().RaiseErrorText("User can add only one record with Quantity equal to 99 and Group equal to 999.");
}
}
}catch(e)
{
throw(e);
}
finally
{
activeBC = null;
ClaimBO = null;
SRTBC = null;
Claimsid = null;
Rowid = null;
Group = null;
Quantity = null;
//Added by shanmukh for code clean up 08/26/2011
BCname = null;
}
}

CMI Claim Submit BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//try catch added by shanmukh for code clean up 08/22/2011
try
{
if (MethodName == "GenerationBatchNumber")
{
GenerationBatchNumber(Inputs, Outputs);
return(CancelOperation);
}
if (MethodName == "GenerationClaimNumber")
{
GenerationClaimNumber(Inputs, Outputs);
return(CancelOperation);
}
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}//end of catch
return (ContinueOperation);
}

CMI Claim Submit BS
GenerationClaimNumber
function GenerationClaimNumber(Inputs, Outputs)
{
/********************************************************************************
* Name: GenerationClaimNumber
* Module: Generic
* Created Date: 14 March 2011
* Created By: ju982
* Description: This function retrives the next sequence for External Claim Number field.
* Input: Distributor Code
* Output: Claim Sequence
* Revision History:
* Modified By:
* Date of Modification:
* Modification Description:
*********************************************************************************/
try
{
var sDistCode = Inputs.GetProperty("DistCode");
var sWarrId = Inputs.GetProperty("WarrId");//DBUNG00004824 Accepting Warranty Id by ko981 on 01/19/2012
var isRecord, currClaimNum;
var newClaimNum = 0;
var maxseq = TheApplication().InvokeMethod("LookupValue","CMI_GENERIC","Max Claim Number");
var sWarrBusUnit = "";//DBUNG00004824 Declaring Business unit variable by ko981 on 01/19/2012
//DBUNG00004824 Querying against Warranty to find Warranty Business Unit by ko981 on 01/19/2012
var oWarrantyBO = TheApplication().GetBusObject("FS Warranty");
var oWarrantyBC = oWarrantyBO.GetBusComp("FS Warranty");
with (oWarrantyBC)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Claim Bus Entity");
SetSearchSpec("Id", sWarrId);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
sWarrBusUnit = GetFieldValue("CMI Claim Bus Entity");
}//end if
}//end with
var sBO = TheApplication().GetBusObject("CMI Claims");
var sBC = sBO.GetBusComp("CMI INS Claims Simple");
if (sWarrBusUnit != "Internal" && sWarrBusUnit != "Other")//DBUNG00004824 Allow claim number generation only for Cummins Warranties by ko981 on 01/19/2012
{
with(sBC)
{
ClearToQuery();
SetViewMode(AllView);
SetSearchExpr("[CMI Distributor Code] = '" + sDistCode + "' AND [CMI External Claim Number] IS NOT NULL");
SetSortSpec("Created (DESCENDING)"); //KM329 Moved from below the ExecuteQuery to above :Defect#904 9th Dec 2011
ExecuteQuery(ForwardOnly);
isRecord = sBC.FirstRecord();
if(isRecord)
{
ActivateField("CMI External Claim Number");
currClaimNum = GetFieldValue("CMI External Claim Number");
newClaimNum= currClaimNum;
if ( currClaimNum == maxseq )
{
newClaimNum = 1;
}
else
{
newClaimNum++;
}
}
else
{
newClaimNum = 1;
}
Outputs.SetProperty("newClaimNum",newClaimNum);
}//end with(sBC)
}//end if
}//end try
catch(e)
{
throw(e);
}
finally
{
oWarrantyBC = null;
oWarrantyBO = null;
sBC = null;
sBO = null;
}
}

CMI Claim Submit BS
GenerationBatchNumber
/*******************************************************************************************
Created By :<Zero Zhou>
Created On : <11/8/2010>
Method Name:GenerationBatchNumber(Inputs, Outputs)
C&I Number:
Requirement #:
Functionality: Generate Batch Number
Input:
Output:
****************************************************************************************** */
function GenerationBatchNumber(Inputs, Outputs)
{
try
{
var oBOClaim = TheApplication().ActiveBusObject();
var oBCClaim = oBOClaim.GetBusComp("INS Claims");
var oBOUser = TheApplication().GetBusObject("Users");
var oBCUser = oBOUser.GetBusComp("User");
var sDistributor = "";
var sBatchNumber = "";
var sDate = Date.fromSystem(Clib.time());
var stime;
var sLoginId = TheApplication().LoginId();
with(oBCUser)
{
SetViewMode(AllView);
ActivateField("Last Name");
ClearToQuery();
SetSearchSpec("Id", sLoginId);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
sDistributor = GetFieldValue("Last Name");
}
}
with(oBCClaim)
{
ActivateField("CMI Distributor Approver");
ActivateField("CMI Batch Number");
stime = sDate.getFullYear().toString()+sDate.getMonth().toString()+sDate.getDate().toString();
sBatchNumber = sDistributor+stime;
SetFieldValue("CMI Batch Number", sBatchNumber);
SetFieldValue("CMI Distributor Approver",sDistributor);
WriteRecord();
}
oBCClaim.InvokeMethod("RefreshBuscomp");
}
catch(e)
{
throw(e);
}
finally
{
oBCUser = null;
oBOUser = null;
sDate = null;
oBCClaim = null;
oBOClaim = null;
}
}

CMI Claims Refresh BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*************************************************************************************************************************
Created By : JR418
Created On : 11-MAR-11
C&I Number :
Requirement # :
Method Name: function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
Functionality: To refresh the CMI My Claims View.
Input: None
Output: None
Customization Approval #: NA
************************************************************************************************************************/
try
{
if(MethodName=="saveSeachSpec")
{
var ActivedBC = TheApplication().ActiveBusObject().GetBusComp("INS Claims");
var spearchSpec = ActivedBC.GetSearchExpr();
TheApplication().SetProfileAttr("CMIClaimsSpec",spearchSpec);
return (CancelOperation);
}
if(MethodName=="refreshApplet")
{
//Modified By KL968 for Req. Ref. 2366 on 08/27/2011 to use profile attribute instead of Application method name as part of the Code Clean Up Activity
//if(TheApplication().ActiveViewName()=="CMI My Claims View")
if(TheApplication().GetProfileAttr("ActiveViewName")=="CMI My Claims View")
{
var ActivedBc = TheApplication().ActiveBusObject().GetBusComp("INS Claims");
ActivedBc.ClearToQuery();
ActivedBc.ExecuteQuery();
}
return (CancelOperation);
}
}catch (e)
{
throw (e);
}
finally
{
ActivedBC = null;
ActivedBc = null;
spearchSpec = null;
}
return (ContinueOperation);
}

CMI Common Quote BS
InactiveInbox
/************************************************************************************************************
Created By : JF344
Created On : 25-Nov-2010
C&I Number :
Requirement # :
Method Name: InactiveInbox
Functionality:
Input: None
Output: None
Customization Approval #: NA
*************************************************************************************************************/
function InactiveInbox(Inputs,Outputs)
{
//incative inbox item and inbox item owner
try{
var sQuoteId = Inputs.GetProperty("RowId");
var boInbox = TheApplication().GetBusObject("UInbox Item History");
var bcInboxItem = boInbox.GetBusComp("UInbox Item");
with(bcInboxItem)
{
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Item Object Id",sQuoteId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var bcInboxTask = boInbox.GetBusComp("UInbox Item Task");
// with(bcInboxTask) // Commented by JW227 for TAM Comment#1 on 02/07/2012
// {
bcInboxTask.ClearToQuery();
bcInboxTask.ActivateField("Active Flag");
bcInboxTask.ExecuteQuery(ForwardOnly);
var bHasRecord = bcInboxTask.FirstRecord();
while(bHasRecord)
{
bcInboxTask.SetFieldValue("Active Flag","N");
bHasRecord = bcInboxTask.NextRecord();
}
// }
}
}
}catch(e){//added by jj638
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}finally{
bcInboxItem = null;
boInbox =null;
sQuoteId = null;//added by jj638 on 25 may 2011
//added by shanmukh for code clean up 08/22/2011
bcInboxTask = null;
}
}

CMI Common Quote BS
LookupOwner
function LookupOwner(sQuoteId,sPrimPosId)
{
// Tiger: Set owner to parent position user. Sales Supervisor
/*********************************************************
AUTHOR: JF344
Purpose: This function is used in CMI Quote Expired WF. When quote is expired, an activity is created for trace.
INPUTS: QuoteId
OUTPUTS: None
DATE CREATED: 31/Aug/2010
UPDATES:
*********************************************************/
try
{
var sReturn = "";
var bcPosition = TheApplication().GetBusObject("Position").GetBusComp("Position");
with(bcPosition)
{
ActivateField("Position Type");
ActivateField("Employee Id");
ActivateField("CMI Parent Employee Id");
ClearToQuery();
SetSearchSpec("Id", sPrimPosId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sReturn = GetFieldValue("CMI Parent Employee Id");
}
}
return sReturn;
}
catch(e)
{
return "";
}
finally{
bcPosition = null;
}
}

CMI Common Quote BS
ProcessCharge
function ProcessCharge()
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS:
Purpose: Engine Down Premium should charge 15 % of the line item total.
its the value of LOV. when choosing this value, the value should be 15% of line item total
Addition of additional value in the Freight Charges LOV: Emergency similar to Engine Premium Down but charges 5 % of the line item total.
OUTPUTS: None
DATE CREATED: 25/10/2010
UPDATES:
*********************************************************/
var nTotal, nFreight4Edp, sFreight;
try {
var bcQuote = TheApplication().ActiveBusObject().GetBusComp("Quote");
if(bcQuote.GetFieldValue("CMI Freight Charges") == TheApplication().InvokeMethod("LookupValue","CMI_CHARGE","Emergency"))
{//set Emergency to 5% of total line item.
nTotal = bcQuote.GetFieldValue("Current Quote Total Net Price");
nFreight4Edp = parseInt(nTotal) * 0.05;
bcQuote.SetFieldValue("Freight",nFreight4Edp);
}
else if(bcQuote.GetFieldValue("CMI Freight Charges") == TheApplication().InvokeMethod("LookupValue","CMI_CHARGE","Engine down premium"))
{//set Emergency to 5% of total line item.
nTotal = bcQuote.GetFieldValue("Current Quote Total Net Price");
nFreight4Edp = parseInt(nTotal) * 0.15;
bcQuote.SetFieldValue("Freight",nFreight4Edp);
}
else
{
//Get value from LOV by Description
// var bcLOV = TheApplication().GetBusObject("List Of Values").GetBusComp("List Of Values");//Commented by ko981 on 12/16/2011
var bcLOV = TheApplication().GetBusObject("List of Values Query").GetBusComp("List of Values Query"); // From Oracle Review#17 Added by ko981 on 12/16/2011
with (bcLOV)
{
ClearToQuery();
ActivateField("Description");
var sFreightCharges = bcQuote.GetFieldValue("CMI Freight Charges");
// SetSearchExpr("[Value] ='" + sFreightCharges +"' AND [Type] = 'CMI_CHARGE' AND [Language] = '" + TheApplication().InvokeMethod("Language")+"'"); //Commented by ko981 on 12/16/2011
SetSearchExpr("[Value] ='" + sFreightCharges + "' AND [Type] = 'CMI_CHARGE' AND [Language] = '" + TheApplication().InvokeMethod("Language") + "' AND [Active] = 'Y'"); // From Oracle Review#17 Added by ko981 on 12/16/2011
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sFreight = GetFieldValue("Description");
bcQuote.SetFieldValue("Freight",sFreight);
}
}
}
}
catch(e)
{
}
finally
{
bcLOV = null;
//Added by shanmukh for code clean up 08/26/2011
bcQuote = null;
}
}

CMI Common Quote BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: build by jf344, Common business service used for quote
INPUTS:
OUTPUTS: None
DATE CREATED: 31/Aug/2010
UPDATES:
*********************************************************/
//Try catch added by shanmukh for code clean up 08/19/2011
try
{
if(MethodName == "CreateActivity")
{
CreateActivity(Inputs,Outputs);
return CancelOperation;
}
if(MethodName == "ProcessCharge")
{
ProcessCharge(Inputs,Outputs);
return CancelOperation;
}
if(MethodName == "InactiveInbox")
{
InactiveInbox(Inputs,Outputs);
return CancelOperation;
}
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
return (ContinueOperation);
}

CMI Common Quote BS
CreateActivity
function CreateActivity(Inputs,Outputs)
{
/*********************************************************
AUTHOR: JF344
Purpose: This function is used in CMI Quote Expired WF. When quote is expired, an activity is created for trace.
INPUTS: QuoteId
OUTPUTS: None
DATE CREATED: 31/Aug/2010
UPDATES:
*********************************************************/
try
{
var sQuoteId = Inputs.GetProperty("QuoteId");
var boQuote = TheApplication().GetBusObject("Quote");
var bcQuote = boQuote.GetBusComp("Quote");
var bcAction = boQuote.GetBusComp("Action (Quote Order)");
with(bcQuote)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Name");
ActivateField("Sales Rep Position Id");
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var sQuoetName = GetFieldValue("Name");
var sPrimPosId = GetFieldValue("Sales Rep Position Id");
//lookup service supervisor
var sOwnerId = LookupOwner(sQuoteId,sPrimPosId);
if(sOwnerId == "") sOwnerId = sPrimPosId;
// with(bcAction) // Commented by JW227 for TAM Comment#1 on 02/07/2012
// {
bcAction.NewRecord(NewAfter);
bcAction.SetFieldValue("Description", "The quote: '"+ sQuoetName +"' has not been accepted before Due date");
bcAction.SetFieldValue("Primary Owner Id",sOwnerId);
try
{
bcAction.WriteRecord();
}
catch(e)
{}
// }
}
}
}
catch(e)
{
var a = e.toString();
}
finally{
bcAction=null;
bcQuote = null;
boQuote= null;
}
}

CMI Create GL Record
ClaimCompletionCOGGL
/*************************************************************************************************************************
Created By : Elen Yu (JR427)
Created On : 2011-3-25
C&I Number : 4658
Functionality: Invoked through RTE on write record of INS Claims BC.It creates GL record for Claim Completion COG scenario.
Modified by KL968 for C & I 4457,Req# 271 on 09/15/2011 for creating GL Records for Write In Products
************************************************************************************************************************/
function ClaimCompletionCOGGL() {
try {
TheApplication().Utility.logStack("ClaimCompletionCOGGL", this);
var oBOClaim = TheApplication().GetBusObject("CMI Claims");//--Added by KM331 for DBUNG00004002 on 12/13/2011;
var oBCClaim = oBOClaim.GetBusComp("INS Claims");
var sClaimId = TheApplication().GetProfileAttr("CMISRClaimId");//--Added by KM331 for DBUNG00004002 on 12/13/2011;
var oBOGL= TheApplication().GetBusObject("CMI GL Entry");
var oBCGL= oBOGL.GetBusComp("CMI GL Entry");
var sOrderBO = TheApplication().GetBusObject("Order Entry (Sales)");
var sOrderBC = sOrderBO.GetBusComp("Order Entry - Orders");
var sOLIBC = sOrderBO.GetBusComp("Order Entry - Line Items");
var sDivisionId = "";
var sClaimCategory;
var sTotalExtdCost;
var sWarrantyId;
var iClaimLaborHrs = 0;
var iClaimTravelHrs = 0;
var sOrderId;
var isOrderRec;
var sTotalSRTHrs = 0;
var sTotalCost = 0;
var sGLAmount = 0;
var sDealerCode;
var sOrgId;
var sSRId;
var isSRRec;
var sLocalCurcyCd;//added by sheldon
var sOrderLocalCurcyCode;//added by sheldon
var sExtendedCostOthers;//Added by KL968 for C & I 4457,Req# S271 on 09/15/2011
var sQtyReq = 0;
var sSRTHrs = 0;
var sSRTQty = 0;
var sMarkUp = 0;
var sSRClaim = TheApplication().InvokeMethod("LookupValue","CMI_CLAIM_CATEGORY","SR Claim");
if(oBCClaim != null) {
with(oBCClaim) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Claim Category");
ActivateField("CMI Total Extended Cost");
ActivateField("CMI FS Warranty Id");
ActivateField("CMI Dealer Code");
ActivateField("CMI Order Id");
// ActivateField("CMI Total SRT Claim Hrs");
ActivateField("Primary Organization Id");
ActivateField("CMI Branch Id");
ActivateField("CMI Service Request Id");
ActivateField("Currency Code");//added by sheldon
ActivateField("CMI Total Extended Cost Others");//Added by KL968 for C & I 4457,Req# S271 on 09/15/2011
ActivateField("CMI Total SRT Claim Hrs");
ActivateField("CMI SRT Travel Hours Qty");
SetSearchSpec("Id", sClaimId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Claim ("+sClaimId+") Found?", FirstRecord());
if(FirstRecord()) {
sDealerCode = GetFieldValue("CMI Dealer Code");
sClaimCategory = GetFieldValue("CMI Claim Category");
sTotalExtdCost = GetFieldValue("CMI Total Extended Cost");
sWarrantyId = GetFieldValue("CMI FS Warranty Id");
// sClaimHrs = GetFieldValue("CMI Total SRT Claim Hrs");
iClaimLaborHrs = ToNumber(GetFieldValue("CMI Total SRT Claim Hrs"));
iClaimTravelHrs = ToNumber(GetFieldValue("CMI SRT Travel Hours Qty"));
sOrderId = GetFieldValue("CMI Order Id");
sOrgId = GetFieldValue("Primary Organization Id");
sSRId = GetFieldValue("CMI Service Request Id");
sLocalCurcyCd = GetFieldValue("Currency Code");//added by sheldon
sExtendedCostOthers = GetFieldValue("CMI Total Extended Cost Others");////Added by KL968 for C & I 4457,Req# S271 on 09/15/2011
sDivisionId = GetFieldValue("CMI Branch Id");
}
}
}
TheApplication().Utility.logVars("Claim Category", sClaimCategory);
if(sClaimCategory == sSRClaim) {
var sSRBO = TheApplication().GetBusObject("Service Request");
var sSRBC = sSRBO.GetBusComp("Service Request");
with(sSRBC) {
SetViewMode(AllView);
ActivateField("Primary Organization Id");
ActivateField("CMI Primary Division Id");
ClearToQuery();
SetSearchSpec("Id", sSRId);
ExecuteQuery();
isSRRec = FirstRecord();
if(isSRRec) {
sOrgId = GetFieldValue("Primary Organization Id");
sDivisionId = GetFieldValue("CMI Primary Division Id");
}
}
//Create Parts COGS GL Entry
TheApplication().Utility.logVars("Total Extended Cost", sTotalExtdCost);
if(sTotalExtdCost != null && sTotalExtdCost != "" && sTotalExtdCost != 0) {
with(oBCGL) {
NewRecord(NewAfter);
SetFieldValue("Amount", sTotalExtdCost);
SetFieldValue("Claim Id", sClaimId);
SetFieldValue("Warranty Id", sWarrantyId);
SetFieldValue("Status", TheApplication().InvokeMethod("LookUpValue", "CMI_GL_STATUS", "Submit"));
SetFieldValue("Transaction Type", "Claim Completion COG");
SetFieldValue("Organization Id", sOrgId);
SetFieldValue("Division Id", sDivisionId);
SetFieldValue("Currency Code", sLocalCurcyCd);//added by sheldon
SetFieldValue("Sub Type", "Part");
SetFieldValue("Service Request Id", sSRId);
WriteRecord();
}
}//end of if(sTotalExtdCost != null && sTotalExtdCost != "" && sTotalExtdCost != 0)
with(sOrderBC) {
SetViewMode(AllView);
ActivateField("CMI Total Labor SRT Hrs");
ActivateField("CMI Total Time Cost");
ActivateField("CMI Local Currency Code");//added by sheldon
ActivateField("CMI Time Cost - Calc");
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery();
isOrderRec = FirstRecord();
TheApplication().Utility.logVars("Order ("+sOrderId+") Found?", isOrderRec);
if(isOrderRec) {
sTotalCost = GetFieldValue("CMI Time Cost - Calc");//MJB 6/5/12 cq8165 GetTotalTimeCost(sOrderId);
sOrderLocalCurcyCode = GetFieldValue("CMI Local Currency Code");//added by sheldon
with(sOLIBC) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Markup Multiplier");
ActivateField("CMI SRT Quantity");
ActivateField("CMI SRT Hours");
ActivateField("Product Type");
ActivateField("Quantity Requested");
SetSearchSpec("Order Header Id", sOrderId);
SetSearchSpec("Product Type", "Labor");
ExecuteQuery(ForwardOnly);
var bisRecord = FirstRecord();
TheApplication().Utility.logVars("1st Order Line Found?", bisRecord);
while(bisRecord) {
sQtyReq = ToNumber(GetFieldValue("Quantity Requested"));
sSRTHrs = ToNumber(GetFieldValue("CMI SRT Hours"));
sSRTQty = ToNumber(GetFieldValue("CMI SRT Quantity"));
sMarkUp = ToNumber(GetFieldValue("CMI Markup Multiplier"));
if(sSRTHrs == 0) {
sTotalSRTHrs = ToNumber(sTotalSRTHrs) + ToNumber(sQtyReq);
} else {
sTotalSRTHrs = ToNumber(sTotalSRTHrs) + (sSRTHrs*sSRTQty);//MJB 6/5/12 cq8165 remove *(1+(sMarkUp/100))
}
bisRecord = NextRecord();
}
}
//Create Labor COGS GL Entry
sGLAmount = ((iClaimLaborHrs + iClaimTravelHrs)/ToNumber(sTotalSRTHrs)) * ToNumber(sTotalCost);
TheApplication().Utility.logStep("Labor = ((Claim Travel + Labor Hours) / Total SRT Hours) * Total Cost");
TheApplication().Utility.logVars("Claim Travel Hours", iClaimTravelHrs,"Claim Labor Hours", iClaimLaborHrs, "Total SRT Hours", sTotalSRTHrs, "Total Cost", sTotalCost, "Labor", sGLAmount);
if(sGLAmount != null && sGLAmount != "" && sGLAmount != 0) {
with(oBCGL) {
NewRecord(NewAfter);
SetFieldValue("Amount", sGLAmount);
SetFieldValue("Claim Id", sClaimId);
SetFieldValue("Warranty Id", sWarrantyId);
SetFieldValue("Status", TheApplication().InvokeMethod("LookUpValue", "CMI_GL_STATUS", "Submit"));
SetFieldValue("Transaction Type", "Claim Completion COG");
SetFieldValue("Organization Id", sOrgId);
SetFieldValue("Division Id", sDivisionId);
SetFieldValue("Sub Type", "Labor");
SetFieldValue("Currency Code", sOrderLocalCurcyCode);//added by sheldon
SetFieldValue("Service Request Id", sSRId);
WriteRecord();
}
}// End of if(sGLAmount != null && sGLAmount != "" && sGLAmount != 0)
//Create Misc COGS GL Entry
TheApplication().Utility.logVars("Extended Cost - Others", sExtendedCostOthers);
if(sExtendedCostOthers != null && sExtendedCostOthers != "" && ToNumber(sExtendedCostOthers) != 0) {
with(oBCGL) {
NewRecord(NewAfter);
SetFieldValue("Amount", sExtendedCostOthers);
SetFieldValue("Claim Id", sClaimId);
SetFieldValue("Warranty Id", sWarrantyId);
SetFieldValue("Status", TheApplication().InvokeMethod("LookUpValue", "CMI_GL_STATUS", "Submit"));
SetFieldValue("Transaction Type", "Claim Completion COG");
SetFieldValue("Organization Id", sOrgId);
SetFieldValue("Division Id", sDivisionId);
SetFieldValue("Sub Type", "Misc");
SetFieldValue("Currency Code", sOrderLocalCurcyCode);
SetFieldValue("Service Request Id", sSRId);
WriteRecord();
}
}//End of if(sExtendedCostOthers != Null && sExtendedCostOthers != "" && sExtendedCostOthers != 0)
}// end of isOrderRec
}// end of sOrderBC
}// end of if(sClaimCategory == "SR Claim")
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sOLIBC = null;
sOrderBC = null;
oBCGL = null;
oBCClaim = null;
sOrderBO = null;
oBOGL = null;
oBOClaim = null;
sSRBC = null;
sSRBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Create GL Record
CreateBillableGL
/*************************************************************************************************************************
Created By : Woody Wu (JR426)
Created On : 2011-3-22
C&I Number : 4658
Functionality: This is triggered from WriteRecordScript of PDS Simplified Order Entry – Orders BC.
It creates GL record for billable labor.
************************************************************************************************************************/
function CreateBillableGL(sOrderId) {
try {
TheApplication().Utility.logStack("CreateBillableGL", this);
var sBO = TheApplication().GetBusObject("Action");
var sOrderBO = TheApplication().GetBusObject("Order Entry (Sales)");
var sBC = sOrderBO.GetBusComp("Order Entry - Orders");
var sActBC = sBO.GetBusComp("Action");
var sGLBO = TheApplication().GetBusObject("CMI GL Entry");
var sGLBC = sGLBO.GetBusComp("CMI GL Entry"); //pls add a standalone entry for GL BC in above BO.
var IsRec;
var IsActRec;
var IsActSubRec;
var sTimeTrackerCost:float = 0;
var sTotalTimeTrackerCost:float = 0;
var sElaspedTime;
var sTotalTTCost:float = 0;
var sTotalElaspedTime = null;
//added by woody
var sSRDivCurrencyCode, sOrgId, divisionId, sSrvReqId;
var bcMVGTimeSheet = null;
var isTimeSheetRec;
with(sBC) {
SetViewMode(AllView);
//added by woody
ActivateField("Primary Organization Id");//CMI DBU Release#3, Defect#3643, Added by KM331 on 02/01/2012;
ActivateField("CMI Primary Division Id");
ActivateField("Service Request Id");//CMI DBU,CQ Ticket#DBUNG00001373 Added by jq486 on Oct 13 2011
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
IsRec = FirstRecord();
TheApplication().Utility.logVars("Order Found?", IsRec);
if(IsRec) {
sOrgId = GetFieldValue("Primary Organization Id");//CMI DBU Release#3, Defect#3643, Added by KM331 on 02/01/2012;
sSrvReqId = GetFieldValue("Service Request Id");//CMI DBU,CQ Ticket#DBUNG00001373 Added by jq486 on Oct 13 2011
sSRDivCurrencyCode = GetFieldValue("Currency Code");
divisionId = GetFieldValue("CMI Primary Division Id");
with(sActBC) {
SetViewMode(AllView);
ActivateField("Order Id");
ActivateField("CMI Total Elapsed Time");
ActivateField("CMI Total Time Cost");
ActivateField("CMI Time Cost");
ActivateField("Currency Code");
ActivateField("Type");
// ActivateField("Primary Owner By Organization Id");
ClearToQuery();
SetSearchSpec("Order Id", sOrderId); // might not need this as we are already in context. Can be removed during Dev if not needed
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Service Labor"));
ExecuteQuery(ForwardOnly);
IsActRec = FirstRecord();
TheApplication().Utility.logVars("1st Service Labor Found?", IsActRec);
while(IsActRec) { // 5/22/12: KK: CQ# 7346
bcMVGTimeSheet = GetMVGBusComp("CMI Time Cost");
with (bcMVGTimeSheet) {
SetViewMode(AllView);
ActivateField("Time Cost");
ActivateField("CMI Time Cost - Calc");
ExecuteQuery();
isTimeSheetRec = FirstRecord();
while(isTimeSheetRec) {
sTimeTrackerCost = GetFieldValue("CMI Time Cost - Calc");
sTotalTimeTrackerCost = ToNumber(sTotalTimeTrackerCost) + ToNumber(sTimeTrackerCost) ;
isTimeSheetRec = NextRecord();
}
}
//sActBC.InvokeMethod("CompleteActivity");
sElaspedTime = GetFieldValue("CMI Total Elapsed Time");
//sTimeTrackerCost = GetFieldValue("CMI Total Time Cost");
//added by woody
// billz - 4/242012 - updated GL Total Amount expression...removed ToNumber
sTotalTTCost = ToNumber(sTotalTTCost) + ToNumber(sTotalTimeTrackerCost);
sTotalTimeTrackerCost=0;
sTotalElaspedTime = sTotalElaspedTime + sElaspedTime; //formatting needs to be done to add time
IsActRec = NextRecord();
}//End of While(IsActRec)
}//end of if(sACTBC)
with(sGLBC) {
TheApplication().Utility.logVars("Total Cost", sTotalTTCost);
if(sTotalTTCost != 0) {
NewRecord(NewAfter);
SetFieldValue("Amount", sTotalTTCost);
SetFieldValue("Transaction Type", "Billable Labor");
SetFieldValue("Status", TheApplication().InvokeMethod("LookupValue","CMI_GL_STATUS","Submit"));
SetFieldValue("Currency Code",sSRDivCurrencyCode)
SetFieldValue("Division Id", divisionId);
SetFieldValue("Organization Id", sOrgId);
SetFieldValue("Order Id", sOrderId);
SetFieldValue("Service Request Id", sSrvReqId);//CMI DBU,CQ Ticket#DBUNG00001373 Added by jq486 on Oct 13 2011
WriteRecord();
}//end of if(sTotalTTCost != null && sTotalTTCost != "" && sTotalTTCost != 0)
}//end of with(sGLBC)
with(sActBC) {
SetViewMode(AllView);
ActivateField("Order Id");
ActivateField("Status");
ClearToQuery();
SetSearchSpec("Order Id", sOrderId); // might not need this as we are already in context. Can be removed during Dev if not needed
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Service Labor"));
ExecuteQuery(ForwardOnly);
IsActRec = FirstRecord();
TheApplication().Utility.logVars("1st Service Labor Found?", IsActRec);
while(IsActSubRec) {
SetFieldValue("Status", TheApplication().InvokeMethod("LookUpValue", "EVENT_STATUS", "Done"));//pls use lookup value method to get value 'Done'
WriteRecord();
IsActSubRec = NextRecord();
}//End of While(IsActRec)
}//end of with(sActBC)
}//End of If(IsRec)
}//End of with(sBC)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sGLBC = null;
sActBC = null;
sBC = null;
sGLBO = null;
sBO = null;
//added by shanmukh for code clean up 08/22/2011
sOrderBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Create GL Record
CreateClaimClosureGL
/*************************************************************************************************************************
Created By : Jacky Huang (JJ631)
Created On : 2011-3-22
C&I Number : 4658
Functionality: Will be triggered through RTE on Write Record on INS Claims Payments BC when Status = Verified.
It creates GL record for Claim Closure scenario
************************************************************************************************************************/
function CreateClaimClosureGL() {
try {
TheApplication().Utility.logStack("CreateClaimClosureGL", this);
var boClaim = TheApplication().GetBusObject("CMI Claims");
var bcClaimPayment = boClaim.GetBusComp("INS Claims Payments");
var bcClaim = boClaim.GetBusComp("INS Claims");
var boGLEntry = TheApplication().GetBusObject("CMI GL Entry");
var bcGLEntry = boGLEntry.GetBusComp("CMI GL Entry");
var boSR:BusObject = TheApplication().GetBusObject("Service Request");
var bcSR:BusComp = boSR.GetBusComp("Service Request");
var bcSRClaim:BusComp = boSR.GetBusComp("INS Claims");
var sClaimId = TheApplication().GetProfileAttr("CMIClaimId");
var sClaimPaymentId = TheApplication().GetProfileAttr("CMIClaimPaymentId");
var sDivisionId = "";
var isClaimRec;
var isClaimPayRec;
var sPayTo:String;
var sServReqId:String;
var claimStatusClosed = TheApplication().InvokeMethod("LookupValue", "INS_CLAIM_STATUS", "Closed");
var noEarlyCredit = TheApplication().InvokeMethod("LookupValue", "CMI_EARLY_CREDIT", "No Early Credit");
var srSubStatusClosed = TheApplication().InvokeMethod("LookupValue", "SR_SUB_STATUS", "Closed");
var openClaims = false;
with(bcClaim) {
SetViewMode(AllView);
ActivateField("Primary Organization Id");
ActivateField("CMI FS Warranty Id");
ActivateField("CMI Early Credit");
ActivateField("Status Code");
ActivateField("CMI Pay To");
ActivateField("CMI Payment Variance Sum");
ActivateField("CMI Service Request Id");
ActivateField("CMI Branch Id");
ClearToQuery();
SetSearchSpec("Id", sClaimId);
ExecuteQuery();
isClaimRec = FirstRecord();
TheApplication().Utility.logVars("Claim ("+sClaimId+") found?", isClaimRec);
if(isClaimRec) {
var sWarrantyId = GetFieldValue("CMI FS Warranty Id");
var sOrganizationId = GetFieldValue("Primary Organization Id");//Changed GetFieldValue from CMI Organization Id to Primary Organization Id by woody on 2011-7-25
sPayTo = GetFieldValue("CMI Pay To");
sServReqId = GetFieldValue("CMI Service Request Id");
sDivisionId = GetFieldValue("CMI Branch Id");
with(bcClaimPayment) {
SetViewMode(AllView);
ActivateField("Payment Amount");
ActivateField("CMI Payment Credit Type");
ActivateField("Currency Code");
ClearToQuery();
SetSearchSpec("Id", sClaimPaymentId);
ExecuteQuery();
isClaimPayRec = FirstRecord();
TheApplication().Utility.logVars("Claim Payment ("+sClaimPaymentId+") found?", isClaimPayRec);
if(isClaimPayRec) {
var sClaimPayment = GetFieldValue("Payment Amount");//change from Payment Amount to CMI Payment Amount Other by Jacky
var sPaymentCreditType = GetFieldValue("CMI Payment Credit Type");
var sLocalCurcyCd = GetFieldValue("Currency Code");
}
}//end of bcClaimPayment
//Setting Claims Status and Early Credit when Pay To is Customer
TheApplication().Utility.logVars("Pay To", sPayTo.valueOf(), "Balance Due", GetFieldValue("CMI Payment Variance Sum"));
if(sPayTo.valueOf() == TheApplication().InvokeMethod("LookupValue", "CMI_CLAIMS_PAYTO", "Customer")) {
TheApplication().SetProfileAttr("ClaimNextStatus", claimStatusClosed);
InvokeMethod("ProgressStatus");
}
}//end of if(isClaimRec)
}//end of with(bcClaim)
//Script to make the status of Claims Closed, added by IY795 as per S139
TheApplication().Utility.logVars("Service Request Id", sServReqId);
if(sServReqId != null && sServReqId != "") {
with(bcSR) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sServReqId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
with(bcSRClaim) {
SetViewMode(AllView);
ActivateField("Status Code");
ClearToQuery();
SetSearchSpec("Status Code", "<> '" + claimStatusClosed + "'");
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Open Claims found?", FirstRecord());
if(FirstRecord()) {
openClaims = true;
}
}//end of with(bcSRClaim)
//If no open claims are found, close the SR
if(openClaims == false) {
SetFieldValue("Sub-Status", srSubStatusClosed);
WriteRecord();
}
}//end of if(FirstRecord()
}//end of with(bcSR)
}
with(bcGLEntry) {
NewRecord(NewAfter);
SetFieldValue("Claim Id", sClaimId);
SetFieldValue("Warranty Id", sWarrantyId);
SetFieldValue("Transaction Type", "Claim Closure");
SetFieldValue("Amount", sClaimPayment);
SetFieldValue("Sub Type", sPaymentCreditType);
SetFieldValue("Organization Id", sOrganizationId);
SetFieldValue("Division Id", sDivisionId);
SetFieldValue("Currency Code", sLocalCurcyCd);
SetFieldValue("Service Request Id", sServReqId);
WriteRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcGLEntry = null;
bcClaimPayment = null;
boGLEntry = null;
bcClaim = null;
boClaim = null;
bcSRClaim = null;
bcSR = null;
boSR = null;
TheApplication().Utility.logUnstack();
}
}

CMI Create GL Record
CreateClaimCompletionGL
/*************************************************************************************************************************
Created By : Elen Yu (JR427)
Created On : 2011-3-25
C&I Number : 4658
Functionality: Invoked through RTE on write record of INS Claims BC.It creates GL record for Claim Completion scenario.
************************************************************************************************************************/
function CreateClaimCompletionGL() {
try {
TheApplication().Utility.logStack("CreateClaimCompletionGL", this);
var oBOClaim = TheApplication().GetBusObject("CMI Claims");//--Added by KM331 for DBUNG00004002 on 12/13/2011;
var oBCClaim = oBOClaim.GetBusComp("INS Claims");
var sClaimId = TheApplication().GetProfileAttr("CMISRClaimId");//--Added by KM331 for DBUNG00004002 on 12/13/2011;
var oBOGL= TheApplication().GetBusObject("CMI GL Entry");
var oBCGL= oBOGL.GetBusComp("CMI GL Entry");
var sDivisionId = "";
var sDealerCode;
var sBFC;
var sPMU;
var sPartTotal;
var sWarrantyId;
var sPartAmount;
var sLaborAmount;
var sMiscAmount;
var sTotalLabor;
var sTotalTravel;
var sClaimCat;
var sOrgId;
var sSRId;
var isSRRec;
var sLocalCurcyCd;//added by sheldon
var sSRClaim = TheApplication().InvokeMethod("LookupValue","CMI_CLAIM_CATEGORY","SR Claim");
if(oBCClaim != null) {
with(oBCClaim) {
//Added by KM326 to fix 4057 on 14-12-2011 -- Querying INS Claims BC as ActiveBO is removed
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Dealer Code");
ActivateField("CMI BFC Total");
ActivateField("CMI PMU Total");
ActivateField("CMI FS Warranty Id");
ActivateField("CMI Total Labor");
ActivateField("CMI Travel Labor Amount");
ActivateField("CMI Claim Category");
ActivateField("Primary Organization Id");
ActivateField("CMI Branch Id");
ActivateField("CMI Service Request Id");
ActivateField("CMI Misc Total");
ActivateField("CMI Cummins Part");
ActivateField("CMI Service Request Id");
ActivateField("Currency Code");//added by sheldon
//Added by KM326 to fix 4057 on 14-12-2011 -- Querying INS Claims BC as ActiveBO is removed
SetSearchSpec("Id", sClaimId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
sDealerCode = GetFieldValue("CMI Dealer Code");
sBFC = GetFieldValue("CMI BFC Total");
sPMU = GetFieldValue("CMI PMU Total");
sWarrantyId = GetFieldValue("CMI FS Warranty Id");
sTotalLabor = GetFieldValue("CMI Total Labor");
sTotalTravel= GetFieldValue("CMI Travel Labor Amount");
sPartTotal= GetFieldValue("CMI Cummins Part");
sMiscAmount = GetFieldValue("CMI Misc Total");
sClaimCat = GetFieldValue("CMI Claim Category");
sOrgId = GetFieldValue("Primary Organization Id");
sSRId = GetFieldValue("CMI Service Request Id");
sLocalCurcyCd = GetFieldValue("Currency Code");//added by sheldon
sDivisionId = GetFieldValue("CMI Branch Id");
TheApplication().Utility.logVars("Claim Category", sClaimCat);
if(sClaimCat == sSRClaim) {
var sSRBO = TheApplication().GetBusObject("Service Request");
var sSRBC = sSRBO.GetBusComp("Service Request");
with(sSRBC) {
SetViewMode(AllView);
ActivateField("Primary Organization Id");
ActivateField("CMI Primary Division Id");
ClearToQuery();
SetSearchSpec("Id", sSRId);
ExecuteQuery();
isSRRec = FirstRecord();
if(isSRRec) {
sOrgId = GetFieldValue("Primary Organization Id");
sDivisionId = GetFieldValue("CMI Primary Division Id");
}
}
}
//GL for Part
sPartAmount = ToNumber(sPartTotal)+ToNumber(sBFC)+ToNumber(sPMU);
TheApplication().Utility.logVars("Parts Total = Parts + BFC + PMU", sPartAmount+" = "+sPartTotal+" + "+sBFC+" + "+sPMU);
if(sPartAmount != "" && sPartAmount != null && sPartAmount != 0) {
with(oBCGL) {
NewRecord(NewAfter);
SetFieldValue("Amount", sPartAmount);
SetFieldValue("Claim Id", sClaimId);
SetFieldValue("Warranty Id", sWarrantyId);
SetFieldValue("Status", "Submit");
SetFieldValue("Transaction Type", "Claim Completion");
SetFieldValue("Organization Id", sOrgId);
SetFieldValue("Division Id", sDivisionId);
SetFieldValue("Sub Type", "Part");
SetFieldValue("Currency Code", sLocalCurcyCd);//added by sheldon
SetFieldValue("Service Request Id", sSRId);
WriteRecord();
}
}
//GL For SRT
sLaborAmount = ToNumber(sTotalTravel)+ToNumber(sTotalLabor);
TheApplication().Utility.logVars("Labor Total = Travel + Labor", sLaborAmount+" = "+sTotalTravel+" + "+sTotalLabor);
if(sLaborAmount != "" && sLaborAmount != null && sLaborAmount != 0) {
with(oBCGL) {
NewRecord(NewAfter);
SetFieldValue("Amount", sLaborAmount );
SetFieldValue("Claim Id", sClaimId);
SetFieldValue("Warranty Id", sWarrantyId);
SetFieldValue("Status", "Submit");
SetFieldValue("Transaction Type", "Claim Completion");
SetFieldValue("Organization Id", sOrgId);
SetFieldValue("Division Id", sDivisionId);
SetFieldValue("Sub Type", "Labor");
SetFieldValue("Currency Code", sLocalCurcyCd);//added by sheldon
SetFieldValue("Service Request Id", sSRId);
WriteRecord();
}
}
//GL For Misc
sMiscAmount = ToNumber(sMiscAmount);
TheApplication().Utility.logVars("Misc Total", sMiscAmount);
if(sMiscAmount != "" && sMiscAmount != null && sMiscAmount != 0) {
with(oBCGL) {
NewRecord(NewAfter);
SetFieldValue("Amount", sMiscAmount );
SetFieldValue("Claim Id", sClaimId);
SetFieldValue("Warranty Id", sWarrantyId);
SetFieldValue("Status", "Submit");
SetFieldValue("Transaction Type", "Claim Completion");
SetFieldValue("Organization Id", sOrgId);
SetFieldValue("Division Id", sDivisionId);
SetFieldValue("Sub Type", "Misc");
SetFieldValue("Currency Code", sLocalCurcyCd);//added by sheldon
SetFieldValue("Service Request Id", sSRId);
WriteRecord();
}
}
}
}
}//end of with
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCGL = null;
oBCClaim= null;
oBOGL = null;
oBOClaim= null;
sSRBC = null;
sSRBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Create GL Record
CreateDistGL
/*************************************************************************************************************************
Created By : Woody Wu (JR426)
Created On : 2011-3-22
C&I Number : 4658
Functionality: Called from Scan Order function for Distributor Warranty scenario.
************************************************************************************************************************/
function CreateDistGL(sGLAmount, sOrderId, SubType, sFSWarrId, sOrgId,sLocalCurcyCd) {
try {
TheApplication().Utility.logStack("CreateDistGL", this);
var sGLBO = TheApplication().GetBusObject("CMI GL Entry");
var sGLBC = sGLBO.GetBusComp("CMI GL Entry");
var GLAmount = sGLAmount;
var OrderId = sOrderId;
var sType = SubType;
var WarrId = sFSWarrId;
var OrganizationId = sOrgId;
var sCurrencyCode = sLocalCurcyCd;
with(sGLBC) {
NewRecord(NewAfter);
SetFieldValue("Transaction Type", "Distributor Warranty");
SetFieldValue("Order Id", OrderId);
SetFieldValue("Amount", GLAmount);
SetFieldValue("Sub Type", sType);
SetFieldValue("Warranty Id", WarrId);
SetFieldValue("Organization Id", OrganizationId);
SetFieldValue("Currency Code", sCurrencyCode);
WriteRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sGLBC = null;
sGLBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Create GL Record
CreateNonBillableGL
/*************************************************************************************************************************
Created By : Woody Wu (JR426)
Created On : 2011-3-22
C&I Number : 4658
Functionality: Will be triggered through RTE on Write Record on Activity Plan Action BC when Status = Completed
and Activity category = Non billable (pls refer to list for exact values). It creates GL record for non-billable labor.
************************************************************************************************************************/
function CreateNonBillableGL() {
try {
TheApplication().Utility.logStack("CreateNonBillableGL", this);
var sActivityId = TheApplication().GetProfileAttr("CMIActivtyId");// this is set in the Action set of the RTE from where this BS is invoked
var sActBO = TheApplication().GetBusObject("Action");
var sBC = sActBO.GetBusComp("Action");
var sGLBO = TheApplication().GetBusObject("CMI GL Entry");
var sGLBC = sGLBO.GetBusComp("CMI GL Entry");
var IsRec = false;
var sElaspedTime, sTimeTrackerCost, sSrvReqId, sOrgId, sDivId, sLocalCurcyCd;
with(sBC) {
SetViewMode(AllView);
ActivateField("Currency Code");
ActivateField("CMI Total Elapsed Time");
ActivateField("CMI Total Time Cost");
ActivateField("CMI Non Billable GL Organization Id");
ActivateField("CMI Non Billable GL Division Id");
ClearToQuery();
SetSearchSpec("Id", sActivityId);
ExecuteQuery(ForwardOnly);
IsRec = FirstRecord();
TheApplication().Utility.logVars("Activity Found?", IsRec);
if(IsRec) {
sBC.InvokeMethod("CompleteActivity");
sElaspedTime = GetFieldValue("CMI Total Elapsed Time");
sTimeTrackerCost = GetFieldValue("CMI Total Time Cost");
sOrgId = GetFieldValue("CMI Non Billable GL Organization Id");
sDivId = GetFieldValue("CMI Non Billable GL Division Id");
sLocalCurcyCd = GetFieldValue("Currency Code");
}
with(sGLBC) {
TheApplication().Utility.logVars("Time Tracker Cost", sTimeTrackerCost);
if(sTimeTrackerCost != null && sTimeTrackerCost != "" && sTimeTrackerCost != 0) {
NewRecord(NewAfter);
SetFieldValue("Amount", sTimeTrackerCost);
SetFieldValue("Transaction Type", "Non Billable Labor");
SetFieldValue("Activity Id", sActivityId);
SetFieldValue("Organization Id", sOrgId);
SetFieldValue("Division Id", sDivId);
SetFieldValue("Currency Code", sLocalCurcyCd);
WriteRecord();
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sBC = null;
sGLBC = null;
sGLBO = null;
sActBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Create GL Record
CreateWarrantyCreditGL
/*************************************************************************************************************************
Created By : Jacky Huang (JJ631)
Created On : 2011-3-22
C&I Number : 4658
Functionality: Will be triggered through RTE on Write Record on CS HH Deposits BC when Status = Accepted.
It creates GL record for Warranty Credit scenario
************************************************************************************************************************/
function CreateWarrantyCreditGL() {
try {
TheApplication().Utility.logStack("CreateWarrantyCreditGL", this);
var sBO = TheApplication().GetBusObject("HH CG Deposit Payments");
var sBC = sBO.GetBusComp("CS HH Deposits");
var sPayBC = sBO.GetBusComp("CS HH FS Payments");
var sGLBO = TheApplication().GetBusObject("CMI GL Entry");
var sGLBC = sGLBO.GetBusComp("CMI GL Entry");
var sBatchId = TheApplication().GetProfileAttr("CMIBatchId");
var isBatchRec;
var isPayRec;
var sVendorCurcyCd;//added by Jacky
with(sBC) {
SetViewMode(AllView);
ActivateField("Bank Name");
ActivateField("CMI Calculated Amount Other")
ActivateField("Payment Date");
ActivateField("Primary Organization Id");
ActivateField("CMI Currency Code");//added by Jacky
ClearToQuery();
SetSearchSpec("Id", sBatchId);
ExecuteQuery();
isBatchRec = FirstRecord();
TheApplication().Utility.logVars("isBatchRecFound?", isBatchRec);
if(isBatchRec) {
var sTotalPaymentAmount = GetFieldValue("CMI Calculated Amount Other");
var sBatchNo = GetFieldValue("Bank Name");
var sBatchDate = GetFieldValue("Payment Date");
var sOrgId = GetFieldValue("Primary Organization Id");
sVendorCurcyCd = GetFieldValue("CMI Currency Code");//added by Jacky
with(sPayBC) {
SetViewMode(AllView);
ActivateField("CMI Warranty Id");
ActivateField("Deposit Id");
ClearToQuery();
SetSearchSpec("Deposit Id", sBatchId);
ExecuteQuery();
isPayRec = FirstRecord();
TheApplication().Utility.logVars("isPayRec?", isPayRec);
if(isPayRec) {
var sWarId = GetFieldValue("CMI Warranty Id");
TheApplication().Utility.logVars("Warranty Id", sWarId);
}
}//end of sPayBC
}//end of isBatchRec
}//end of with(sBC)
TheApplication().Utility.logVars("Total Payment Amount", sTotalPaymentAmount);
if(sTotalPaymentAmount != "" && sTotalPaymentAmount != null && sTotalPaymentAmount != 0) {
with(sGLBC) {
NewRecord(NewAfter);
SetFieldValue("Amount", sTotalPaymentAmount);
SetFieldValue("Transaction Type", "Warranty Credit");
SetFieldValue("Payment Header Id", sBatchId);//changed from sBatchNo to sBatchId for Integration scenario by iy795 on 28th Apr,2011
//SetFieldValue("Payment Date", sBatchDate);// commented as this field is now coming from join
SetFieldValue("Organization Id", sOrgId);
SetFieldValue("Warranty Id", sWarId);
SetFieldValue("Currency Code", sVendorCurcyCd);
SetFieldValue("Status", "Submit")
WriteRecord();
TheApplication().Utility.logVars("WarrantyCreditGLId", GetFieldValue("Id"));
}//end of with(sGLBC)
}// end of if(sTotalPaymentAmount != "" && sTotalPaymentAmount != null && sTotalPaymentAmount != 0)
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
sGLBC = null;
sBC = null;
sPayBC = null;
sGLBO = null;
sBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Create GL Record
ScanOrder
/*************************************************************************************************************************
Created By : Woody Wu (JR426)
Created On : 2011-3-22
C&I Number : 4658
Functionality: This is triggered from WriteRecordScript of PDS Simplified Order Entry – Orders BC.
It creates GL record for Distributor Warranty scenario.
************************************************************************************************************************/
function ScanOrder(SRId, OrderId, WarrantyId, sOrgId) {
try {
var sSRId = SRId;
var sOrderId = OrderId;
var sWarrId = WarrantyId;
var sBO = TheApplication().GetBusObject("Order Entry (Sales)");
var sOrderBC = sBO.GetBusComp("Order Entry - Orders");
var sBC = sBO.GetBusComp("CMI Order Line Item Warranty (Simple)");
var isPartRec;
var isLaborRec;
var isMiscRec;
var isOrderRec;
var sPartAmount = 0;
var sLaborAmt = 0;
var sMiscAmt = 0;
var sExtPrc;
var sType;
var sWType; //JSH_05012012: Warranty Type
var OrganizationId = sOrgId;
var sFSWarrId;//this is the service warranty id
var sLocalCurcyCd;
//call for Part items associated to the warranty for an order
with(sOrderBC) {
SetViewMode(AllView);
ActivateField("Id");
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery();
isOrderRec = FirstRecord();
if(isOrderRec){
with(sBC) {
SetViewMode(AllView);
ActivateField("CMI Local Currency Code");
ActivateField("CMI Currency Field");
ActivateField("CMI Extended Price Local");
ActivateField("CMI Order Id");
ActivateField("CMI Product Type");
ActivateField("CMI SR Warranty Id");
ActivateField("CMI FS Warranty Id");
ActivateField("CMI Wrnty WOff"); // JSH_05012012: Added field for Internal Warranty (i.e Distr. Warranties)
ActivateField("CMI Warranty Business Entity"); // JSH_05012012: Added field for Internal Warranty (i.e Distr. Warranties)
ClearToQuery();
SetSearchSpec("CMI Order Id", sOrderId);
SetSearchSpec("CMI SR Warranty Id", sWarrId);
SetSearchSpec("CMI Product Type", TheApplication().InvokeMethod("LookUpValue", "PRODUCT_TYPE", "Part"));
ExecuteQuery();
isPartRec = FirstRecord();
while(isPartRec) {
//sLocalCurcyCd = GetFieldValue("CMI Local Currency Code");
sLocalCurcyCd = GetFieldValue("CMI Currency Field");
sExtPrc = GetFieldValue("CMI Extended Price Local");
sFSWarrId = GetFieldValue("CMI FS Warranty Id");
// JSH_05012012: Updated to include Internal Warranty (i.e. Distrib. Warranty)
sWType = GetFieldValue("CMI Warranty Business Entity");
if(sWType != "Internal") {
sPartAmount = ToNumber(sPartAmount) + ToNumber(sExtPrc);
} else {
sPartAmount = ToNumber(sPartAmount) + ToNumber(GetFieldValue("CMI Wrnty WOff"));
}
isPartRec = NextRecord();
}//end of while(isPartRec)
if(sPartAmount != "" && sPartAmount!= null && sPartAmount != 0) {
sType = "Part";
CreateDistGL(sPartAmount, sOrderId, sType, sFSWarrId, OrganizationId,sLocalCurcyCd);
}
}// end of with(sBC)
//call for Labor items associated to the warranty for an order
with(sBC) {
SetViewMode(AllView);
ActivateField("CMI Local Currency Code");
ActivateField("CMI Currency Field");
ActivateField("CMI Extended Price Local");
ActivateField("CMI Order Id");
ActivateField("CMI Product Type");
ActivateField("CMI SR Warranty Id");
ActivateField("CMI FS Warranty Id");
ActivateField("CMI Wrnty WOff"); // JSH_05012012: Added field for Internal Warranty (i.e Distr. Warranties)
ActivateField("CMI Warranty Business Entity"); // JSH_05012012: Added field for Internal Warranty (i.e Distr. Warranties)
ClearToQuery();
SetSearchSpec("CMI Order Id", sOrderId);
SetSearchSpec("CMI SR Warranty Id", sWarrId);
SetSearchSpec("CMI Product Type", TheApplication().InvokeMethod("LookUpValue", "PRODUCT_TYPE", "Labor"));
ExecuteQuery();
isLaborRec = FirstRecord();
while(isLaborRec) {
//sLocalCurcyCd = GetFieldValue("CMI Local Currency Code");
sLocalCurcyCd = GetFieldValue("CMI Currency Field"); // KK: 6/12/12: CQ# 5952, Dist. Write Off currency need to be transactional currency
sExtPrc = GetFieldValue("CMI Extended Price Local");
sFSWarrId = GetFieldValue("CMI FS Warranty Id");
// JSH_05012012: Updated to include Internal Warranty (i.e. Distrib. Warranty)
sWType = GetFieldValue("CMI Warranty Business Entity");
if(sWType != "Internal")
{
sLaborAmt = ToNumber(sLaborAmt) + ToNumber(sExtPrc);
}
else
{
sLaborAmt = ToNumber(sLaborAmt) + ToNumber(GetFieldValue("CMI Wrnty WOff"));
}
isLaborRec = NextRecord();
}//end of while(isPartRec)
if(sLaborAmt != "" && sLaborAmt!= null && sLaborAmt != 0)
{
sType = "Labor";
CreateDistGL(sLaborAmt, sOrderId, sType, sFSWarrId, OrganizationId,sLocalCurcyCd);
}
}// end of with(sBC)
//call for Misc items associated to the warranty for an order
with(sBC)
{
SetViewMode(AllView);
ActivateField("CMI Local Currency Code");
ActivateField("CMI Currency Field");
ActivateField("CMI Extended Price Local");
ActivateField("CMI Order Id");
ActivateField("CMI Product Type");
ActivateField("CMI SR Warranty Id");
ActivateField("CMI FS Warranty Id");
ActivateField("CMI Wrnty WOff"); // JSH_05012012: Added field for Internal Warranty (i.e Distr. Warranties)
ActivateField("CMI Warranty Business Entity"); // JSH_05012012: Added field for Internal Warranty (i.e Distr. Warranties)
ClearToQuery();
SetSearchSpec("CMI Order Id", sOrderId);
SetSearchSpec("CMI SR Warranty Id", sWarrId);
SetSearchSpec("CMI Product Type", TheApplication().InvokeMethod("LookUpValue", "PRODUCT_TYPE", "Misc"));
ExecuteQuery();
isMiscRec = FirstRecord();
while(isMiscRec)
{
sLocalCurcyCd = GetFieldValue("CMI Currency Field");
//sLocalCurcyCd = GetFieldValue("CMI Local Currency Code");
sExtPrc = GetFieldValue("CMI Extended Price Local");
sFSWarrId = GetFieldValue("CMI FS Warranty Id");
// JSH_05012012: Updated to include Internal Warranty (i.e. Distrib. Warranty)
sWType = GetFieldValue("CMI Warranty Business Entity");
if(sWType != "Internal")
{
sMiscAmt = ToNumber(sMiscAmt) + ToNumber(sExtPrc);
}
else
{
sMiscAmt = ToNumber(sMiscAmt) + ToNumber(GetFieldValue("CMI Wrnty WOff"));
}
isMiscRec = NextRecord();
}//end of while(isPartRec)
if(sMiscAmt != "" && sMiscAmt!= null && sMiscAmt != 0)
{
sType = "Misc";
CreateDistGL(sMiscAmt, sOrderId, sType, sFSWarrId, OrganizationId,sLocalCurcyCd);
}
}// end of with(sBC)
}//end of if(isOrderRec)
}//end of with(OrderBC)
}
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally
{
//Added by shanmukh for code clean up 08/26/2011
sOrderBC = null;
sBC = null;
sBO = null;
}
}

CMI Create GL Record
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//try catch added by shanmukh for code clean up 08/22/2011
try
{
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
switch (MethodName) {
case "CreateBillableGL":
var sOrderId = Inputs.GetProperty("CMIOrderId");
CreateBillableGL(sOrderId);
break;
case "CreateNonBillableGL":
CreateNonBillableGL();
break;
case "CreateClaimClosureGL":
CreateClaimClosureGL();
break;
case "CreateWarrantyCreditGL":
CreateWarrantyCreditGL();
break;
case "CMIScanOrderForWarranty":
var SRId = Inputs.GetProperty("SRId");
var OrderId = Inputs.GetProperty("OrderId");
var WarrantyId = Inputs.GetProperty("WarrantyId");
var sOrgId = Inputs.GetProperty("OrganizationId");
ScanOrder(SRId, OrderId, WarrantyId, sOrgId);
break;
case "CMIClaimCompletion":
CreateClaimCompletionGL();
break;
case "CMIClaimCompletionCOG":
ClaimCompletionCOGGL();
break;
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Create Parent SR BS
(declarations)
var sParentSRId = null;

CMI Create Parent SR BS
SRCreateParentSR
function SRCreateParentSR(Inp, Out)
{
/*********************************************************
AUTHOR: build by jj953, migrated from POC by Anand Shanmugam, Oracle Corporation
DESCRIPTION:
INPUTS: sId,sSRAccountId
OUTPUTS:
DATE CREATED:
UPDATES:
*********************************************************/
try
{//try
var oBOPSR = TheApplication().GetBusObject("Service Request");
var oBCPSR = oBOPSR.GetBusComp("Service Request");
var sId = Inp.GetProperty("sId");
var sSRAccountId = Inp.GetProperty("sSRAccountId");
var sSRAContactId = Inp.GetProperty("sSRAContactId");
var sSRType = Inp.GetProperty("sSRType");
var sProductLineName = Inp.GetProperty("sProductLineName");
var sSubType = Inp.GetProperty("sSubType");
var sSRPriority = Inp.GetProperty("sSRPriority");
with (oBCPSR)
{
NewRecord(NewAfter);
SetFieldValue("Account Id",sSRAccountId);
SetFieldValue("Asset Id","");
SetFieldValue("Product Id","");
SetFieldValue("Contact Id",sSRAContactId);
SetFieldValue("SR Type",sSRType);
SetFieldValue("CMI Product Line Name",sProductLineName);
SetFieldValue("Sub Type",sSubType);
SetFieldValue("Priority",sSRPriority);
ActivateField("CMI Parent SR"); //JQ487: Activated field for fixing defect 475, 468 on Dev on 10/11/11
SetFieldValue("CMI Parent SR", "Y"); //JQ487: Setting field for fixing defect 475, 468 on Dev on 10/11/11
WriteRecord();
sParentSRId = GetFieldValue("Id");
}
var oBCRSR = oBOPSR.GetBusComp("CMI Related Service Request");
with (oBCRSR)
{
NewRecord(NewAfter);
SetFieldValue("Child SR Id",sId );
WriteRecord();
}
with(oBCPSR)
{
SetViewMode(AllView);
ClearToQuery();
var searchst = "[Id] = '" + sParentSRId + "'";
SetSearchExpr(searchst);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
var sSRInvCon = TheApplication().InvokeMethod("LookupValue", "CMI_SR_INVOICE_CONSOLIDATION", "Consolidated");
//var sSRInvCon = TheApplication().InvokeMethod("LookupValue", "CMI_SR_INVOICE_CONSOLIDATION", "NoConsolidation");
ActivateField("CMI SR Invoice Consolidation");
SetFieldValue("CMI SR Invoice Consolidation", sSRInvCon);
WriteRecord();
}
}
}//try
catch(e)
{
TheApplication().SetProfileAttr("CMIBYPASSWRITE", "N");
TheApplication().RaiseErrorText(e.toString());
throw(e);
}
finally
{
oBCPSR = null;
oBCRSR = null;
oBOPSR = null;
}
}

CMI Create Parent SR BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: build by jj953, migrated from POC by Anand Shanmugam - Oracle Corporation
DESCRIPTION: The Business Service Creates a Parent SR and associate the current SR with the Parent SR.
It also adds an entry in the Related Srs BC
INPUTS: There is no mandatory inputs since the service is run in Run Time Events
OUTPUTS: None
DATE CREATED: 2/9/2010
UPDATES:
*********************************************************/
if (MethodName == "SRCreateParentSR")
{
//Add Try catch block by Jw920 on 20/10/2011 <Code Clean up>
try
{
var oBO = TheApplication().ActiveBusObject();
var oBC = oBO.GetBusComp("Service Request");
var sId = oBC.GetFieldValue ("Id");
var sSRAccountId = oBC.GetFieldValue("Account Id");
var sSRAContactId = oBC.GetFieldValue("Contact Id");
var sSRType = oBC.GetFieldValue("SR Type");
var sProductLineName = oBC.GetFieldValue("CMI Product Line Name");
var sSubType = oBC.GetFieldValue("Sub Type");
var sSRPriority = oBC.GetFieldValue("Priority");
var Inp = TheApplication().NewPropertySet();
var Out = TheApplication().NewPropertySet();
Inp.SetProperty("sId", sId);
Inp.SetProperty("sSRAccountId", sSRAccountId);
Inp.SetProperty("sSRAContactId", sSRAContactId);
Inp.SetProperty("sSRType", sSRType);
Inp.SetProperty("sProductLineName", sProductLineName);
Inp.SetProperty("sSubType", sSubType);
Inp.SetProperty("sSRPriority", sSRPriority);
SRCreateParentSR(Inp, Out);
var oBCPickSR = oBC.GetPicklistBusComp("CMI Parent SR Number");
with (oBCPickSR)
{
SetViewMode(AllView);
ClearToQuery();
var searchst = "[Id] = '" + sParentSRId + "'";
SetSearchExpr(searchst);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
Pick();
}
}
oBC.WriteRecord();
}
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally
{
sParentSRId=null;
oBCPickSR = null;
oBC = null;
oBO = null;
//Added by shanmukh for code clean up 08/26/2011
Inp = null;
Out = null;
}
return (CancelOperation);
}
//Created by JN705 on Mar 25 to fix defect #664. This is to close Parent SR
//When all the related SRs have been closed.
if (MethodName == "SRCloseParentSR")
{
try
{
var aBO = TheApplication().ActiveBusObject();
var pBO = TheApplication().GetBusObject("Service Request");
var pBC = pBO.GetBusComp("Service Request");
var pRelatedBC = pBO.GetBusComp("Related Service Request")
var sClosed=TheApplication().InvokeMethod("LookupValue", "SR_STATUS", "Closed");
var sClosedFlg = "N";
var sParentSRFlg = "Y";
if(aBO != null)
{
//get related SR Id
var aBC = aBO.GetBusComp("Service Request");
sParentSRId = aBC.GetFieldValue("Parent Service Request Id");
if(sParentSRId==null)
return;
with(pBC)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("CMI Calc Parent SR Flg");
SetSearchExpr("[Id] = '"+sParentSRId +"'");
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sParentSRFlg = GetFieldValue("CMI Calc Parent SR Flg");
// with(pRelatedBC) // Commented by JW227 for TAM review comment#1 on 02/07/2012
// {
pRelatedBC.SetViewMode(AllView);
pRelatedBC.ClearToQuery();
pRelatedBC.SetSearchExpr("[Status]<>'"+sClosed+"'");
pRelatedBC.ExecuteQuery(ForwardOnly);
if(!pRelatedBC.FirstRecord())
sClosedFlg="Y";
// }
}
//update parent SR status
if(sClosedFlg == "Y" && sParentSRFlg == "N")
{
SetFieldValue("Status",sClosed);
WriteRecord();
}
}
}
}
catch(e)
{
throw(e);
}
finally
{
sClosedFlg=null;
sClosed=null;
pRelatedBC=null;
pBC=null;
pBO=null;
//Added by shanmukh for code clean up 08/26/2011
aBC = null;
aBO = null;
}
return (CancelOperation);
}
}

CMI Create Quote Labor Template
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if (MethodName == "CopyQuoteTemplate") {
var SRId = TheApplication().GetProfileAttr("SR Id");
var sQuoteId = TheApplication().GetProfileAttr("Quote Id");
try {
var oBOQt:BusObject;
var oBCQt:BusComp;
var boActive:BusObject = TheApplication().ActiveBusObject();
var bcActive:BusComp = boActive.GetBusComp("Quote");
var firstSelected = bcActive.FirstSelected();
//If record in quote is active, get fields from active instantiation, otherwise requery
TheApplication().Utility.logVars("Quote record?", firstSelected);
if (firstSelected) {
sShipAccId = bcActive.GetFieldValue("Ship To Account Id");
sShipSiteId = bcActive.GetFieldValue("CMI Ship To Profile Id");
sSiteAddrId = bcActive.GetFieldValue("CMI Ship To Address Id");
TheApplication().Utility.logVars("Ship To Site Id", sShipSiteId);
}
} catch(e) {
TheApplication().Utility.logError(e);
oBOQt = TheApplication().GetBusObject("Quote");
oBCQt = oBOQt.GetBusComp("Quote");
with (oBCQt) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardOnly);
var isRec = FirstRecord();
TheApplication().Utility.logVars("Quote ("+sQuoteId+") Found?", isRec);
if (isRec) {
sShipAccId = GetFieldValue("Ship To Account Id");
sShipSiteId = GetFieldValue("CMI Ship To Profile Id");
sSiteAddrId = GetFieldValue("CMI Ship To Address Id");
TheApplication().Utility.logVars("Ship To Site Id", sShipSiteId);
}//end if
}//end with
} finally {
bcActive = null;
boActive = null;
oBCQt = null;
oBOQt = null;
}
QuoteTemplate(SRId,sQuoteId,sShipAccId,sShipSiteId,sSiteAddrId);
} //if
//The BS method is created to refresh a applet with the users search spec on it for Bug # DBUNG00000751
if (MethodName == "RefreshBusComp") {
var BCName = Inputs.GetProperty("Context");
RefreshBusComp(BCName);
}
//End of //The BS method is created to refresh a applet with the users search spec on it for Bug # DBUNG00000751
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Create Quote Labor Template
QuoteTemplate
/*********************************************************
AUTHOR:
DESCRIPTION:
OUTPUTS: None
DATE CREATED: 10/14/2011
UPDATES:
Updated the code logic to optimize the code and added a extra comparision logic for Internal Bug # 71 - duplicate template lines created by ki795 on 14-Oct-2011
Adding logic for SRT redesign as per BUG # DBUNG00000289 by ki795 on 14-Oct-2011
//Removed all the CountRecords() and added ForwardOnly to ExecuteQuery to improve performance
*********************************************************/
function QuoteTemplate(SRId,sQuoteId,sShipAccId,sShipSiteId,sSiteAddrId) {
try {
TheApplication().Utility.logStack("QuoteTemplate", this);
var sPriceList = TheApplication().GetProfileAttr("Price List");
var sCurrencyCode = TheApplication().GetProfileAttr("Currency Code");
var oBO = TheApplication().GetBusObject("Quote");//change by james from ActiveBusObject to GetBusObject at 22dec-2010
var oBCSR = oBO.GetBusComp("Service Request");
var oBOQuote = TheApplication().GetBusObject("Quote");
var oBOQ = TheApplication().GetBusObject("CMI Quote");
var oBCQuote = oBOQ.GetBusComp("CMI Quote Simple");
var oBCQuoteItem = oBOQ.GetBusComp("CMI Quote Item Lite");
var oBCQuoteTemplate = oBOQuote.GetBusComp("CMI Quote Template");
var sPrevTempQuoteItemId;
var sCurTempQuoteItemId;
var iMaxLineNumber = 1;
var sSRType;
var QTID;
var sLineCopied:String = "No"; // CMI DBUNG00000289 to execute SRT validaiton if Template get copied by ki795 on 13-Oct-2011
with (oBCSR) {
SetViewMode(AllView);
ActivateField("Job Type");
ActivateField("CMI SR Access Code"); // CMI DBUNG00000289 to pass Access Code as an input to SRT validaiton by ki795 on 13-Oct-201
ClearToQuery();
SetSearchSpec("Id",SRId);
ExecuteQuery(ForwardOnly);
var isRecord2 = FirstRecord();
TheApplication().Utility.logVars("SR ("+SRId+") Found?", isRecord2);
if (isRecord2) {
var sSRsubtype:String = GetFieldValue("Sub Type");
var sSRProdLine:String = GetFieldValue("CMI Product Line Name"); // CMI DBUNG00000289 to pass Product Line as an input to SRT validaiton by ki795 on 13-Oct-2011
var sSRAccessCode:String = GetFieldValue("CMI SR Access Code"); // CMI DBUNG00000289 to pass Access Code as an input to SRT validaiton by ki795 on 13-Oct-201
sSRType = oBCSR.GetFieldValue("Job Type");
}//end if
}//end with(oBCSR)
TheApplication().Utility.logVars("SR Sub Type", sSRsubtype);
if (sSRsubtype != "Respec") {
TheApplication().Utility.logVars("SR Type", sSRType);
if (sSRType == TheApplication().InvokeMethod("LookupValue", "JOB_TYPE", "In-Shop")) {
with(oBCQuoteTemplate) {
SetViewMode(AllView);
ActivateField("Name");
ClearToQuery();
SetSearchSpec("Name", "InShop");
ExecuteQuery(ForwardOnly);
var isRecord3 = FirstRecord();
if (isRecord3) {
QTID = oBCQuoteTemplate.GetFieldValue("Id");
}//end if isrecord3
}//end with(oBCQuoteTemplate)
} else if (sSRType == TheApplication().InvokeMethod("LookupValue", "JOB_TYPE", "Mobile")) {
with(oBCQuoteTemplate) {
SetViewMode(AllView);
ActivateField("Name");
ClearToQuery();
SetSearchSpec("Name", "Mobile");
ExecuteQuery(ForwardOnly);
isRecord3 = FirstRecord();
if (isRecord3) {
QTID = oBCQuoteTemplate.GetFieldValue("Id");
}
}
} else {
return (CancelOperation);
}
TheApplication().Utility.logVars("Quote Template Id", QTID);
if(QTID != "" && QTID != null) {
with (oBCQuote) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",QTID);
ExecuteQuery(ForwardOnly);
var isRecord = FirstRecord();
if (isRecord) {
//Initialize Parent
oBCQuoteItem.SetViewMode(AllView);
oBCQuoteItem.ActivateField("Line Number");
oBCQuoteItem.ActivateField("CMI Today");
oBCQuoteItem.ClearToQuery();
oBCQuoteItem.SetSearchSpec("Quote Id",QTID);
//MJB Commented out sort and changed execute query mode to ForwardBackward which should filter out all duplicates
// oBCQuoteItem.SetSortSpec("Id(ASCENDING)");//Added sorting parameter as next record retrives the same record twice by ki795 on 14-Oct-2011
oBCQuoteItem.ExecuteQuery(ForwardBackward);
var isRecord1 = oBCQuoteItem.FirstRecord();
while (isRecord1) {
// sCurTempQuoteItemId = oBCQuoteItem.GetFieldValue("Id"); //Added comaprison parameter as next record retrives the same record twice by ki795 on 14-Oct-2011
//Added comaprison parameter as next record retrives the same record twice by ki795 on 14-Oct-2011
// if (sCurTempQuoteItemId != sPrevTempQuoteItemId) {
// sPrevTempQuoteItemId = oBCQuoteItem.GetFieldValue("Id");
// Moved the below one line code inside the if loop for Bug # DBUNG00001441 by ki795 on 29-Aug-2011
var currentTime = oBCQuoteItem.GetFieldValue("CMI Today");//Add by peter for set Due Date Today
var sUOM = oBCQuoteItem.GetFieldValue("Unit of Measure");
oBCQuoteItem.NewRecord(NewAfterCopy);
oBCQuoteItem.SetFieldValue("Quote Id",sQuoteId);
oBCQuoteItem.SetFieldValue("Line Number", iMaxLineNumber);
oBCQuoteItem.SetFieldValue("Item Price List Id", sPriceList);
oBCQuoteItem.SetFieldValue("CMI Unit of Measure", sUOM);
oBCQuoteItem.SetFieldValue("Currency Code", sCurrencyCode);
//Added by Riju to default Account/Site Id and Address Id on Quote Item
//created automatically when applying Quote template By Riju On 03/24/2011
oBCQuoteItem.SetFieldValue("Ship To Account Id", sShipAccId);
oBCQuoteItem.SetFieldValue("Ship To Address Id", sSiteAddrId);//MJB 7/5/12 changed from sShipAddrId
oBCQuoteItem.SetFieldValue("CMI Ship To Profile Id", sShipSiteId);
oBCQuoteItem.SetFieldValue("CMI Ship To Address Id",sSiteAddrId);
oBCQuoteItem.SetFieldValue("Requested Delivery Date", currentTime);//Add by peter for set Due Date Today
iMaxLineNumber = ToNumber(iMaxLineNumber) + 1;
oBCQuoteItem.WriteRecord();
sLineCopied = "Yes";
// }
isRecord1 = oBCQuoteItem.NextRecord();
}//end While
}// end if
}//end with (oBCQuote)
}
// CMI DBUNG00000289 Start of code to execute SRT validaiton if Template get copied by ki795 on 13-Oct-2011
TheApplication().Utility.logVars("Line Copied", sLineCopied);
if (sLineCopied == "Yes") {
var sSRTValidaitonService = TheApplication().GetService("CMI SRT Validation Service");
var psInput = TheApplication().NewPropertySet();
var psOutput = TheApplication().NewPropertySet();
psInput.SetProperty("Quote Id", sQuoteId);
psInput.SetProperty("SR Product Line", sSRProdLine);
psInput.SetProperty("SR Access Code", sSRAccessCode);
sSRTValidaitonService.InvokeMethod("SRT Validation",psInput,psOutput);
sSRTValidaitonService = null;
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCSR = null;
oBOQuote = null;
oBOQ = null;
oBCQuote = null;
oBCQuoteItem = null;
oBCQuoteTemplate = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Create Quote Labor Template
RefreshBusComp
/*********************************************************
AUTHOR: Arun N Chellathurai
DESCRIPTION: The BS is created to refresh a applet to bring back the context of the record which the user has created
OUTPUTS: None
DATE CREATED: 8/11/2011
Bug # DBUNG00000751
UPDATES:
*********************************************************/
function RefreshBusComp(BusCompName)
{
try
{
var oBO = TheApplication().ActiveBusObject();
var oBusComp = oBO.GetBusComp(BusCompName);
with (oBusComp)
{
SetViewMode(PersonalView);
ClearToQuery();
SetSortSpec("Updated(DESCENDING), Revision(DESCENDING)");
ExecuteQuery(ForwardBackward);
}
}
catch(e)
{
throw(e);
}
}

CMI Create Quote Labor Template
(declarations)
var sShipAddrId = "";
var sShipAccId = "";
var sShipSiteId = "";
var sSiteAddrId = "";

CMI CreateSRClaimsByOrder
(declarations)
var oBOClaims:BusObject;
var oBCClaims:BusComp;
var oBCClaimsNote:BusComp;
var oBCClaimsFailCd:BusComp;
var oBCClaimsParts:BusComp;
var oBCClaimsSRT:BusComp;
var oBCClaimsOthers:BusComp;
var oBCClaimsMulti:BusComp;
var oBCClaimsSimple:BusComp;
var oBOSR:BusObject = TheApplication().GetBusObject("Service Request");
var oBCSR:BusComp = oBOSR.GetBusComp("Service Request");
var oBCSRFailCd:BusComp = oBOSR.GetBusComp("CMI SR Failure Code");
var oBCSRWarrty:BusComp = oBOSR.GetBusComp("Service Request");
var oBCSRWarrantyFailRL:BusComp = oBOSR.GetBusComp("CMI Warranty Failure Relation");
var oBCSRNote:BusComp = oBOSR.GetBusComp("FIN Service Request Notes");
var sMisc = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Misc");
var sLabor = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
var sFailCdPrimaryId = "N";
var sFailCdPrmrySetId = "N";

CMI CreateSRClaimsByOrder
CallSRClaimPricingWF
/*Added this function to call the WF for 2nd iLog call by KM331 on 12/09/2011*/
function CallSRClaimPricingWF(sClaimId)
{
try {
TheApplication().Utility.logStack("CallSRClaimPricingWF", this);
var oBS = TheApplication().GetService("Workflow Process Manager");
var sInProp = TheApplication().NewPropertySet();
var sOutProp = TheApplication().NewPropertySet();
sInProp.SetProperty("ProcessName", "CMI SR Claims iLog Price");
sInProp.SetProperty("Object Id", sClaimId);
sInProp.SetProperty("Call Type", "Markup");
oBS.InvokeMethod("RunProcess", sInProp, sOutProp);
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sInProp = null;
sOutProp = null;
oBS = null;
TheApplication().Utility.logUnstack();
}
}

CMI CreateSRClaimsByOrder
ChangeClaimStatus
/*Added function to change the status of claim at the end when claim record is created along
with all child item records by KM331 on 12/10/2011*/
function ChangeClaimStatus(sClaimId) {
try {
TheApplication().Utility.logStack("ChangeClaimStatus", this);
/*START--Added code to update Status of claim from thin BC as per C&I# 4648, S197 by KM331 on 11/18/2011*/
with(oBCClaimsSimple) {
SetViewMode(AllView);
ActivateField("CMI Status Code");
ClearToQuery();
SetSearchSpec("Id", sClaimId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
SetFieldValue("CMI Status Code", TheApplication().InvokeMethod("LookupValue", "INS_CLAIM_STATUS", "Ready To Verify"));
WriteRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
}

CMI CreateSRClaimsByOrder
CreateClaimHeaderNoteFailCd
function CreateClaimHeaderNoteFailCd(sSRId, sOrderId, sOrderPriOrgId, sSRWarrtyId, sSRPriDivisionId, sFSWarId,sPriceListId)
{
try {
TheApplication().Utility.logStack("CreateClaimHeaderNoteFailCd", this);
var sSRAstNum:String = "";
var sClaimId:String = "";
var sAddr:String = "";
var sWarrBusUnit = "";
var nIMSClaimNum = "";
var sAssetId = "";
var sPickMsrmtRead = "";
//Added by KM326 for CMI DBU Bug 4824 S250 on 04-02-2012
var oWarrantyBO = TheApplication().GetBusObject("FS Warranty");
var oWarrantyBC = oWarrantyBO.GetBusComp("FS Warranty");
var sSerNum, sWarDt, sMeasType, sReading, sProdName, sUnitModel, sProdId, sUnitMfgId, sUnitConfig, sUnitMfg, sPreDelivery, sWWSPSRate;
var sFailLoc, sSRClaim, sMeasId, sMeasUnits, sWarMeasType, sWarReading, sWarProdName,sWarStartDt, sWarSerNum, sReadingId;
with(oWarrantyBC) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Claim Bus Entity");
SetSearchSpec("Id", sFSWarId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Warranty ("+sFSWarId+") Found?", FirstRecord());
if (FirstRecord()) {
sWarrBusUnit = GetFieldValue("CMI Claim Bus Entity");
}//end if
}//end with
TheApplication().Utility.logVars("Warranty Bus Unit", sWarrBusUnit);
if(sWarrBusUnit != TheApplication().InvokeMethod("LookupValue", "CMI_CLAIM_BUS_ENTITY", "Other")) {
//Call WF to get Claim Seq Num Added by KM326 to fix bug 4056 on 23-01-2012
var oBS = TheApplication().GetService("Workflow Process Manager");
var pInputProp = TheApplication().NewPropertySet();
var pOutputProp = TheApplication().NewPropertySet();
pInputProp.SetProperty("ProcessName", "CMI Generate Claim Sequence");
pInputProp.SetProperty("Order Id", sOrderId);
pInputProp.SetProperty("Warranty Id", sSRWarrtyId);
pInputProp.SetProperty("Division Id", sSRPriDivisionId);
oBS.InvokeMethod("RunProcess", pInputProp, pOutputProp);
nIMSClaimNum = pOutputProp.GetProperty("ClaimSeqNum");
}
with(oBCSR) {
SetViewMode(AllView);
ActivateField("Asset Number");
ActivateField("CMI Last Asset Measurement Id");
ActivateField("CMI Last Asset Measurement Type Code");
ActivateField("CMI Last Asset Measurement Units Code");
ActivateField("CMI Last Asset Reading");
ActivateField("CMI Primary Asset Reading Id");
ActivateField("Asset Id");
ActivateField("Serial Number");
ActivateField("CMI Warranty Start Date");
ActivateField("Product");
ClearToQuery();
SetSearchSpec("Id", sSRId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("SR ("+sSRId+") Found?", FirstRecord());
if(FirstRecord()) {
sSRAstNum = GetFieldValue("Asset Number");
sAssetId = GetFieldValue("Asset Id");
sSerNum = GetFieldValue("Serial Number");
sWarDt = GetFieldValue("CMI Warranty Start Date");
sProdName = GetFieldValue("Product");
//MJB 1/17/13 CQ9812 Get SR Primary measurement fields. These are from the first measurement taken for this SR
sMeasType = GetFieldValue("CMI Last Asset Measurement Type Code");
sMeasId = GetFieldValue("CMI Last Asset Measurement Id");
sMeasUnits = GetFieldValue("CMI Last Asset Measurement Units Code");
sReading = GetFieldValue("CMI Last Asset Reading");
sReadingId = GetFieldValue("CMI Primary Asset Reading Id");
}
}//end with(oBCSR)
//Start CMI DBUNG00001416 to populate the sales team with Order Sales Team Primary by KI795 on 8-Sep-2011
var sPriPostId:String = "";
var oOrderBusObj:BusObject = TheApplication().GetBusObject("Order Entry");
var oOrderBusComp:BusComp = oOrderBusObj.GetBusComp("Order Entry - Orders");
with (oOrderBusComp) {
SetViewMode(AllView);
ActivateField("Primary Position Id");
ActivateField("CMI Claim Address Formatted");
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Order ("+sOrderId+") Found?", FirstRecord());
if(FirstRecord()) {
sPriPostId = GetFieldValue("Primary Position Id");
sAddr = GetFieldValue("CMI Claim Address Formatted");
}
}
//End of Code change for DBUNG00001416 to populate the sales team with Order Sales Team Primary by KI795 on 8-Sep-2011
//Added by KM326 for CMI DBU C&I 4607 S250 on 13-01-2012
var sBCSRWar:BusComp = oBOSR.GetBusComp("CMI Service Request Warranty");
with(sBCSRWar) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI WWSPS Conversion Rate");
ActivateField("CMI Parent SR Id");
ActivateField("CMI Serial Number");
ActivateField("CMI Warranty Start Date");
ActivateField("CMI Measurement Type");
ActivateField("CMI Measurement Reading");
ActivateField("CMI Product Name");
ActivateField("CMI Manufacturer");
ActivateField("CMI Root Manufacturer Id");
ActivateField("CMI Unit Model");
ActivateField("CMI Product Id");
ActivateField("CMI Unit Configuration");
ActivateField("CMI Pre Delivery");
ActivateField("CMI Fail Location");
SetSearchSpec("Id",sSRWarrtyId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("SR Warranty ("+sSRWarrtyId+") Found?", FirstRecord());
if(FirstRecord()) {
sSRId = GetFieldValue("CMI Parent SR Id");;
sUnitMfg = GetFieldValue("CMI Manufacturer");
sUnitMfgId = GetFieldValue("CMI Root Manufacturer Id");
sUnitModel = GetFieldValue("CMI Unit Model");
sUnitConfig = GetFieldValue("CMI Unit Configuration");
sProdId = GetFieldValue("CMI Product Id");
sPreDelivery = GetFieldValue("CMI Pre Delivery");
sFailLoc = GetFieldValue("CMI Fail Location");
sWarMeasType = GetFieldValue("CMI Measurement Type");
sWarReading = GetFieldValue("CMI Measurement Reading");
sWarProdName = GetFieldValue("CMI Product Name");
sWarStartDt = GetFieldValue("CMI Warranty Start Date");
sWarSerNum = GetFieldValue("CMI Serial Number");
sWWSPSRate = GetFieldValue("CMI WWSPS Conversion Rate");
//MJB 1/17/13 CQ 9812 If the warranty asset overrides are populated, override values retrieved from the SR
TheApplication().Utility.logStep("Overrides - SN ("+sWarSerNum+")/Start ("+sWarStartDt+")/Product ("+sWarProdName+")/Measurement ("+sWarMeasType+")/Reading ("+sWarReading+")");
if (sWarSerNum != "") sSerNum = sWarSerNum;
if (sWarStartDt != "") sWarDt = sWarStartDt;
if (sWarProdName != "") sProdName = sWarProdName;
if (sWarMeasType != "" || sWarReading != "") {
sReading = sWarReading;
sMeasType = sWarMeasType;
sPickMsrmtRead = "No";
}
}
}//end of with(sBCSRWar)
/* MJB Comment 1/17/13 CQ 9812 take the asset, measurement and reading directly from the SR and SR/Reading relationship
var oBcAsset:BusComp = oBOSR.GetBusComp("Asset Mgmt - Asset");
with(oBcAsset) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("Serial Number");
ActivateField("CMI Warranty Start Date");
ActivateField("Product Name");
ActivateField("Product Id");
SetSearchSpec("Id", sAssetId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
if(sSerNum == "" || sSerNum == null) {
sSerNum = GetFieldValue("Serial Number");
}
if(sWarDt == "" || sWarDt == null) {
sWarDt = GetFieldValue("CMI Warranty Start Date");
}
if(sProdName == "" || sProdName == null) {
sProdName = GetFieldValue("Product Name");
}
if((sMeasType == "" || sMeasType == null) && (sReading == "" || sReading == null)) {
//Query Measurement BC
var oBCMeasurement:BusComp = oBOSR.GetBusComp("FS Asset Measurement Characteristics");
var oBCReading:BusComp = oBOSR.GetBusComp("FS Asset Reading");
with(oBCMeasurement) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("Measurement Type Code");
SetSearchSpec("Asset Id", sAssetId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
sMeasType = GetFieldValue("Measurement Type Code");
sMeasId = GetFieldValue("Id");
with(oBCReading) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("Reading");
SetSortSpec("Created(DESCENDING)");
SetSearchSpec("Asset Id", sAssetId);
SetSearchSpec("Asset Measurement Id", sMeasId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
sReading = GetFieldValue("Reading");
}
}
}
}
} else if ((sMeasType != "" || sMeasType != null) && (sReading != "" || sReading != null)) {
sPickMsrmtRead = "No"
}
}
}
*/
oBOClaims = TheApplication().GetBusObject("CMI Claims");
oBCClaims = oBOClaims.GetBusComp("INS Claims");
oBCClaimsNote = oBOClaims.GetBusComp("INS Claims Note");
oBCClaimsFailCd = oBOClaims.GetBusComp("CMI Claims Failure Codes");
oBCClaimsParts = oBOClaims.GetBusComp("CMI Claims Part Detail");
oBCClaimsSRT = oBOClaims.GetBusComp("CMI Claims SRT Details");
oBCClaimsOthers = oBOClaims.GetBusComp("CMI Claims Other Items");
oBCClaimsMulti = oBOClaims.GetBusComp("INS Claims Insured Property");
oBCClaimsSimple = oBOClaims.GetBusComp("CMI INS Claims Simple");
with(oBCClaims) {
ActivateField("CMI Asset Address");
ActivateField("CMI Asset Number");
ActivateField("CMI Branch Id");
ActivateField("CMI Claim Category");
ActivateField("CMI Engine Model");
ActivateField("CMI Engine Serial Number");
ActivateField("CMI External Claim Number");
ActivateField("CMI Fail Location");
ActivateField("CMI Measurement Type");
ActivateField("CMI Measurement Type Id");
ActivateField("CMI Measurement Units Code");
ActivateField("CMI Order Id");
ActivateField("CMI Pay To");
ActivateField("CMI Pre Delivery");
ActivateField("CMI Price List Id");
ActivateField("CMI Primary Id");
ActivateField("CMI Reading");
ActivateField("CMI Reading Id");
ActivateField("CMI Related Service Request Number");
ActivateField("CMI Root Manufacturer");
ActivateField("CMI Validation Summary");//new-line
ActivateField("CMI Warranty Id");
ActivateField("CMI Warranty Start Date");
ActivateField("Primary Organization Id");
ActivateField("Sales Rep");
ActivateField("CMI WWSPS Conversion Rate");
NewRecord(NewAfter);
//Added by KM326 to fix bug 4824 on 04-02-2012
if(nIMSClaimNum != "" && nIMSClaimNum != null) {
//Added by KM326 to fix bug 4056 (IMS Claims # generation)) on 23-01-2012
SetFieldValue("CMI External Claim Number", ToNumber(nIMSClaimNum));
}
//MJB 1/21/13 CQ9812 Set the Reading/Measurement from Info on the SR. Set Before setting the asset so logic
//on Claims does not execute to set the Reading
if(sMeasType != "" && sMeasType != null) {
if (sPickMsrmtRead != "No") {
SetFieldValue("CMI Measurement Type Id", sMeasId);
SetFieldValue("CMI Measurement Units Code", sMeasUnits);
} else {
SetFieldValue("CMI Measurement Units Code", sMeasType);
}
}
if(sReading != "" && sReading != null && isNaN(parseInt(sReading)) == false) {
if (sPickMsrmtRead != "No") {
SetFieldValue("CMI Reading", sReading);
SetFieldValue("CMI Reading Id", sReadingId);
} else {
SetFieldValue("CMI Reading", sReading);
}
}
sPickMsrmtRead = "";
var oSRPickComp = GetPicklistBusComp("CMI Related Service Request Number");
with(oSRPickComp) {
ClearToQuery();
ActivateField("CMI Primary Failure Id");
SetSearchSpec("Id", sSRId);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) {
sFailCdPrimaryId = GetFieldValue("CMI Primary Failure Id");
Pick();
}
}
SetFieldValue("CMI Claim Category", TheApplication().InvokeMethod("LookupValue", "CMI_CLAIM_CATEGORY", "SR Claim") );
SetFieldValue("CMI Warranty Id", sSRWarrtyId);
SetFieldValue("CMI Order Id", sOrderId);
SetFieldValue("CMI WWSPS Conversion Rate", sWWSPSRate);
var oAssetPickBC = GetPicklistBusComp("CMI Asset Number");
with(oAssetPickBC) {
ClearToQuery();
SetSearchSpec("Asset Number",sSRAstNum);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) Pick();
}
SetFieldValue("CMI Pay To", TheApplication().InvokeMethod("LookupValue", "CMI_CLAIMS_PAYTO", "Distributor"));
SetFieldValue("CMI Branch Id", sSRPriDivisionId);
if (sOrderPriOrgId != null && sOrderPriOrgId != "") {
var oOrgMVGComp:BusComp = GetMVGBusComp("Organization Name");
with(oOrgMVGComp) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderPriOrgId);
ExecuteQuery(ForwardOnly);
if (!FirstRecord()) {
var oOrgAssBusComp:BusComp = oOrgMVGComp.GetAssocBusComp();
with(oOrgAssBusComp) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderPriOrgId);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) {
Associate(NewBefore);
}
}
}
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderPriOrgId);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) {
SetFieldValue("SSA Primary Field", "Y");
WriteRecord();
}
}
}
if (sPriPostId != null && sPriPostId != "") {
var oProductMVG:BusComp = GetMVGBusComp("Sales Rep");
with(oProductMVG) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sPriPostId);
ExecuteQuery(ForwardOnly);
if (!FirstRecord()) {
with(oProductMVG.GetAssocBusComp()) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sPriPostId);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) {
Associate(NewBefore);
}
}
}
}
}
SetFieldValue("Primary Organization Id", sOrderPriOrgId);
SetFieldValue("CMI Validation Summary", TheApplication().InvokeMethod("LookupValue", "X_CMI_VALIDATION_SUMMARY", "Proceed"));//new-line
//setting Override fields
// RR 05/22/2012:: Added for CQ 8021 & 5967
var sSerialNum = GetFieldValue("CMI Engine Serial Number");
if(sSerNum == "" || sSerNum == null) {
if(sSerialNum != "" && sSerialNum != null) {
SetFieldValue("CMI Engine Serial Number", sSerialNum);
}
} else {
SetFieldValue("CMI Engine Serial Number", sSerNum);
}
// RR 05/22/2012:: Added for CQ 8158
if(sWarDt != "" && sWarDt != null) {
SetFieldValue("CMI Warranty Start Date", sWarDt);
}
if(sUnitMfgId != null && sUnitMfgId != "") {
var oRMPickBC = GetPicklistBusComp("CMI Root Manufacturer");
with(oRMPickBC) {
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Id", sUnitMfgId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) Pick();
}
}
SetFieldValue("CMI Engine Model", sProdName);
SetFieldValue("CMI Pre Delivery", sPreDelivery);
SetFieldValue("CMI Fail Location", sFailLoc);
SetFieldValue("CMI Asset Address", sAddr);
SetFieldValue("CMI Price List Id", sPriceListId);
WriteRecord();
sClaimId = GetFieldValue("Id");
}//end with(oBCClaims)
CreateClaimOrder(sOrderId, sClaimId);
CreateNote();
CreateFailCd(sSRId, sSRWarrtyId, sClaimId);
with(oBCClaims) {
if (sFailCdPrmrySetId != "N" && sFailCdPrmrySetId != "Y") {
SetFieldValue("CMI Primary Id", sFailCdPrmrySetId);
WriteRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oOrderBusComp = null;
oOrderBusObj = null;
oSRPickComp=null;
oOrgAssBusComp=null;
oOrgMVGComp = null;
oProductMVG = null;
oRMPickBC = null;
// oReadPickBC = null;
oAssetPickBC=null;
// oMTPickBC = null;
// oBcAsset = null;
sBCSRWar = null;
// oBCReading = null;
// oBCMeasurement = null;
oBS = null;
pInputProp = null;
pOutputProp = null;
oWarrantyBC = null;
oWarrantyBO = null;
TheApplication().Utility.logUnstack(sClaimId);
}
return (sClaimId);
}

CMI CreateSRClaimsByOrder
CreateClaimOrder
/************************************************************************
Name: CreateClaimOrder
Created by: KM326 for 4029 on 26-12-2011
Description: Used to make entry into intersection table so as to
make Order visible on Claims -> Order tab and vice-versa
*************************************************************************/
function CreateClaimOrder(sOrderId, sClaimId)
{
try {
TheApplication().Utility.logStack("CreateClaimOrder", this);
var sClaimBO = TheApplication().GetBusObject("CMI Claims");
var sClaimOrderBC = sClaimBO.GetBusComp("CMI Claim Orders");
with(sClaimOrderBC) {
SetViewMode(AllView);
ActivateField("CMI Claim Id");
ActivateField("CMI Order Id");
NewRecord(NewAfter);
SetFieldValue("CMI Claim Id", sClaimId);
SetFieldValue("CMI Order Id", sOrderId);
WriteRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sClaimOrderBC = null;
sClaimBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI CreateSRClaimsByOrder
CreateFailCd
function CreateFailCd(sSRId, sWarrantyId, sClaimId)
{
try {
TheApplication().Utility.logStack("CreateClaimOrder", this);
//Added by KM326 to fix bug 845/862 on 06-12-2011
var oBOClaimsFailCD = TheApplication().GetBusObject("CMI Claims");
var oBCClaimsFailCdFailCD = oBOClaimsFailCD.GetBusComp("CMI Claims Failure Codes");
with(oBCSRWarrantyFailRL)
{
SetViewMode(AllView);
ActivateField("CMI Type");
ActivateField("CMI SR Failure Code Id");
ClearToQuery();
SetSearchSpec("CMI Parent SR Id", sSRId);
SetSearchSpec("CMI Warranty Id", sWarrantyId);
ExecuteQuery(ForwardOnly)
var HasRecord = FirstRecord();
while(HasRecord)
{
var sFailCodeId = GetFieldValue("CMI SR Failure Code Id");
with(oBCSRFailCd)
{
SetViewMode(AllView);
ActivateField("CMI Failure Id");
ActivateField("CMI Group Id");
ActivateField("CMI LOC");
ActivateField("CMI Major Code Id");
ActivateField("CMI Minor Code Id");
ActivateField("CMI Mode Code Id");
ClearToQuery();
SetSearchSpec("Id", sFailCodeId);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
var sSRFailCodeId = GetFieldValue("CMI Failure Id");
var sSRGroupId = GetFieldValue("CMI Group Id");
var sSRLoc = GetFieldValue("CMI LOC");
var sMajorId = GetFieldValue("CMI Major Code Id");
var sMinorId = GetFieldValue("CMI Minor Code Id");
var sModeId = GetFieldValue("CMI Mode Code Id");
var sVendor = GetFieldValue("CMI Vendor");
var sProdLine = GetFieldValue("CMI Product Line Name");
var sPrmFailCdFlgId = GetFieldValue("Id");
if (sPrmFailCdFlgId == sFailCdPrimaryId && sFailCdPrmrySetId == "N")
sFailCdPrmrySetId = "Y";
//Modified by KM326 to fix bug 845/862 on 06-12-2011
//with(oBCClaimsFailCd)
with(oBCClaimsFailCdFailCD)
{
NewRecord(NewAfter);
//Added by KM326 to fix bug 845/862 on 06-12-2011
SetFieldValue("CMI Claims Id", sClaimId);
SetFieldValue("CMI Vendor", sVendor);
SetFieldValue("CMI Group Id", sSRGroupId);
SetFieldValue("CMI Product Line Name", sProdLine);
SetFieldValue("CMI Mode Id", sModeId);
SetFieldValue("CMI Major Code Id", sMajorId);
SetFieldValue("CMI Minor Code Id", sMinorId);
SetFieldValue("CMI Failure Id",sSRFailCodeId);
SetFieldValue("CMI LOC", sSRLoc);
if (sFailCdPrmrySetId == "Y")
{
sFailCdPrmrySetId = GetFieldValue("Id");
// SetFieldValue("SSA Primary Field", "Y");
}
WriteRecord();
}//end with(oBCFailCode)
}//end if (FirstRecord())
}//end with(oBCClaimsFailCd)
HasRecord = NextRecord();
}//end while(HasRecord)
}//end with(oBCSRWarrantyFailRL)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCClaimsFailCdFailCD = null;
oBOClaimsFailCD = null;
TheApplication().Utility.logUnstack();
}
}

CMI CreateSRClaimsByOrder
CreateNote
function CreateNote()
{
try {
TheApplication().Utility.logStack("CreateNote", this);
with(oBCSRNote) {//Copy SR Notes to Claims Note
SetViewMode(AllView);
ActivateField("Note Type");
ActivateField("Note");
ActivateField("CMI Description");
ActivateField("CMI Notes High");//CMI <Bug/Fix - DBU>, Defect # CQ 1134 <Configuration>: <Added to validate Claims Note Type> By <ki795> On <08-04-2011>
ClearToQuery();
ExecuteQuery(ForwardOnly);
var HasRecord = FirstRecord();
while (HasRecord)
{
var sNoteType = GetFieldValue("Note Type");
var sNote = GetFieldValue("Note");
var sClaimsNote = GetFieldValue("CMI Notes High"); //CMI <Bug/Fix - DBU>, Defect # CQ 1134 <Configuration>: <Added to validate Claims Note Type> By <ki795> On <08-04-2011>
var sNoteDesc = GetFieldValue("CMI Description");
if (sClaimsNote == "Claims Note Type")//CMI <Bug/Fix - DBU>, Defect # CQ 1134 <Configuration>: <Added to validate Claims Note Type> By <ki795> On <08-04-2011>
{
with(oBCClaimsNote)
{
NewRecord(NewAfter); //Changed the value 1 to NewAfter from oracle review <added by> <k0981> on <09-11-2011>
SetFieldValue("Note Type", sNoteType); //CMI<defect#DBUNG00001181> <Configuration>Changed the set value to sNoteType from sNoteDesc<added by ki795 on 27july2011>
SetFieldValue("Note", sNote);
WriteRecord();
}
}
HasRecord = NextRecord();
}//end while (HasRecord)
}//end with(oBCSRNote)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
}

CMI CreateSRClaimsByOrder
CreateOthers
function CreateOthers(sQtyReq, sProdId, sUniPrice, sOrderLineExtMiscPrc, sUOM, sCoveredPercent, sParentItemId, sFlag)
{
try
{
TheApplication().Utility.logStack("CreateOthers", this);
with(oBCClaimsOthers) {
ActivateField("CMI Unit of Measure");
ActivateField("CMI Adj Percentage");
//added below line for S041 C&I 4462 by JQ487 on 12/21/2011
ActivateField("CMI Parent Line Item Id");
NewRecord(NewAfter);
//Inactivating to fix 546, temporary Inactivation by ju982
//SetFieldValue("CMI Amount", sOrderLineExtMiscPrc);
//SetFieldValue("CMI Quantity Requested", sQtyReq);//Commented line for defect 877 by ko981 on 12/09/2011
//SetFieldValue("CMI Unit Price", sUniPrice);//Commented line for defect 877 by ko981 on 12/09/2011
//SetFieldValue("CMI Product Id", sProdId);//Commented for DBUNG000002696 by ki795 on 8-Nov-2011
//DBUNG000002696 change the setfield value to picklist buscomp pick by ki795 on 8-Nov-2011
var sProductPickBC:BusComp = GetPicklistBusComp("CMI Product for ClaimBySR");// RR 09/07/2013:: Changed the picklist field name for CQ 12437
with (sProductPickBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sProdId);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
Pick();
}
sProductPickBC = null
//End of DBUNG000002696 code by ki795 on 8-Nov-2011
SetFieldValue("CMI Quantity Requested", sQtyReq);//Added line for defect 877 by ko981 on 12/09/2011
TheApplication().SetProfileAttr("CMI PriceAsOfDate Flag","Y");//Added line for DBUNG00004013 by ko981 on 12/13/2011
SetFieldValue("CMI Unit Price", sUniPrice);//Added line for defect 877 by ko981 on 12/09/2011
TheApplication().SetProfileAttr("CMI PriceAsOfDate Flag","N");//Added line for DBUNG00004013 by ko981 on 12/13/2011
SetFieldValue("CMI Unit of Measure", sUOM);
//Added by Km326 for C&I 4457 on 20-12-2011
SetFieldValue("CMI Adj Percentage", sCoveredPercent);
//added below line for S041 C&I 4462 by JQ487 on 12/21/2011
if(sFlag == "Y")
{
SetFieldValue("CMI Parent Line Item Id", sParentItemId);
}
WriteRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
}

CMI CreateSRClaimsByOrder
CreateOthersforWriteIn
/******************************************
Created By : KL968
Created On : 09/15/2011
Method Name: CreateOthersforWriteIn
C&I Number : 4457
Requirement#: S271
Functionality: Create SR Claim for WriteIn Product under Other items
Input:
Output:
******************************************/
function CreateOthersforWriteIn(sQtyReq, sProdId, sNetPrice,sOrderLineExtMiscPrc,sOrderLineCost,sWriteInDesc,sItemId,sUnitPrice)
{
try
{
TheApplication().Utility.logStack("CreateOthersforWriteIn", this);
var writeInProdId;
with(oBCClaimsOthers) {
ActivateField("CMI Adj Percentage");
ActivateField("CMI Quantity Requested");
ActivateField("CMI Unit Price");
ActivateField("CMI Product Id");
ActivateField("CMI Unit Cost");
ActivateField("CMI Write In Description");
//Added by KM326 for bug 878 on 09-12-2011
ActivateField("CMI Description");
NewRecord(NewAfter);
//SetFieldValue("CMI Amount", sOrderLineExtMiscPrc);
//START Added pick BC for defect 877 by ko981 on 12/09/2011
var sProductPickBC:BusComp = GetPicklistBusComp("CMI Product");
with (sProductPickBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sProdId);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
Pick();
}
sProductPickBC = null
//END Added pick BC for defect 877 by ko981 on 12/09/2011
SetFieldValue("CMI Adj Percentage", sItemId);
SetFieldValue("CMI Quantity Requested", sQtyReq);
//Modified by KM326 for C&I 4457 on 20-12-2011
//SetFieldValue("CMI Unit Price", sNetPrice);
SetFieldValue("CMI Unit Price", sUnitPrice);
// BB 091313: CQ 12491. checking product Id set by above pick and uncommenting set field
writeInProdId = GetFieldValue("CMI Product Id");
if (writeInProdId.length == 0)
SetFieldValue("CMI Product Id", sProdId);//TBU this will copy the write in product from order line item to Claim, we can give product id of the “Other” product here to replace It with “Other”
//Commented above line for defect 877 by ko981 on 12/09/2011
SetFieldValue("CMI Write In Description",sWriteInDesc);
SetFieldValue("CMI Unit Cost", sOrderLineCost);
//Added by KM326 for bug 878 on 09-12-2011
SetFieldValue("CMI Description",sWriteInDesc);
WriteRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
}

CMI CreateSRClaimsByOrder
CreateParts
function CreateParts(sProdId, sQtyReq, sUniPrice, sWrrtyCvrdPercent, sPriceListId, sOrderLineCost, sUOM)
{
try
{
TheApplication().Utility.logStack("CreateParts", this);
with(oBCClaimsParts)
{
//Commented out update of Price list since field is now a join from Claim Header by IX970 for 4814 On 10/20/2011
//Retrofit on 11/7/2011 by IX970
//ActivateField("CMI Price Id");
ActivateField("CMI Unit of Measure");
NewRecord(NewAfter);
//Modified by jq486- 10 Dec 2011- For Temporary Workaround, the SetField Value is done instead of Pick(). Otherwise the script fails below.
SetFieldValue("CMI Product Id", sProdId);//Commented for DBUNG000002696 by ki795 on 8-Nov-2011
//DBUNG000002696 change the setfield value to picklist buscomp pick by ki795 on 8-Nov-2011
/*var sProductPickBC:BusComp = GetPicklistBusComp("CMI Part Name");
with (sProductPickBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sProdId);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
Pick();
}
sProductPickBC = null*/
//End of DBUNG000002696 code by ki795 on 8-Nov-2011
SetFieldValue("CMI Quantity", sQtyReq);
SetFieldValue("CMI Unit Price", sUniPrice);
SetFieldValue("CMI Adj Percentage", sWrrtyCvrdPercent);
//Commented out update of Price list since field is now a join from Claim Header by IX970 for 4814 On 10/20/2011
//Retrofit on 11/7/2011 by IX970
//SetFieldValue("CMI Price Id", sPriceListId);
SetFieldValue("CMI Unit Cost", sOrderLineCost);
SetFieldValue("CMI Unit of Measure", sUOM);
WriteRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
}

CMI CreateSRClaimsByOrder
CreateSRClaim
function CreateSRClaim(Inputs, Outputs) {
/******************************************
Created By :<Alex Xu>
Created On : <3/12/2011>
Method Name: CreateSRClaim
C&I Number : 4608
Requirement#:
Functionality: <Create SR Claims by Order ID>
Input: <Order Id>
Output:
******************************************/
try {
TheApplication().Utility.logStack("CreateSRClaim", this);
var sOrderId = Inputs.GetProperty("Order Id");
var sSRId = "";
var sProdId = "";
var sProdType = "";
var sQtyReq = 0;
var sSRWarrtyId = "";
var sUniPrice = 0;
var sUnitPrice = 0;//created new variable; defect 877 by ko981 on 12/09/2011
var sWrrtyCvrdPercent = 0;
var sSRTId = "";
var sSRTStepId = "";
var sSRTHour = 0;
var sAccessCode = "";
var sSRTQty = 0;
var sOrderLineProdLine = "";
var sOrderLineVendor = "";
var sOrderLineGroupId = "";
var sOrderLineExtMiscPrc = 0;
var sOrderLineProductId ="";
var sOrderLineItemQty=0;
var sOrderPriOrgId = "";
var sPriceListId = "";
var sParentId = "";
var sUOM = "";
var sOrderLineCost = 0;
var sSRPriDivisionId = "";
var internalWarranty = TheApplication().InvokeMethod("LookupValue", "CMI_CLAIM_BUS_ENTITY", "Internal");
var warrantyType;
var oBOCreateClaims = TheApplication().GetBusObject("CMI SR Claims Creation BO");
var oBCCreateClaims = oBOCreateClaims.GetBusComp("CMI SR Claims Creation BC");
var sOrderLineWriteInIdentifier : String = "No";
var sNetPrice;
var sWriteInDesc;
var sOtherProdId;
var sSRClaimId = "";
var sProdName;
var sParentItemId;
var sCustomerDown = TheApplication().InvokeMethod("LookupValue", "CMI_CD_EM", "Customer Down");
var sEconomy = TheApplication().InvokeMethod("LookupValue", "CMI_CD_EM", "Economy");
var sFlag;
var sFSWarId = "";
var sPreSRWrrtyId = "";
var sCurSRWrrtyId = "";
with(oBCCreateClaims) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("CMI Unit of Measure");
ActivateField("CMI Product Name");
ActivateField("CMI Parent Order Item Id");
ActivateField("CMI Warranty BE Price - Calc1");
ActivateField("CMI FS Warranty Id"); //Added by KM326 on 04-02-2012 to fix Bug 4824
SetSearchSpec("CMI Order Id", sOrderId);
SetSortSpec("CMI SR Warranty Id");
ExecuteQuery(ForwardOnly);
var sIsCreation = FirstRecord();
TheApplication().Utility.logVars("Warranty for Order ("+sOrderId+") Found?", sIsCreation);
while(sIsCreation) {
sCurSRWrrtyId = GetFieldValue("CMI SR Warranty Id");
warrantyType = GetFieldValue("CMI FS Warranty Type");
TheApplication().Utility.logStep("Process ("+sCurSRWrrtyId+" / "+sPreSRWrrtyId+") Warranty Type: "+warrantyType);
if (warrantyType != internalWarranty) {
sSRId = GetFieldValue("CMI Order SR Id");
sProdId = GetFieldValue("CMI Order Item Product Id");
sProdType = GetFieldValue("CMI Product Type");
sQtyReq = ToNumber(GetFieldValue("CMI Quantity Requested"));
sSRWarrtyId = GetFieldValue("CMI SR Warranty Id");
sWrrtyCvrdPercent = GetFieldValue("CMI Percent Covered");
sUniPrice = GetFieldValue("CMI Warranty Price Local");
sUnitPrice = GetFieldValue("CMI Warranty BE Price - Calc1");
sSRTId = GetFieldValue("CMI SRT Id");
sSRTStepId = GetFieldValue("CMI SRT Step Id");
sSRTHour = GetFieldValue("CMI SRT Hours");
sAccessCode = GetFieldValue("CMI SRT Access Code");
sSRTQty = GetFieldValue("CMI SRT Quantity");
sOrderLineProdLine = GetFieldValue("CMI Order Line Prod Line");
sOrderLineVendor = GetFieldValue("CMI Order Line Vendor");
sOrderLineGroupId = GetFieldValue("CMI SRT Group Id");
sOrderLineExtMiscPrc = GetFieldValue("CMI Extended Price Local");
sOrderLineProductId= GetFieldValue("CMI Order Item Product Id");
sOrderLineItemQty= GetFieldValue("CMI OLI Qty");
sOrderPriOrgId = GetFieldValue("CMI Order Pri Org Id");
sParentId = GetFieldValue("Parent Id");
sPriceListId = GetFieldValue("CMI Warranty Price List Id");
sUOM = GetFieldValue("CMI Unit of Measure");
sOrderLineCost = GetFieldValue("CMI Order Line Item Cost Local");//Change from 'CMI Order Line Item Cost' to 'CMI Order Line Item Cost Local' by jr418 on June 14.
sSRPriDivisionId = GetFieldValue("CMI SR Pri Division Id");
sOrderLineWriteInIdentifier = GetFieldValue("CMI Write In Identifier");
sNetPrice = GetFieldValue("CMI Line Net Price");
sProdName = GetFieldValue("CMI Product Name");
sParentItemId = GetFieldValue("CMI Parent Order Item Id");
sFSWarId = GetFieldValue("CMI FS Warranty Id");
TheApplication().Utility.logVars("Product", sProdName);
if((sProdName == sCustomerDown) || (sProdName == sEconomy)) {
sFlag = "Y";
}
if(sPreSRWrrtyId != sCurSRWrrtyId) {//create new Claim
TheApplication().Utility.logVars("Claim Id", sSRClaimId);
if(sSRClaimId != "" && sSRClaimId != null) {
ChangeClaimStatus(sSRClaimId);
CallSRClaimPricingWF(sSRClaimId);//Added to invoke CMI SR Claims iLog Price for defect#847 by KM331 on 12/09/2011;
}
sSRClaimId = CreateClaimHeaderNoteFailCd(sSRId, sOrderId, sOrderPriOrgId, sSRWarrtyId, sSRPriDivisionId, sFSWarId,sPriceListId); //sFSWarId added as input by km326 to fix bug 4824 on 04-02-2012
sPreSRWrrtyId = sCurSRWrrtyId;
}
//use existing Claim
//START Querying Order Line Item Warranty BC to get warranty price; defect 877 by ko981 on 12/09/2011
//RR 07/25/2012:: Inactivated the code below for CQ 9079 as we dont ned it just to get the Unit Price... Unit Price can be obtained from the main BC used in this script
/* var oBOOrderEntrySales = TheApplication().GetBusObject("Order Entry (Sales)");
var oBCOrder = oBOOrderEntrySales.GetBusComp("Order Entry - Orders");
var oBCOrderLineItem = oBOOrderEntrySales.GetBusComp("Order Entry - Line Items");
var oBCOrderLineWrrty = oBOOrderEntrySales.GetBusComp("CMI Order Line Item Warranty");
with (oBCOrder) {//RR 07/25/2012:: Added for CQ 9079
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sOrderId);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) {//RR 07/25/2012:: End of code Added for CQ 9079
with (oBCOrderLineItem) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sParentId);//Modified line for DBUNG00004013, querying against order line item id by ko981 on 12/13/2011
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Line ("+sParentId+") Found?", FirstRecord());
if (FirstRecord()) {
with (oBCOrderLineWrrty) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("Parent Id");
ActivateField("CMI SR Warranty Id");
ActivateField("CMI Warranty BE Price - Calc1");
ActivateField("CMI Warranty BE Price - Calc Local");
//SetSearchSpec("Parent Id", sParentId);
SetSearchSpec("CMI SR Warranty Id", sSRWarrtyId);
ExecuteQuery(ForwardOnly);
var sIsRec = FirstRecord();
TheApplication().Utility.logVars("Line Warranty Found?", sIsRec);
if (sIsRec) {
//Modified by km326 to fix bug 4205 on 30-12-2011
//sUnitPrice = GetFieldValue("CMI Warranty BE Price - Calc");
sUnitPrice = GetFieldValue("CMI Warranty BE Price - Calc1");
}
}//END Querying Order Line Item Warranty BC
}//END if (FirstRecord())
}//END with (oBCOrderLineItem)
}
}*/
//Added by KL968 for C & I 4457,Req# 271 on 09/15/2011 for fetching if the products are Write In
TheApplication().Utility.logVars("Write In", sOrderLineWriteInIdentifier);
if(sOrderLineWriteInIdentifier == "Yes") {
sOtherProdId = TheApplication().InvokeMethod("LookupValue", "CMI_REPLACE_ITEM", "Other");
sProdId = GetReplaceItem(sOtherProdId);//Added to get the the Replace Item field of other product(Field Creation is part of TS4610)
sWriteInDesc = GetFieldValue("CMI Write In Description");
CreateOthersforWriteIn(sQtyReq, sProdId, sNetPrice,sOrderLineExtMiscPrc,sOrderLineCost,sWriteInDesc,sWrrtyCvrdPercent,sUnitPrice); //Passing sUnitPrice for 4457 on 20-12-2011 by KM326
}
TheApplication().Utility.logVars("Product Type", sProdType);
switch (sProdType) {
case sMisc:
if(sOrderLineWriteInIdentifier != "Yes")//Added by KL968 for C & I 4457,Req# 271 on 09/15/2011
CreateOthers(sQtyReq, sProdId, sUnitPrice, sOrderLineExtMiscPrc, sUOM, sWrrtyCvrdPercent, sParentItemId, sFlag); //Passing sWrrtyCvrdPercent for 4457 on 20-12-2011 by KM326
sFlag = "";
break;
case sLabor:
CreateSRT(sSRTId, sSRTStepId, sSRTHour, sAccessCode, sSRTQty, sWrrtyCvrdPercent, sOrderLineVendor, sOrderLineProdLine, sOrderLineGroupId,sOrderLineProductId,sOrderLineItemQty,sUOM,sProdName);
break;
default:
if(sOrderLineWriteInIdentifier != "Yes")//Added by KL968 for C & I 4457,Req# 271 on 09/15/2011
CreateParts(sProdId, sQtyReq, sUniPrice, sWrrtyCvrdPercent, sPriceListId, sOrderLineCost, sUOM);
break;
}
}
sIsCreation = NextRecord();
}
if(sSRClaimId != "" && sSRClaimId != null) {
ChangeClaimStatus(sSRClaimId);
CallSRClaimPricingWF(sSRClaimId);//Added to invoke CMI SR Claims iLog Price for defect#847 by KM331 on 12/09/2011;
}
}//end with(oBCCreateClaims)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCCreateClaims=null;
oBOCreateClaims=null;
//oBCOrderLineWrrty = null;
//oBCOrderLineItem = null;
//oBCOrder = null;
//oBOOrderEntrySales = null;
TheApplication().Utility.logUnstack();
}
}

CMI CreateSRClaimsByOrder
CreateSRT
function CreateSRT(sSRTId, sSRTStepId, sSRTHour, sAccessCode, sSRTQty, sWrrtyCvrdPercent, sOrderLineVendor, sOrderLineProdLine, sOrderLineGroupId,sOrderLineProductId,sOrderLineItemQty, sUOM,sProdName)
{
try
{
TheApplication().Utility.logStack("CreateSRT", this);
with(oBCClaimsSRT) {
ActivateField("CMI Unit of Measure");
NewRecord(NewAfter);
//CMI <Release# 3 - DBU>, Defect # 36 <Configuration>: < map SRT Group from Order line item Labor to Claim SRT list applet > By <jr419> On <11/03/2011>
SetFieldValue("CMI Vendor", sOrderLineVendor);
SetFieldValue("CMI Product Line", sOrderLineProdLine);
SetFieldValue("CMI Group Id", sOrderLineGroupId);
SetFieldValue("CMI SRT Access Code", sAccessCode)
SetFieldValue("CMI SRT Id", sSRTId);
SetFieldValue("CMI SRT Step Id", sSRTStepId);
SetFieldValue("CMI SRT Hours", sSRTHour);
SetFieldValue("CMI SRT Quantity", sSRTQty);
//SetFieldValue("CMI SRT Product Id",sOrderLineProductId); //Commented for DBUNG000002696 by ki795 on 8-Nov-2011
//DBUNG000002696 change the setfield value to picklist buscomp pick by ki795 on 8-Nov-2011
var sProductPickBC:BusComp = GetPicklistBusComp("CMI Product Name Auto Claim");
with (sProductPickBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderLineProductId);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
Pick();
else
{
SetFieldValue("CMI SRT Product Id", sOrderLineProductId);
}
}
sProductPickBC = null
//End of DBUNG000002696 code by ki795 on 8-Nov-2011
SetFieldValue("CMI Qty",sOrderLineItemQty);
SetFieldValue("CMI Percentage of SRT", sWrrtyCvrdPercent);
SetFieldValue("CMI Unit of Measure", sUOM);
WriteRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
}

CMI CreateSRClaimsByOrder
GetReplaceItem
function GetReplaceItem(sId)
{
//JQ486:Added on 03 Jan 2011 for write-in product addition.This function will search in the product bc to retrieve the write-in's actual procuct name and id.
try
{
TheApplication().Utility.logStack("GetReplaceItem", this);
var oBO = TheApplication().GetBusObject("Internal Product");
var oBCInterProd = oBO.GetBusComp("Internal Product");
var sProductOtherId="";
with(oBCInterProd)
{
SetViewMode(AllView);
//ActivateField("Product");
ActivateField("Name");
ClearToQuery();
SetSearchSpec("Name", sId);
ExecuteQuery(ForwardOnly);
var isRec1 = FirstRecord();
if(isRec1)
{
sProductOtherId = GetFieldValue("Id");
//sProduct = GetFieldValue("Name");
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCInterProd = null;
oBO = null;
TheApplication().Utility.logUnstack(sProductOtherId);
}
return(sProductOtherId);
}

CMI CreateSRClaimsByOrder
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retValue = CancelOperation;
if (MethodName == "CreateSRClaimsByOrder") {
CreateSRClaim(Inputs, Outputs);
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
oBCClaimsNote = null;
oBCClaimsFailCd = null;
oBCClaimsParts = null;
oBCClaimsSRT = null;
oBCClaimsOthers = null;
oBCClaimsMulti = null;
oBCClaimsSimple = null;
oBCSRFailCd = null;
oBCSRWarrty = null;
oBCSRWarrantyFailRL = null;
oBCSRNote = null;
oBCSR = null;
oBOSR = null;
oBCClaims = null;
oBOClaims = null;
TheApplication().Utility.logUnstack(retValue);
}
return (retValue);
}

CMI CreditCheck Notification BS
SendInboxItem
function SendInboxItem(Inputs, Outputs){
// Added/Modified By <jr419> for <try catch block code review> on <01/06/2011>
//<Begin>
try
{
var positionName = Inputs.GetProperty("Position Name");
var positionType = Inputs.GetProperty("Position Type");
var psMessage = TheApplication().NewPropertySet();
psMessage.SetType("InboxInfo");
var psItem = TheApplication().NewPropertySet();
var psOwner ;
var Temp_id = "NONE";
var PrimaryId = "";
psItem.SetType("InboxItemInfo");
psItem.SetProperty("ObjectId", Inputs.GetProperty("ObjectId"));
psItem.SetProperty("InboxName",Inputs.GetProperty("InboxName"));
psItem.SetProperty("InboxTypeName", Inputs.GetProperty("InboxTypeName"));
var bcPosition = TheApplication().GetBusObject("Position").GetBusComp("Position");
with(bcPosition){
ActivateField("Name");
ActivateField("Primary Employee Id");
ActivateField("Id");
ActivateField("Position Type");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Name", positionName);
SetSearchSpec("Position Type", positionType);
ExecuteQuery(ForwardOnly);
var isRecord = FirstRecord();
if(isRecord){
PrimaryId = GetFieldValue("Primary Employee Id");
Temp_id = GetFieldValue("Id");
}
}
psItem.SetProperty("InboxPartyId",PrimaryId);
var bcAccount = TheApplication().GetBusObject("Employee").GetBusComp("Employee");
with(bcAccount){
ActivateField("Position Id");
ActivateField("Id");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Position Id", Temp_id);
ExecuteQuery(ForwardOnly);
var count = CountRecords();
var haverecords = FirstRecord();
while(haverecords){
if(PrimaryId != GetFieldValue("Id")){
psOwner = TheApplication().NewPropertySet();
psOwner.SetType("InboxOwnerInfo");
psOwner.SetProperty("OwnerPartyId",GetFieldValue("Id"));
psItem.AddChild(psOwner);
}
haverecords = NextRecord();
}
}
psMessage.AddChild(psItem);
var inboxInputs = TheApplication().NewPropertySet();
var inboxOnputs = TheApplication().NewPropertySet();
inboxInputs.AddChild(psItem);
var InboxBS = TheApplication().GetService("Universal Inbox");
InboxBS.InvokeMethod("CreateInbox",psMessage,inboxOnputs);
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
finally
{
positionName = null;
positionType = null;
psMessage = null;
psItem = null;
psOwner = null;
Temp_id = null;
PrimaryId = null;
//Added by shanmukh for code clean up 08/26/2011
bcPosition = null;
bcAccount = null;
inboxInputs = null;
inboxOnputs = null;
InboxBS = null;
}
//<End>
}

CMI CreditCheck Notification BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
// Added/Modified By <jr419> for <try catch block code review> on <01/06/2011>
//<Begin>
try
{
if(MethodName == "SendInboxItem"){
SendInboxItem(Inputs, Outputs);
return (CancelOperation);
}
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
/*Commented by shanmukh for code clean up 08/26/2011
finally
{
}*/
//<End>
return (ContinueOperation);
}

CMI CreditCheck Runtime Event BS
ValidateQuote
function ValidateQuote(Inputs,Outputs)
{
try
{
row_id = Inputs.GetProperty("RowId");
QuoteTotal = TheApplication().ActiveBusObject().GetBusComp("Quote").GetFieldValue("Quote Total");
var aQuotePaymentMethod = TheApplication().ActiveBusObject().GetBusComp("Quote").GetFieldValue("CMI Payment Method");
var BillToSite = ""
BillToSite = TheApplication().ActiveBusObject().GetBusComp("Quote").GetFieldValue("CMI Bill To Profile Id");
// bcQuote = TheApplication().GetBusObject("Quote").GetBusComp("Quote");
if(row_id =="")
row_id = TheApplication().ActiveBusObject().GetBusComp("Quote").GetFieldValue("Id");
if (BillToSite == "")
TheApplication().RaiseError("CMI Credit Check Bill To");
if (TheApplication().ActiveBusObject().GetBusComp("Quote").GetFieldValue("Quote Display Type") == TheApplication().InvokeMethod("LookupValue","QUOTE_TYPE","Wholegoods Quote"))
{
QuoteTotal = 0; // to ensure that Credit check is bypassed for Whole Goods Quote..only Bill To Site is checked for a whole goods Quote
}
if (QuoteTotal != 0 && aQuotePaymentMethod == tempMethod)
QuoteCreditToBeValidated();
else
TheApplication().SetProfileAttr("CMIQuoteCreditCheckValidate","Approved");
}
catch(e)
{
throw e;
}
finally
{
BillToSite = null;
//Added by shanmukh for code clean up 08/26/2011
aQuotePaymentMethod = null;
}
}

CMI CreditCheck Runtime Event BS
(declarations)
//r OrderCreditCheckNeeded = "Y";
//var QuoteCreditCheckNeeded = "Y";
var aActiveBO = "";
var aActiveBC = "";
var aField = "";
var CreditToBeValidated = 0;
var CreditValidated = 0;
var QuoteTotal = 0;
var tempMethod = TheApplication().InvokeMethod("LookupValue","PAYMENT_METHOD_CODE","Purchase Order");
var row_id;
var OrderPaymentId = ""; //this will hold the Payment Id at the Order
var bcQuote;
var bcPayment;
//var aActiveBusComp;
//var aActiveBusObject;
// aActiveBusObject = TheApplication().ActiveBusObject();
// aActiveBusComp = aActiveBusObject.GetBusComp(aActiveBC);

CMI CreditCheck Runtime Event BS
CallCreditCheckOrderInterface
function CallCreditCheckOrderInterface(row_id,OrderPaymentId)
{
// Added/Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
// Function to Call Credit Check OOTB interface
var tempBS = TheApplication().GetService("Workflow Process Manager");
var tempInput = TheApplication().NewPropertySet();
var tempOutput = TheApplication().NewPropertySet();
// tempInput.SetProperty("RowId",paymentId);
tempInput.SetProperty("RowId",OrderPaymentId);
tempInput.SetProperty("ProcessName","SWISendCreditCheck");
tempBS.InvokeMethod("RunProcess",tempInput,tempOutput);
var bcOrderHold = TheApplication().ActiveBusObject().GetBusComp("PDS Simplified Order");
var hold_flg = "N"
with (bcOrderHold)
{
ActivateField("Hold Flag");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Id",row_id);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
hold_flg = GetFieldValue("Hold Flag");
}
}
if (hold_flg == "Y")
{
//raise a soft warning to user.
}
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
finally
{
tempBS = null;
tempInput = null;
tempOutput = null;
bcOrderHold = null;
hold_flg = null;
}
//<End>
}

CMI CreditCheck Runtime Event BS
ChangeStatusToVerification
function ChangeStatusToVerification(Inputs, Outputs)
{
// Added/Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
row_id = Inputs.GetProperty("RowId");
if(row_id =="")
row_id = TheApplication().ActiveBusObject().GetBusComp("Quote").GetFieldValue("Id");
tempMethod = TheApplication().InvokeMethod("LookupValue","PAYMENT_METHOD_CODE","Purchase Order");
//var tempPaymentTerm = TheApplication().ActiveBusObject().GetBusComp("Quote").GetFieldValue("Payment Term");
// if (Revision > 1)
// QuoteCreditToBeValidated();
bcPayment = TheApplication().GetBusObject("Quote").GetBusComp("Payments");
with(bcPayment)
{
ActivateField("Id");
ActivateField("Base Quote Id");
ActivateField("Quote Id");
ActivateField("Payment Method");
ActivateField("Payment Term");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Base Quote Id",row_id);
SetSearchSpec("Payment Method",tempMethod);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
//bcPayment.InvokeMethod("CreditCheck");
var NodoPaymentTerm = TheApplication().InvokeMethod("LookupValue","CMI_CREDIT_ABOUT","NoCreditTerm");
var tempPaymentTerm = GetFieldValue("Payment Term");
if(tempPaymentTerm != NodoPaymentTerm){
var paymentId = GetFieldValue("Id");
var tempBS = TheApplication().GetService("Workflow Process Manager");
var tempInput = TheApplication().NewPropertySet();
var tempOutput = TheApplication().NewPropertySet();
// tempInput.SetProperty("RowId",paymentId);
tempInput.SetProperty("RowId",row_id);
tempInput.SetProperty("FromSingal","N");
tempInput.SetProperty("Payment #",paymentId);
tempInput.SetProperty("ProcessName","CMISendQuoteCreditCheck");
tempBS.InvokeMethod("RunProcess",tempInput,tempOutput);
var tempBS2 = TheApplication().GetService("Workflow Process Manager");
var tempAfterInput = TheApplication().NewPropertySet();
var tempAfterOutput = TheApplication().NewPropertySet();
tempAfterInput.SetProperty("RowId",paymentId);
tempAfterInput.SetProperty("RefreshSkip","Yes"); //Added by ki795 for Internal Bug # 40 on 21-Sep-2011
tempAfterInput.SetProperty("ProcessName","CMI Credit Check After Flow Process Payment WF");
tempBS2.InvokeMethod("RunProcess",tempAfterInput,tempAfterOutput);
var RaiseBS = TheApplication().GetService("CMI DBU Raise Error BS");
var RaiseInput = TheApplication().NewPropertySet();
var RaiseOutput = TheApplication().NewPropertySet();
RaiseInput.SetProperty("row_id",row_id);//Added by ki795 for Internal Bug # 40 on 21-Sep-2011
RaiseBS.InvokeMethod("CallByCreditCheckSingle",RaiseInput,RaiseOutput);
}
}
}
/*}
else
{
with(bcQuote)
{
ActivateField("Status");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",row_id);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
SetFieldValue("Status",TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Approved"));
}
}
//update status of Quote to Approved
}
*/
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
finally
{
bcPayment = null;
NodoPaymentTerm = null;
tempPaymentTerm = null;
tempPaymentTerm = null;
tempBS = null;
tempInput = null;
tempOutput = null;
tempBS2 = null;
tempAfterInput = null;
tempAfterOutput = null;
RaiseBS = null;
RaiseInput = null;
RaiseOutput = null;
}
//<End>
}

CMI CreditCheck Runtime Event BS
CheckOneOffItem
function CheckOneOffItem(Inputs, Outputs)
{
try{
var tBO = TheApplication().GetBusObject("PDS Simplified Quote");
var tQuoteItem = tBO.GetBusComp("PDS Simplified Quote Item");
var QuoteId = Inputs.GetProperty("RowId");
var raiseErrorFlag = "N";
var FailedProdsNotsend = "";
var FailedProdsNotsync = "";
var PickBC;
var WriteInName;
var WriteInStatus;
with(tQuoteItem)
{
InvokeMethod("SetAdminMode", "TRUE");
ActivateField("Id");
ActivateField("Quote Id");
ActivateField("CMI Write-In Status Code");
/*==================below added by jr418=================*/
/*===================Date: Apr 08, 2011==================*/
/*=====Purpose: Change Write-In product name ============*/
ActivateField("Write-In Product");
ActivateField("CMI Write In Description");
ActivateField("CMI Write-In Message");
ActivateField("CMI Write-In Product Type");
ActivateField("Product");
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr("[Quote Id] = '"+QuoteId+"' AND ([Part Number] = 'SEBLRSVWIP1' OR [Part Number] = 'SEBLRSVLP1')");
ExecuteQuery(ForwardOnly);
var isRecord = FirstRecord();
while(isRecord)
{
WriteInName = GetFieldValue("Write-In Product");
WriteInStatus = GetFieldValue("CMI Write-In Status Code");
if (WriteInStatus =="SUCCESS")
{
PickBC = GetPicklistBusComp("Product");
// with(PickBC)
// {
PickBC.InvokeMethod("SetAdminMode", "TRUE");
PickBC.ActivateField("Name");
PickBC.ClearToQuery();
PickBC.SetSearchSpec("Product Name", WriteInName);
PickBC.ExecuteQuery(ForwardOnly);
if (PickBC.FirstRecord())
{
PickBC.Pick();
tQuoteItem.SetFieldValue("CMI Write In Description", "");
tQuoteItem.SetFieldValue("CMI Write-In Status Code", "");
tQuoteItem.SetFieldValue("CMI Write-In Message", "");
tQuoteItem.SetFieldValue("CMI Write-In Product Type", "");
tQuoteItem.SetFieldValue("Write-In Product", "");
tQuoteItem.WriteRecord();
}
else
{
raiseErrorFlag = "Y";
FailedProdsNotsync = WriteInName + "," + FailedProdsNotsync;
}
// } //end of (PickBC)
}
else
{
raiseErrorFlag = "Y";
FailedProdsNotsend = WriteInName + "," + FailedProdsNotsend;
}
PickBC = null;
isRecord = NextRecord();
}//end of while(isRecord)
}//end of with(tQuoteItem)
if (raiseErrorFlag == "Y")
{
if(FailedProdsNotsend != "" && FailedProdsNotsync == "")
{
TheApplication().RaiseError("CMI One Off Error Message1", FailedProdsNotsend);
}
if(FailedProdsNotsend != "" && FailedProdsNotsync != "")
{
TheApplication().RaiseError("CMI One Off Error Message3", FailedProdsNotsend, FailedProdsNotsync);
}
if(FailedProdsNotsend == "" && FailedProdsNotsync != "")
{
TheApplication().RaiseError("CMI One Off Error Message2", FailedProdsNotsync);
}
}
/*===========above added by jr418===========*/
}//end of try
catch(e){
throw e;
}
finally{
tQuoteItem = null;
tBO = null;
QuoteId = null;
QuoteId = null;
raiseErrorFlag = null;
FailedProdsNotsend = null;
FailedProdsNotsync = null;
PickBC=null;
WriteInName=null;
WriteInStatus=null;
}
}

CMI CreditCheck Runtime Event BS
CreditCheckOrder
function CreditCheckOrder(Inputs,Outputs)
{
// Function to Call credit check after performing the validations related to Quote its created from
try
{
row_id = Inputs.GetProperty("RowId");
var inPS = TheApplication().NewPropertySet();
var outPS = TheApplication().NewPropertySet();
inPS.SetProperty("Id","");
inPS.SetProperty("Quote Id","");
inPS.SetProperty("Order Total","");
inPS.SetProperty("CMI Payment Method","");
inPS.SetProperty("CMI Bill To Profile Id","");
TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetMultipleFieldValues(inPS,outPS);
if(row_id =="")
row_id = outPS.GetProperty("Id"); //TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetFieldValue("Id");
var Order_QuoteId = outPS.GetProperty("Quote Id"); //TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetFieldValue("Quote Id");
var Order_TotalAmt = outPS.GetProperty("Order Total"); //TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetFieldValue("Order Total");
var aPaymentMethod = outPS.GetProperty("CMI Payment Method"); //TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetFieldValue("CMI Payment Method");
//OrderCreditCheckNeeded = "Y";
if (outPS.GetProperty("CMI Bill To Profile Id") == "")
TheApplication().RaiseError("CMI Credit Check Bill To");
// TheApplication().RaiseErrorText("Bill To Site is a Required Field");
var PaymentLineAmt = 0;
var CreditValidated = 0;
var CreditToBeValidated = 0;
TheApplication().SetProfileAttr("CMIOrderCreditCheck","N");
if (Order_TotalAmt != 0 && aPaymentMethod == tempMethod)
{
//get the Order Payment Details
//Assumin there will be only one Order (no Revisions exists)
/*if there can be more than one revision, then Set Search spec to Order Id instead on Base Order Id and
use while loop to parse through all Purchase Order Payment Lines. Inside While loop get the Base Order Id,
when base order id = order id, the payment line is created for the current order, and rest all are for previous
versions, sum up the payment lines of previous versions and reduce the amount from Order_TotalAmt (this is the
total amount to be validated at this Order)
*/
bcPayment = TheApplication().ActiveBusObject().GetBusComp("Payments");
with (bcPayment)
{
ActivateField("Base Order Id");
ActivateField("Order Id");
ActivateField("Transaction Amount");
ActivateField("Payment Method");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Order Id",row_id);
ExecuteQuery(ForwardOnly);
var RecordExists;
var BaseOrderId;
var aPaymentStatus;
var aPaymentStatusApp = TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Approved");
if (FirstRecord())
{
RecordExists = FirstRecord();
while (RecordExists)
{
var inPayPS = TheApplication().NewPropertySet();
var outPayPS = TheApplication().NewPropertySet();
inPayPS.SetProperty("Id","");
inPayPS.SetProperty("Transaction Amount","");
inPayPS.SetProperty("Base Order Id","");
inPayPS.SetProperty("Payment Status","");
GetMultipleFieldValues(inPayPS,outPayPS); //only single hit to DB.
PaymentLineAmt = outPayPS.GetProperty("Transaction Amount"); //GetFieldValue("Transaction Amount");
OrderPaymentId = outPayPS.GetProperty("Id"); //GetFieldValue("Id");
BaseOrderId = outPayPS.GetProperty("Base Order Id");
aPaymentStatus = outPayPS.GetProperty("Payment Status");
if (BaseOrderId == row_id)
CreditToBeValidated = ToNumber(CreditToBeValidated) + ToNumber(PaymentLineAmt);
else
if (aPaymentStatusApp == aPaymentStatus)
CreditValidated = ToNumber(CreditValidated) + ToNumber(PaymentLineAmt);
RecordExists = NextRecord();
}
}
else
{
ClearToQuery();
ExecuteQuery(ForwardOnly);
TheApplication().SetProfileAttr("CMIOrderCreditCheck","N");
TheApplication().RaiseError("CMI Credit Check - No Payment");
}
}
// CreditValidated -- Quotes Payment Line's total amount
// Order_TotalAmt -- Order Amount
// CreditToBeValidated --
var ActualCreditToBeValidated = ToNumber(Order_TotalAmt) - ToNumber(CreditValidated);
//Below added by jr418 on May 27,2011 to fix numberic error
var ActualCreditToBeValidated2 = ActualCreditToBeValidated.toFixed(2);
if (ActualCreditToBeValidated2 > 0)
{
//Below added by jr418 on May 27,2011 to fix numberic error
var CreditToBeValidated2 = CreditToBeValidated.toFixed(2);
if (CreditToBeValidated2 <= ActualCreditToBeValidated2)
{
if (CreditToBeValidated2 == 0) //no payment line created or payment amount = 0
TheApplication().RaiseError("CMI Credit Check - No Payment");
if (ActualCreditToBeValidated2 != CreditToBeValidated2)
TheApplication().RaiseError("CMI Credit Check - Order Quote",CreditValidated,ActualCreditToBeValidated2);
else
TheApplication().SetProfileAttr("CMIOrderCreditCheck","Y");
}
else
{
TheApplication().RaiseErrorText("Credit Check is Already done for " + CreditValidated + " Credit Check is needed only for: "+ ActualCreditToBeValidated2 );
}
}
}
TheApplication().SetProfileAttr("CMIOrderCreditCheckPayment",OrderPaymentId);
}
catch(e)
{
throw e;
}
finally
{
bcPayment = null;
inPS=null;
outPS= null;
inPayPS = null;
outPayPS = null;
PaymentLineAmt = null;
aPaymentMethod = null;
Order_TotalAmt = null;
Order_QuoteId = null;
}
}

CMI CreditCheck Runtime Event BS
DeletePaymentLines
function DeletePaymentLines(Inputs, Outputs)
{
//Esnure that the RTE calling this is having a conditional expression that the [Payment Method] is not null, this will ensure
//that we are not calling this script when there are no payment lines. Reason: Payment Method is OOTB Column which is join from child payment line
try
{
row_id = Inputs.GetProperty("RowId");
aActiveBO = TheApplication().ActiveBusObject().Name();
aActiveBC = "";
aField = "";
bcPayment = TheApplication().ActiveBusObject().GetBusComp("Payments");
switch (aActiveBO)
{
case "Order Entry (Sales)":
aActiveBC = "Order Entry - Orders";
aField = "Order Id"
break;
case "Quote":
aActiveBC = "Quote";
aField = "Quote Id";
break;
case "Service Request":
aActiveBC = "Quote";
aField = "Quote Id";
break;
}
if(row_id =="")
row_id = TheApplication().ActiveBusObject().GetBusComp(aActiveBC).GetFieldValue("Id");
with (bcPayment)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec(aField,row_id);
ExecuteQuery(ForwardOnly);
while (FirstRecord())
{
DeleteRecord();
NextSelected();
}
}
}
catch(e)
{
throw e;
}
finally
{
bcPayment = null;
aActiveBC = null;
aActiveBO = null;
}
}

CMI CreditCheck Runtime Event BS
OrderCreditCheck
function OrderCreditCheck(Inputs, Outputs)
{
try
{
row_id = Inputs.GetProperty("RowId");
if(row_id =="")
row_id = TheApplication().ActiveBusObject().GetBusComp("Quote").GetFieldValue("Id");
var tempBS = TheApplication().GetService("Workflow Process Manager");
var tempInput = TheApplication().NewPropertySet();
var tempOutput = TheApplication().NewPropertySet();
tempInput.SetProperty("RowId",TheApplication().GetProfileAttr("CMIOrderCreditCheckPayment"));
tempInput.SetProperty("ProcessName","SWISendCreditCheck");
tempBS.InvokeMethod("RunProcess",tempInput,tempOutput);
var aOrderHoldFlag = TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetFieldValue("Hold Flag");
if (aOrderHoldFlag == "Y")
TheApplication().RaiseError("CMI Credit Check - Fail");
}
catch (e)
{
throw e;
}
finally
{
tempOutput = null;
tempInput = null;
tempBS = null;
//Added by shanmukh for code clean up 08/26/2011
aOrderHoldFlag = null;
}
}

CMI CreditCheck Runtime Event BS
QuoteCreditToBeValidated
function QuoteCreditToBeValidated()
{
try
{
if (TheApplication().ActiveBusObject().GetBusComp("Quote").GetFieldValue("Quote Display Type") != TheApplication().InvokeMethod("LookupValue","QUOTE_TYPE","Wholegoods Quote"))
{
bcPayment = TheApplication().ActiveBusObject().GetBusComp("Payments");
var aPaymentStatus = TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Approved");
var aBaseQuoteId = "";
var iPaymentId = "";
with (bcPayment)
{
ActivateField("Payment Method");
ActivateField("Payment Status");
ActivateField("Quote Id");
ActivateField("Base Quote Id");
ActivateField("Transaction Amount");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Quote Id",row_id);
SetSearchSpec("Payment Method",tempMethod);
ExecuteQuery(ForwardOnly);
var RecordExists = FirstRecord();
while (RecordExists)
{
aBaseQuoteId = GetFieldValue("Base Quote Id");
if (aBaseQuoteId == row_id)
{
CreditToBeValidated = ToNumber(CreditToBeValidated) + ToNumber(GetFieldValue("Transaction Amount"));
iPaymentId = "Y";
}
else
if ( GetFieldValue("Payment Status") == aPaymentStatus )
CreditValidated = ToNumber(CreditValidated) + ToNumber(GetFieldValue("Transaction Amount"));
RecordExists = NextRecord();
}
}
var ActualCreditToBeValidated = QuoteTotal - CreditValidated;
// CreditToBeValidated
// CreditValidated
//Added by jr418 on May 27,2011 to fix numberic error
var ActualCreditToBeValidated2 = ActualCreditToBeValidated.toFixed(2);
var CreditToBeValidated2 = CreditToBeValidated.toFixed(2);
if (CreditToBeValidated2 != 0)
switch (ActualCreditToBeValidated2/CreditToBeValidated2)
{
case 1:
TheApplication().SetProfileAttr("CMIQuoteCreditCheckValidate","Y");
break;
case 0:
TheApplication().SetProfileAttr("CMIQuoteCreditCheckValidate","Approved");
break;
default:
if (ActualCreditToBeValidated <= 0)
TheApplication().SetProfileAttr("CMIQuoteCreditCheckValidate","Approved");
else
{
TheApplication().SetProfileAttr("CMIQuoteCreditCheckValidate","N");
TheApplication().RaiseError("CMI Credit Check - Transaction Amount",CreditToBeValidated2,ActualCreditToBeValidated2);
}
break;
}
else
if (ActualCreditToBeValidated2 > 0)
{
TheApplication().SetProfileAttr("CMIQuoteCreditCheckValidate","N");
if (iPaymentId == "Y")
TheApplication().RaiseError("CMI Credit Check - Zero Transaction", ActualCreditToBeValidated2 );
else
TheApplication().RaiseError("CMI Credit Check - No Payment");
}
else
TheApplication().SetProfileAttr("CMIQuoteCreditCheckValidate","Approved");
}
}
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally
{
bcPayment = null;
ActualCreditToBeValidated = null;
RecordExists = null;
aPaymentStatus = null;
}
}

CMI CreditCheck Runtime Event BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
// Added/Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
switch(MethodName)
{
case "ValidateQuote":
ValidateQuote(Inputs, Outputs);
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
case "ValidateOrder":
CreditCheckOrder(Inputs, Outputs);
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
case "ChangeStatusToVerification":
ChangeStatusToVerification(Inputs, Outputs);
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
case "CheckOneOffItem":
CheckOneOffItem(Inputs, Outputs);
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
case "DeletePaymentLines":
DeletePaymentLines(Inputs, Outputs);
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
case "CreditCheckOrder":
OrderCreditCheck(Inputs, Outputs);
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
}
/* if(MethodName=="ChangeStatusToVerification"){
ChangeStatusToVerification(Inputs, Outputs);
return (CancelOperation);
}
if(MethodName = "CheckOneOffItem"){
CheckOneOffItem(Inputs, Outputs);
return (CancelOperation);
}
*/
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
/*
//Commented the finally block , by jw920 on 20/08/11 <code clean up process>
finally
{
}*/
//<End>
return (ContinueOperation);
}

CMI CreditCheck Runtime Event BS
ValidateQuoteOrder
function ValidateQuoteOrder(row_id,Order_TotalAmt,Order_QuoteId,PaymentLineAmt)
{
//function to fetch the Quote Total Amount, and if credit check is done on it.
try
{
var QuoteAmount = 0;
var CreditCheckDone = "N";
if (Order_QuoteId != "")
{
var boOrder_Quote = TheApplication().GetBusObject("Quote");
var bcOrder_Quote = boOrder_Quote.GetBusComp("Quote");
// var bcQuotePayment = boOrder_Quote.GetBusComp("Payments");
with (bcOrder_Quote)
{
ActivateField("Quote Total");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",Order_QuoteId);
SetSearchSpec("Payment Method",tempMethod);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
QuoteAmount = GetFieldValue("Quote Total");
}
}
}
var CreditToBeVerified = Order_TotalAmt - QuoteAmount;
switch ((CreditToBeVerified/PaymentLineAmt))
{
case 0:
break;
case 1:
TheApplication().SetProfileAttr("CMIOrderCreditCheck","Y");
//Only when Payment line has correct value we will proceed for credit check
break;
default:
if (QuoteAmount == 0)
TheApplication().RaiseError("CMI Credit Check - Order Full" , CreditToBeVerified);
else
TheApplication().RaiseError("CMI Credit Check - Order Quote",QuoteAmount,CreditToBeVerified);
break;
}
}
catch(e)
{
throw e;
}
finally
{
// bcQuotePayment = null;
bcOrder_Quote = null;
boOrder_Quote = null;
CreditToBeVerified = null;
CreditCheckDone = null;
QuoteAmount = null;
}
}

CMI Customer Surver BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : Rohit Anchi (IY793)
Created On : 20th April 2010
Updated By : Techie (JR630)
Updated On : 14th Sep 2010
C&I Number : 3907
Requirement # : WU00.02
Method Name: SendSurvey
Functionality: This BS method will be triggered on through a batch job.
The process will create an excel spreadsheet with the fields listed below for each SR closed that
day (or previous day depending on what time it’s scheduled to run) and remove any records where the
contact doesn’t have an email address, has the flag set for Do Not Contact or flag set for Do Not Survey,
and where the last surveyed date is within the past 30 days.
Update Reason: INC000000813979:Customer Requested to add SR Channel at the end of the survey report
Input: ClosedDate
Output: None
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if (MethodName == "SendSurvey")
{
var sBO = TheApplication().GetBusObject("Service Request");
var sEBO = TheApplication().GetBusObject("Employee");
var sCBO = TheApplication().GetBusObject("Contact");
var sSRBC = sBO.GetBusComp("Service Request");
var sSRCntBC = sCBO.GetBusComp("Contact");
var sSROwnEmpBC = sEBO.GetBusComp("Employee");
var sCntBC = sBO.GetBusComp("Contact");
var sLOVBO = TheApplication().GetBusObject("PickList Generic");
var sLOVBC = sLOVBO.GetBusComp("PickList Generic");
var sSRNum;
var sSROwner;
var sSROwnGrp = "";
var sSRClsDt;
var sSRCntName;
var sSRCntPh;
var sSRCntEmail;
var isRecord;
var sHeader;
var srow;
var sPath;
var sfileName;
var fp = "";
var tm1;
var sSRClsVal = TheApplication().InvokeMethod("LookupValue","SR_STATUS","Closed");
var sTRUE = "Y";
var tmStrFmt1 = "";
var sSrchExp;
var sSurveyDays = TheApplication().InvokeMethod("LookupValue","CMI_SURVEY_DAYS","CMI_LAST_SURVEY_DAYS");
var sSRCntId;
var isCRecord;
var isORecord;
var sOwnerId;
var sClosedDt = Inputs.GetProperty("ClosedDate");
var sToday;
var tClosedDt;
//Add by JR630
var sSource = "";
//End by JR630
with(sLOVBC)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("Name");
ActivateField("Description");
SetSearchSpec("Name","SurveyPath");
ExecuteQuery(ForwardOnly);
sPath = GetFieldValue("Description");
}
if(sClosedDt == "")
{
tm1 = Clib.localtime(Clib.time());
Clib.strftime(tmStrFmt1, "%m_%d_%Y",tm1);
sfileName = sPath+"CustomerSurvey_"+ tmStrFmt1+".csv";
fp = Clib.fopen(sfileName, "wat+");
Clib.strftime(tmStrFmt1, "%m/%d/%Y",tm1);
}
else
{
var rtn;
var pat = "/";
tClosedDt = sClosedDt;
rtn = sClosedDt.replace(pat, "_");
sClosedDt = rtn.replace(pat, "_");
tmStrFmt1 = sClosedDt;
sfileName = sPath+"CustomerSurvey_"+ tmStrFmt1+".csv";
fp = Clib.fopen(sfileName, "wat+");
tmStrFmt1 = tClosedDt;
}
with(sSRBC)
{
SetViewMode(AllView);
ActivateField("SR Number");
ActivateField("CMI Owner");
ActivateField("CMI Closed Date");
ActivateField("Owner Group");
ActivateField("Contact First Name");
ActivateField("Contact Last Name");
ActivateField("Contact Email Address");
ActivateField("Contact Business Phone");
ActivateField("CMI CntCall Flag");
ActivateField("CMI Survey Flag");
ActivateField("CMI Survey Gap");
ActivateField("Contact Id");
ActivateField("Owned By Id");
ActivateField("CMI Today");
//Add by JR630
ActivateField("Source");
//End by JR630
ClearToQuery();
sSrchExp = "[CMI Closed Date] = '" + tmStrFmt1 + "' AND [Status] = '" + sSRClsVal + "' AND [CMI Survey Flag] <> '" + sTRUE + "' AND [CMI CntCall Flag] <> '" + sTRUE + "' AND ([CMI Survey Gap] > '" + sSurveyDays + "' OR [CMI Survey Gap] IS NULL)";
SetSearchExpr(sSrchExp);
ExecuteQuery(ForwardOnly);
/* C&I3907, DEF#CARE200001149 inactivated the below code t oremove header columns from the file by iy793 on 07 May 2020 */
// sHeader = "SR Close Date" + "," + "Contact Name" + "," + "Contact Phone #" + "," + "Contact Email Address" + "," + "SR #" + "," + "SR Owner" + "," + "Owner Division" + "\n";
// Clib.fputs(sHeader,fp);
isRecord = FirstRecord();
while (isRecord)
{
sSRNum = GetFieldValue("SR Number");
sSROwner = GetFieldValue("CMI Owner");
sSRClsDt = GetFieldValue("CMI Closed Date");
sSRCntName = GetFieldValue("Contact First Name") + " " + GetFieldValue("Contact Last Name");;
sSRCntPh = GetFieldValue("Contact Business Phone");
sSRCntEmail = GetFieldValue("Contact Email Address");
sSRCntId = GetFieldValue("Contact Id");
sOwnerId = GetFieldValue("Owned By Id");
sToday = GetFieldValue("CMI Today");
//Add by JR630
sSource = GetFieldValue("Source");
//End by JR630
if(sSRCntEmail != "")
{
//Get Owner Division
with(sSROwnEmpBC)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("Id");
ActivateField("Division");
SetSearchSpec("Id",sOwnerId);
ExecuteQuery(ForwardBackward);
isORecord = FirstRecord();
if(isORecord)
{
sSROwnGrp = GetFieldValue("Division");
}
}
//Include details in csv
//modifed by JR630
var sCareFlag;
sCareFlag = TheApplication().GetProfileAttr("Org.Type");
if (sCareFlag == "Customer Care")
{
Clib.fputs(sSRClsDt + "," + sSRCntName + "," + sSRCntPh + "," + sSRCntEmail + "," + sSRNum + "," + sSROwner + "," + sSROwnGrp + "," +sSource+"\n", fp);
}
else
{
Clib.fputs(sSRClsDt + "," + sSRCntName + "," + sSRCntPh + "," + sSRCntEmail + "," + sSRNum + "," + sSROwner + "," + sSROwnGrp + "\n", fp);
}
//End by JR630
// Update contact's Last Survey Date with Today
with(sSRCntBC)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("Id");
ActivateField("CMI Survey Date");
SetSearchSpec("Id",sSRCntId);
ExecuteQuery(ForwardBackward);
isCRecord = FirstRecord();
if(isCRecord)
{
SetFieldValue("CMI Survey Date", sToday);
WriteRecord();
}
}
}
isRecord = NextRecord();
}
}
Clib.fclose(fp);
return (CancelOperation);
}
}// end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " +"ERROR: " + e.errText +"STACK: " + e.toString());
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "ERROR: " + e.errText +"STACK: " + e.toString());
}
}// end of catch
finally
{
sSRBC = null;
sSRCntBC = null;
sLOVBC = null;
sSRNum = null;
sSROwner = null;
sSROwnGrp = null;
sSRClsDt = null;
sSRCntName = null;
sSRCntPh = null;
sSRCntEmail = null;
isRecord = null;
sHeader = null;
srow = null;
sPath = null;
sfileName = null;
fp = null;
tm1 = null;
sSRClsVal = null;
sTRUE = null;
tmStrFmt1 = null;
sSrchExp = null;
sSurveyDays = null;
sSRCntId = null;
sSRCntBC = null;
isCRecord = null;
//Pankaj K - Nullified BOs at last on 05/26/10
sBO = null;
sLOVBO = null;
sEBO = null;//Pankaj K - Nullified BOs on 05/26/10
sCBO = null;//Pankaj K - Nullified BOs on 05/26/10
//Added by shanmukh for code clean up 08/26/2011
sSROwnEmpBC = null;
sCntBC = null;
}
return(ContinueOperation);
}

CMI DBU Customer Outbound BS
(declarations)
var sAccnt_id = "";
var sAcctBO = "";
var sAcctBC = "";

CMI DBU Customer Outbound BS
CallAccountUpdate
function CallAccountUpdate(Inputs,Outputs)
{
try
{
sAcctBO = TheApplication().ActiveBusObject();
sAcctBC = sAcctBO.GetBusComp("Account");
sAccnt_id = sAcctBC.GetFieldValue("Id");
Inputs.SetProperty("ObjectId",sAccnt_id);
Inputs.SetProperty("EventId",sAccnt_id);
Inputs.SetProperty("Event","Account_Update");
CallOutboundWorkflow(Inputs,Outputs);
}
catch(e)
{
throw e;
}
finally
{
sAccnt_id = null;
sAcctBC = null;
sAcctBO = null;
}
}

CMI DBU Customer Outbound BS
CallContactAddressUpdate
function CallContactAddressUpdate(Inputs,Outputs)
{
try
{
}
catch(e)
{
}
finally
{
}
}

CMI DBU Customer Outbound BS
CallContactUpdate
function CallContactUpdate(Inputs,Outputs)
{
try
{
var sContactBO = TheApplication().ActiveBusObject();
var sContactBC = sContactBO.GetBusComp("Contact");
var sContactId = sContactBC.GetFieldValue("Id");
// sContactBC.ActivateField("Person Id");
// sAccnt_id = sContactBC.GetFieldValue("Person Id");
sContactBO = TheApplication().GetBusObject("Contact");
sContactBC = sContactBO.GetBusComp("Contact Account Affiliation");
with (sContactBC)
{
ActivateField("Account Id");
ActivateField("Contact Id");
ClearToQuery();
SetSearchSpec("Contact Id",sContactId);
ExecuteQuery(ForwardOnly);
var RecordExists = FirstRecord();
while(RecordExists)
{
Inputs.SetProperty("ObjectId",GetFieldValue("Account Id"));
Inputs.SetProperty("EventId",sContactId);
Inputs.SetProperty("Event","Contact_Update");
CallOutboundWorkflow(Inputs,Outputs);
RecordExists = NextRecord();
}
}
}
catch(e)
{
throw e;
}
finally
{
//Added by shanmukh for code clean up 08/26/2011
sContactBC = null;
sContactBO = null;
}
}

CMI DBU Customer Outbound BS
CallOutboundWorkflow
function CallOutboundWorkflow(Inputs,Outputs)
{
// Added/Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
//TheApplication().GetService ("Workflow Process Manager");statement removed by saurabh
var sWF = TheApplication().GetService("Workflow Process Manager");
var sWF_IP = TheApplication().NewPropertySet();
var sWF_OP = TheApplication().NewPropertySet();
sWF_IP.SetProperty("RowId",Inputs.GetProperty("ObjectId"));
sWF_IP.SetProperty("Entity",Inputs.GetProperty("Event"));
sWF_IP.SetProperty("Entity_Id",Inputs.GetProperty("EventId"));
sWF_IP.SetProperty("ProcessName","CMI DBU Customer Sync Outbound WF");
sWF.InvokeMethod("RunProcess",sWF_IP,sWF_OP);
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
//Commented by jw920 on 21/08/11 <code Clean up>
//Shanmukh - Uncommented finally block to nullify objects for code clean up 08/26/2011
finally
{
sWF_IP = null;
sWF_OP = null;
sWF = null;
}
//<End>
}

CMI DBU Customer Outbound BS
CallSiteUpdate
function CallSiteUpdate(Inputs,Outputs)
{
try
{
var sSiteBO = TheApplication().ActiveBusObject();
var sSiteBC = sSiteBO.GetBusComp("Organization Payment Profile");
var sSiteId = sSiteBC.GetFieldValue("Id");
sAccnt_id = sSiteBC.GetFieldValue("Person Id");
sAcctBO = TheApplication().GetBusObject("Account");
sAcctBC = sAcctBO.GetBusComp("Account");
// sAccnt_id = sAcctBC.GetFieldValue("Id");
Inputs.SetProperty("ObjectId",sAccnt_id);
Inputs.SetProperty("EventId",sSiteId);
Inputs.SetProperty("Event","Site_Update");
CallOutboundWorkflow(Inputs,Outputs);
}
catch(e)
{
}
finally
{
//Added by shanmukh for code clean up 08/26/2011
sSiteBC = null;
sSiteBO = null;
sAcctBC = null;
sAcctBO = null;
}
}

CMI DBU Customer Outbound BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
// Added/Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
switch (MethodName)
{
case "AccountUpdate":
CallAccountUpdate(Inputs, Outputs);
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
case "ContactAddressUpdate":
CallContactAddressUpdate(Inputs, Outputs);
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
case "ContactUpdate":
CallContactUpdate(Inputs, Outputs);
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
case "SiteUpdate":
CallSiteUpdate(Inputs, Outputs);
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
}
}
catch(e)
{
throw e;
}
//Commented by jw920 on 21/08/11 <code Clean up>
/* finally
{
}*/
//<End>
return (ContinueOperation);
}

CMI DBU Generic BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if (MethodName == "Error Message")
{
try
{
var sMsgCatName = Inputs.GetProperty("Message Name");
var sSRTMsgGroup = Inputs.GetProperty("SRT Group");
var sSRTMsgProcedure = Inputs.GetProperty("SRT Procedure");
var sSRTMsgStep = Inputs.GetProperty("SRT Step");
var sSRTMsgPL = Inputs.GetProperty("SRT Product Line");
var sSRTMsgAccCode = Inputs.GetProperty("SRT Access Code");
var sSRTMsgBU = Inputs.GetProperty("SRT Business Unit");
TheApplication().RaiseError(sMsgCatName , sSRTMsgGroup,sSRTMsgProcedure,sSRTMsgStep,sSRTMsgPL,sSRTMsgAccCode,sSRTMsgBU);
}
catch (e)
{
var sErrorMsg:String = e.toString();
var sErrorForm = sErrorMsg.split("(");
Outputs.SetProperty("CMI Error Msg",sErrorForm[0]);
return (CancelOperation);
}
}
return (ContinueOperation);
}

CMI DBU Raise Error BS
CallCreditCheck
/*************************************************************************************************************************
Functionality: To alert user when ever the Credit check is set to hlod.
************************************************************************************************************************/
function CallCreditCheck(Inputs,Outputs)
{
try{
var sType = Inputs.GetProperty("Type");
var bHold = Inputs.GetProperty("isHold");
switch (sType)
{
case TheApplication().InvokeMethod("LookupValue","QUOTE_TYPE", "Parts Quote"):
case TheApplication().InvokeMethod("LookupValue","QUOTE_TYPE", "Over the Counter"):
if(bHold == 'Y')
{
//Nag; 1/15/2013; Added for CQ# 9714 & 8645.
//TheApplication().RaiseErrorText("Customer does not have sufficient credit.");
Outputs.SetProperty("Error Code", "CMI_CREDIT_101");
//Outputs.SetProperty("Error Message", TheApplication().InvokeMethod("LookupName","CMI_CREDIT_CHECK", "101"));
Outputs.SetProperty("Error Message", sErrMsg101);
}
//Nag; 1/15/2013; Added for CQ# 9714 & 8645.
else if(bHold == 'P')
{
//TheApplication().RaiseErrorText("Customer is past due.");
Outputs.SetProperty("Error Code", "CMI_CREDIT_102");
Outputs.SetProperty("Error Message", sErrMsg102);
// Outputs.SetProperty("Error Message", TheApplication().InvokeMethod("LookupName","CMI_CREDIT_CHECK", "102"));
}
}
}
catch(e)
{
TheApplication().RaiseErrorText(e.toString());
}
finally //Destroying objects
{
sType = null;
}
}

CMI DBU Raise Error BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Functionality: To raise error messages
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
// Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
switch (MethodName)
{
case "CreditCheck":
CallCreditCheck(Inputs, Outputs);
return (CancelOperation);
case "ResourceAvailability":
CallResourceAvailability(Inputs, Outputs);
return (CancelOperation);
case "CallByCreditCheckSingle":
CallByCreditCheckSingle(Inputs, Outputs);
return (CancelOperation);
}
}
catch(e)
{
//Removed TheApplicaiton. for Bug # 5283 by ki795 on 2-feb-2011
TheApplication().RaiseErrorText(e.toString());
}
//Commented by jw920 ,on 21/08/11<Code Clean Up Process>
/*finally
{
}*/
return (ContinueOperation);
//<End>
}

CMI DBU Raise Error BS
(declarations)
var sErrMsg101 = "";
var sErrMsg102 = "";
var sErrMsg103 = "";
var sErrMsg104 = "";

CMI DBU Raise Error BS
CallByCreditCheckSingle
function CallByCreditCheckSingle(Inputs,Outputs)
{
// Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
//var tempQuote = TheApplication().ActiveBusObject().GetBusComp("Quote"); //Commented by ki795 on 21-Sep-2011 for Internal Bug # 40 -- No Record found error on Quote Verification
//var rowId = tempQuote.GetFieldValue("Id");//Commented by ki795 on 21-Sep-2011 for Internal Bug # 40 -- No Record found error on Quote Verification
var rowId = Inputs.GetProperty("row_id"); //Added by ki795 on 21-Sep-2011 for Internal Bug # 40 -- No Record found error on Quote Verification
var btemp = TheApplication().GetBusObject("PDS Simplified Quote").GetBusComp("PDS Simplified Quote");
var btempchild = TheApplication().GetBusObject("PDS Simplified Quote").GetBusComp("PDS Simplified Quote Item");
with(btemp)
{
ActivateField("Id");
ActivateField("CMI Hold Flag");
ActivateField("Quote Display Type");
ActivateField("CMI Quote Total");
ActivateField("CMI Validation ErrMsg_101");
ActivateField("CMI Validation ErrMsg_102");
ActivateField("CMI Validation ErrMsg_103");
ActivateField("CMI Validation ErrMsg_104");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",rowId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var isHold = GetFieldValue("CMI Hold Flag");
var iQuoteTotal = GetFieldValue("CMI Quote Total");
var sQuoteType = GetFieldValue("Quote Display Type");
sErrMsg101 = GetFieldValue("CMI Validation ErrMsg_101");
sErrMsg102 = GetFieldValue("CMI Validation ErrMsg_102");
sErrMsg103 = GetFieldValue("CMI Validation ErrMsg_103");
sErrMsg104 = GetFieldValue("CMI Validation ErrMsg_104");
//Nag; 1/15/2013; Added isHold == 'P' condition for CQ# 9714.
if(sQuoteType == "Service" && (isHold=="P" || isHold=="Y") && iQuoteTotal == 0)
{
var sReconType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type");
var sReconReturnType = TheApplication().InvokeMethod("LookupValue","CMI_LINE_TYPE","Recon Return Line type");
var sExpr = "[Quote Id] = '"+rowId+"' AND ([CMI Non Internal Warranty Percentage] < 100 OR [CMI Non Internal Warranty Percentage] IS NULL) AND [CMI Line Type] <> \'"+ sReconType+ "\' AND [CMI Line Type] <> \'"+ sReconReturnType+"\'";;
with(btempchild)
{
ActivateField("CMI Non Internal Warranty Percentage");
ActivateField("Quote Id");
SetViewMode(AllView);
ClearToQuery();
//SetSearchSpec("CMI Non Internal Warranty Percentage","< 100");
//SetSearchSpec("Quote Id",rowId);
SetSearchExpr(sExpr);
ExecuteQuery(ForwardOnly);
if(!FirstRecord())
{
if(isHold == "P")
{
Outputs.SetProperty("Error Code", "CMI_CREDIT_103");
Outputs.SetProperty("Error Message", sErrMsg103);
}
else if(isHold=="Y")
{
Outputs.SetProperty("Error Code", "CMI_CREDIT_104");
Outputs.SetProperty("Error Message", sErrMsg104);
}
}
}
}
else if(isHold=="Y" || isHold=="P")
{
Inputs.SetProperty("Type",GetFieldValue("Quote Display Type"));
//Nag; 1/15/2013; Added for CQ# 9714.
Inputs.SetProperty("isHold",isHold);
CallCreditCheck(Inputs,Outputs);
}
}
}
}
catch(e)
{
//Removed TheApplicaiton. for Bug # 5283 by ki795 on 2-feb-2011
throw e;
}
finally
{
//tempQuote = null;
sErrMsg101 = "";
sErrMsg102 = "";
sErrMsg103 = "";
rowId = null;
btempchild = null;
btemp = null;
isHold = null;
}
//<End>
}

CMI DBU Raise Error BS
CallResourceAvailability
function CallResourceAvailability(Inputs,Outputs)
{
try{
TheApplication().RaiseErrorText("A Dummy Order Request has been sent to EBS for Resource ATP");
}
catch(e)
{
//Removed TheApplicaiton. for Bug # 5283 by ki795 on 2-feb-2011
throw e;
}
//Commented by jw920 ,on 21/08/11<Code Clean Up Process>
/*finally //Destroying objects
{
} */
}

CMI Daily Work InTask BS
BillableJob
/*
Created By : Rachel-Zang
Created On : 25-Jan-2011
C&I Number : 4468
Requirement # :
Method Name: ClearBillableJob
Functionality:
Input: None
Output: None
Customization Approval #: NA
*/
function BillableJob(Inputs,Outputs)
{
// process billable job branch
try {
TheApplication().Utility.logStack("BillableJob", this);
TheApplication().Utility.logPS(Inputs);
var sActionId = Inputs.GetProperty("Action Id");
var sStatus = Inputs.GetProperty("Status");
var sDistance = Inputs.GetProperty("Distance");
var sDistanceType = Inputs.GetProperty("Distance Type");
var sSerialInput = Inputs.GetProperty("Serial # Entry");
var sReading = Inputs.GetProperty("Reading");
var sConfirmFlag = Inputs.GetProperty("Confirm Flag");
var sMeasurementType = Inputs.GetProperty("Measurement Type");
var sAssetId = Inputs.GetProperty("Asset Id");
var sAssetSerialNum = Inputs.GetProperty("Asset Serial Num");
var sSRNum = Inputs.GetProperty("SR #");
var sCreated = Inputs.GetProperty("Created");
var sAssetNum = "";//CMI<defect#DBUNG00001108> we need dispaly Asset # in message<added by jj638 on 28july2011>
var bNoMeasurement = false;
if( sMeasurementType == "") bNoMeasurement = true;
var bNoAsset = false;
var bNoSR = false;
if(sAssetId == "") bNoAsset = true;
if(sSRNum == "") bNoSR = true;
var boAction = TheApplication().GetBusObject("Action");
var bcAction = boAction.GetBusComp("Action");
with (bcAction)
{
ActivateField("CMI SN Confirmed Flag");
ActivateField("Status");//CMI <Release# 2 - DBU>, C&I# 4454 <Configuration>: < \ Create a field defect# 109> By <jr428> On <12/07/2010>
ActivateField("CMI Done Flag");//CMI <Release# 2 - DBU>, C&I# 4454 <Configuration>: < \ Create a field defect# 109> By <jr428> On <12/07/2010>
ActivateField("Asset Number");//CMI<defect#DBUNG00001108> we need dispaly Asset # in message<added by jj638 on 28july2011>
ClearToQuery();
SetSearchSpec("Id",sActionId);
ExecuteQuery(ForwardOnly)
if(FirstRecord())
{
sAssetNum = GetFieldValue("Asset Number");//CMI<defect#DBUNG00001108> we need dispaly Asset # in message<added by jj638 on 28july2011>
//wirte tracker
var bcTimeTracker = boAction.GetBusComp("Time Sheet Unassoc Daily Hours");
// SetFieldValue("Status",sStatus);//CMI <Release# 2 - DBU>, C&I# 4454 <Configuration>: < \ Create a field defect# 109> By <jr428> On <12/07/2010>
if(sStatus == "Done")
{
SetFieldValue("CMI Done Flag","Y");//CMI <Release# 2 - DBU>, C&I# 4454 <Configuration>: < \ Create a field defect# 109> By <jr428> On <12/07/2010>
}
if (sConfirmFlag != "")
SetFieldValue("CMI SN Confirmed Flag",sConfirmFlag);
//write reading if confirmed
//we can not locate messurement type from action, remove sMeasurementType condition and use the first Measurement Type
//if(sMeasurementType != "" && sReading != "" && sConfirmFlag == "Y" )
if(sReading != "" && sConfirmFlag == "Y" && !bNoSR && !bNoAsset &&!bNoMeasurement)
{
var boAsset = TheApplication().GetBusObject("Asset Management");
var bcAsset = boAsset.GetBusComp("Asset Mgmt - Asset");
with(bcAsset)
{
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Id", sAssetId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var bcMeasurement = boAsset.GetBusComp("FS Asset Measurement Characteristics");
with(bcMeasurement)
{
ClearToQuery();
//SetSearchSpec("Measurement Type Code",sMeasurementType);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var bcReading = boAsset.GetBusComp("FS Asset Reading");
with(bcReading)
{
ClearToQuery();
NewRecord(NewAfter);
SetFieldValue("Reading",sReading);
WriteRecord();
}
}
else // could not find measurement
{
bNoMeasurement = true;
}
}
}
else
{
bNoAsset = true;
}
}
}
//write note to sr if not confirmed
if(((sConfirmFlag != "Y" && sSRNum != "" && sReading != "" ) || bNoMeasurement || bNoAsset || bNoSR) && (sConfirmFlag == "Y" || sSerialInput!="" ) )
{
var boSR = TheApplication().GetBusObject("Service Request");
var bcSR = boSR.GetBusComp("Service Request");
with(bcSR)
{
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("SR Number",sSRNum);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var bcNote = boSR.GetBusComp("FIN Service Request Notes");
with(bcNote)
{
NewRecord(NewBefore);
try
{
SetFieldValue("Note Type", TheApplication().InvokeMethod("LookupValue","FS_NOTE_TYPE","Technician Summary"));
}
catch(e)
{
//picklist constrain
}
//if(bNoSR) SetFieldValue("Note","No Service Request exists for the job. Reading:" + sReading);
if(bNoAsset) SetFieldValue("Note","Asset Serial # "+sAssetSerialNum+" does not exist in system. Serial # "+sAssetSerialNum+" entered by Tech: "+sSerialInput+", Reading: " + sReading);
//CMI<defect#DBUNG00001108> we need dispaly Serial # in message<added by jj638 on 28july2011>
else if(sConfirmFlag!="Y")
{
SetFieldValue("Note","Asset Serial # "+sAssetSerialNum+" does not match with Serial Number entered by Tech - "+sSerialInput+". Reading:" + sReading); //CMI <Release# 2 - DBU>, C&I# 4454 <Configuration>: < \ Added for formatting the Note Display Message for defect# 512> By <jc792> On <3 Jan 2011>.
if(bNoMeasurement)
{
NewRecord(NewBeforeCopy);
//CMI<defect#DBUNG00001108> we need dispaly Serial # and Asset# in message<added by jj638 on 28july2011>
SetFieldValue("Note","Measurement type does not exist for Asset # "+sAssetNum+" having Serial # "+sAssetSerialNum+".");
}
} //CMI<defect#DBUNG00001108> we need dispaly Serial # and Asset# in message<added by jj638 on 28july2011>
else if(bNoMeasurement) SetFieldValue("Note","Measurement type does not exist for Asset # "+sAssetNum+" having Serial # "+sAssetSerialNum+".");
else SetFieldValue("Note", "Other error");
WriteRecord();
}
}
}
}
//Tiger: create expense tracker
if(TheApplication().GetProfileAttr("CMIMileageRequired") == "Y")
{
var bcExpTrkr = boAction.GetBusComp("FS Expense Item");
with(bcExpTrkr)
{
NewRecord(NewAfter);
if(sDistanceType == TheApplication().InvokeMethod("LookupValue","LOY_UOM_CD", "MIL")) //miles
SetFieldValue("Expense Item Type Name", TheApplication().InvokeMethod("LookupValue", "EXP_ITEM_TYPE", "Mileage - Miles"));
else
SetFieldValue("Expense Item Type Name", TheApplication().InvokeMethod("LookupValue", "EXP_ITEM_TYPE", "Mileage - Km"));
SetFieldValue("Quantity", sDistance);
WriteRecord();
}
}
WriteRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally{
bcExpTrkr = null;
bcNote = null;
boAction = null;
bcAction = null;
bcAsset = null;
boAsset = null;
bcSR = null;
boSR = null;
bcTimeTracker = null; //Added by jw920 on 21-08-11 <Code Clean UP Process>
bcMeasurement = null;//Added by jw920 on 21-08-11 <Code Clean UP Process>
bcReading = null; //Added by jw920 on 21-08-11 <Code Clean UP Process>
TheApplication().Utility.logUnstack();
}
}

CMI Daily Work InTask BS
(declarations)
var sActivityPlanActionId:String; //Added by ki795 for Internal Bug # 77

CMI Daily Work InTask BS
NonBillableJob
/*********************************************************
Created By : JF344
Created On : 11-Nov-2010
C&I Number : 4468
Requirement # :
Method Name: NonBollableJOb
Functionality: For get some information about login
Input: None
Output: None
Customization Approval #: NA
*********************************************************/
function NonBillableJob(Inputs,Outputs)
{
// process non billable job branch
try {
TheApplication().Utility.logStack("NonBillableJob", this);
var sLastTimeSheetId = Inputs.GetProperty("Last Time Sheet Id"); //remain the id of last started time sheet record.
var sActionId = Inputs.GetProperty("Action Id");
var sStatus = Inputs.GetProperty("Status");
var sComments = Inputs.GetProperty("Comments");
var sStartTime = Inputs.GetProperty("Start Time");
var sEndTime = Inputs.GetProperty("End Time");
var sSheetComments = "";
var sJobStatus = "";
var boAction:BusObject = TheApplication().GetBusObject("Action");
var bcAction:BusComp = boAction.GetBusComp("Action");
var bcTimeSheet:BusComp;
if(sStatus == TheApplication().InvokeMethod("LookupValue","CMI_DAILY_JOB_STATUS","Job Started"))
sJobStatus = "Start";
else sJobStatus = "End";
with (bcAction)
{
ClearToQuery();
SetSearchSpec("Id",sActionId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
bcTimeSheet = boAction.GetBusComp("Time Sheet Unassoc Daily Hours");
with (bcTimeSheet)
{
ActivateField("Item Date");
ActivateField("External Comments");
if(sJobStatus == "Start")
{
NewRecord(NewAfter);
SetFieldValue("Project","Work");//set default work type
//SetFieldValue("Start Time", sStartTime);
SetFieldValue("External Comments",sComments);
SetFieldValue("Item Date",sStartTime);
}
else if(sJobStatus == "End")
{
ClearToQuery();
//SetSearchSpec("Id",sLastTimeSheetId);
SetSearchExpr("[Activity Id] = '"+ sActionId + "' AND [End Time] is null");
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
SetFieldValue("End Time",sEndTime);
sSheetComments = GetFieldValue("External Comments");
if(sComments != "" && sSheetComments != "")
sComments = sSheetComments + "\n" + TheApplication().LoginName() +": " + sComments;
else if(sComments == "")
sComments = sSheetComments;
else if(sSheetComments == "")
sComments = TheApplication().LoginName() +": " + sComments;
SetFieldValue("External Comments",sComments);
SetFieldValue("Item Date",sStartTime);
}
}
WriteRecord();
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcTimeSheet = null;
bcAction = null;
boAction = null;
TheApplication().Utility.logUnstack();
}
}

CMI Daily Work InTask BS
IsJobDone
/*
Created By : JF344
Created On : 10-Jan-11
C&I Number : 4468
Requirement # :
Method Name: IsJobDone
Functionality:
Input: None
Output: None
Customization Approval #: NA
*/
function IsJobDone(Inputs,Outputs)
{
try
{
Outputs.SetProperty("DoneFlag","Y"); //set default
var sActionId = Inputs.GetProperty("ActionId");
if(sActionId != "") //logic modified by saurabh
{
return;
}
var bcSheet = TheApplication().GetBusObject("Time Sheet Item").GetBusComp("Time Sheet Unassoc Daily Hours");
with (bcSheet)
{
ClearToQuery();
ActivateField("CMI Activity Type");
SetViewMode(PersonalView);
var sExpr = "[End Time] is null AND [Activity Id] ='"+ sActionId +"'";
SetSearchExpr(sExpr);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
Outputs.SetProperty("DoneFlag","N");
}
}
}
catch(e)
{
//bcSheet = null;//removed by saurabh
var err = e.toString();
TheApplication().RaiseErrorText(err);//added by jj638 on 25 May2011
}finally{
sActionId = null;//added by jj638 on 25 May2011
bcSheet = null;//added by jj638 on 25 May2011
}
}

CMI Daily Work InTask BS
GetCurrentTime
function GetCurrentTime(strTime)
{
/*********************************************************
AUTHOR: JR429
Purpose: This function is used for transfer the time format to MM/DD/YY HH/MM/SS.
INPUTS:
OUTPUTS: None
DATE CREATED: 13/Jan/2011
UPDATES:
*********************************************************/
try{
var v_Time = strTime;
var sMonth = ToString(v_Time.getMonth() + 1);
if (sMonth.length == 1)
sMonth = "0" + sMonth;
var sDay = ToString(v_Time.getDate());
if (sDay.length == 1)
sDay = "0" + sDay;
var sHours = ToString(v_Time.getHours());
if (sHours.length == 1)
sHours = "0" + sHours;
var sMinutes = ToString(v_Time.getMinutes());
if (sMinutes.length == 1)
sMinutes = "0" + sMinutes;
var sSeconds = ToString(v_Time.getSeconds());
if (sSeconds.length == 1)
sSeconds = "0" + sSeconds;
var v_TimeStr;
v_TimeStr = sMonth +"/"+ sDay +"/" + v_Time.getFullYear() + " " + sHours+":"+sMinutes+":"+sSeconds;
v_Time = null;
}catch(e){
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally{}
return v_TimeStr;
}

CMI Daily Work InTask BS
DailyClock
/*
Created By : JF344
Created On : 10-Jan-2011
C&I Number : 4468
Requirement # :
Method Name: DailyClock
Functionality:
Input: None
Output: None
Customization Approval #: NA
*/
function DailyClock(Inputs,Outputs)
{
try
{
//Create time sheet records and associate with Daily Clock Activity
var sFullname = TheApplication().GetProfileAttr("Full Name");
var sStatus = Inputs.GetProperty("Status");
var sStartTime = Inputs.GetProperty("Start Time");
var sEndTime = Inputs.GetProperty("End Time");
var sPayRollId;
var sActionType = TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Payroll");
var bcActPayroll = TheApplication().GetBusObject("Action").GetBusComp("Action");
var bcActTimeTracker = TheApplication().GetBusObject("Action").GetBusComp("Time Sheet Daily Hours");
var sTaskWF;
var InputPS;
var OutputPS;
var sCreated;
var sStartTimeStr1 = new Date(sStartTime);
var sStartTimeStr = GetCurrentTime(sStartTimeStr1);
if(sEndTime != "" && sEndTime != null)
{
var sEndTimeStr1 = new Date(sEndTime);
var sEndTimeStr = GetCurrentTime(sEndTimeStr1);
}
if(sStatus == TheApplication().InvokeMethod("LookupValue","CMI_DAILY_CLOCK_STATUS","Start Day"))
{
sTaskWF = TheApplication().GetService("Workflow Process Manager");
InputPS = TheApplication().NewPropertySet();
OutputPS = TheApplication().NewPropertySet();
InputPS.SetProperty("ProcessName", "CMI Task Payroll Time Tracker Process");
InputPS.SetProperty("Operation", "Create");
InputPS.SetProperty("Object Id", TheApplication().LoginId());
InputPS.SetProperty("CMI Date", sStartTimeStr);
//InputPS.SetProperty("Task Start Time", sStartTimeStr);
sTaskWF.InvokeMethod("RunProcess", InputPS, OutputPS);
sCreated = OutputPS.GetProperty("Operation Status");
if (sCreated == "Record Present")
{
TheApplication().RaiseErrorText("You have already clocked in. Please clock out for next clock in.");
}
else if(sCreated == "Failed")
{
TheApplication().RaiseErrorText("Error Creating Activity. Please contact Siebel Administrator");
}
}
if(sStatus == TheApplication().InvokeMethod("LookupValue","CMI_DAILY_CLOCK_STATUS","End Day"))
{
sTaskWF = TheApplication().GetService("Workflow Process Manager");
InputPS = TheApplication().NewPropertySet();
OutputPS = TheApplication().NewPropertySet();
InputPS.SetProperty("ProcessName", "CMI Task Payroll Time Tracker Process");
InputPS.SetProperty("Operation", "End Job");
InputPS.SetProperty("Object Id", TheApplication().LoginId());
InputPS.SetProperty("CMI Date", sStartTimeStr);
//InputPS.SetProperty("Task Start Time", sStartTimeStr);
sTaskWF.InvokeMethod("RunProcess", InputPS, OutputPS);
sCreated = OutputPS.GetProperty("Operation Status");
if (sCreated == "Record Present")
{
TheApplication().RaiseErrorText("You have already clocked in. Please clock out for next clock in.");
}
else if(sCreated == "Failed")
{
TheApplication().RaiseErrorText("Error Creating Activity. Please contact Siebel Administrator");
}
}
}
catch(e)
{
throw(e);
}
finally
{
bcActPayroll = null;
bcActTimeTracker = null;
sTaskWF = null;
InputPS = null;
OutputPS = null;
}
}
//Start Job Code commenting
/*with(bcActPayroll)
{
//ActivateField("Done");
ActivateField("Planned");
ActivateField("Activity Id");
SetSearchExpr("[Type] = '" + sActionType +"' AND [Done] is null AND [CMI Owner FullName] ='" + sFullname +"'");
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sPayRollId = GetFieldValue("Id");
var TestA = GetFieldValue("CMI Owner FullName");
with(bcActTimeTracker)
{
ActivateField("Start Time");
ActivateField("Item Date");
ActivateField("Activity Id");
ActivateField("Project");
SetSearchSpec("Activity Id", sPayRollId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
TheApplication().RaiseErrorText("You have already clocked in. Please clock out for next clock in.");
}
else
{
NewRecord(NewAfter);
SetFieldValue("Item Date", sStartTimeStr);
SetFieldValue("Start Time", sStartTimeStr);
SetFieldValue("Owner Login", TheApplication().GetProfileAttr("Login Name")); //Added by ki795 as part of internal Bug # 77
SetFieldValue("Activity Id", sPayRollId);
SetFieldValue("Project", "Daily Clock");
WriteRecord();
}
}
}
else
{
//C&I 4559 Commented below code by ki795 on 20-Sep-2011
/*NewRecord(NewAfter);
SetFieldValue("Category",sActionType); //Added by ki795 as part of internal bug # 77
SetFieldValue("Type", sActionType);
SetFieldValue("Planned",sStartTimeStr);
//SetFieldValue("Status", "In Progress"); //Modified by ki795 as part of internal bug # 77
WriteRecord();
sPayRollId = GetFieldValue("Id");*/
//C&I 4559 Added new function to create payroll activity for given user by ki795 on 20-Sep-2011
/* CreateActivity(TheApplication().GetProfileAttr("Login Name"));
sPayRollId = sActivityPlanActionId;
if (sActivityPlanActionId == null || sActivityPlanActionId == "")
{
TheApplication().RaiseErrorText("Error Creating Activity. Please contact Siebel Administrator");
}
//End of changes by ki795 for 4559
with(bcActTimeTracker)
{
ActivateField("Start Time");
ActivateField("Item Date");
ActivateField("Activity Id");
ActivateField("Project");
NewRecord(NewAfter);
SetFieldValue("Item Date", sStartTimeStr);
SetFieldValue("Start Time", sStartTimeStr);
SetFieldValue("Owner Login", TheApplication().GetProfileAttr("Login Name")); //Added by ki795 as part of internal Bug # 77
SetFieldValue("Activity Id", sPayRollId);
SetFieldValue("Project", "Daily Clock");
WriteRecord();
}
}
}*/
//End Job Code Commenting
/*with(bcActPayroll)
{
SetViewMode(AllView);
SetSearchExpr("[Type] = '" + sActionType +"' AND [Done] is null AND [CMI Owner FullName] ='" + sFullname +"'");
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sPayRollId = GetFieldValue("Id");
}
with(bcActTimeTracker)
{
SetViewMode(AllView);
ActivateField("End Time");
ActivateField("Item Date");
ActivateField("Activity Id");
ClearToQuery();
SetSearchExpr("[End Time] is null AND [Owner Id] ='" + TheApplication().LoginId() +"' AND [Activity Id] = '" + sPayRollId +"'" );
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
SetFieldValue("Item Date", sEndTimeStr);
SetFieldValue("End Time", sEndTimeStr);
SetFieldValue("Activity Id", sPayRollId);
WriteRecord();
}
else
{
TheApplication().RaiseErrorText("You have already clocked out. Please clock in for next clock out.");
}
}
//SetFieldValue("Done", sEndTimeStr);
//WriteRecord();
}*/

CMI Daily Work InTask BS
CreateTimeSheetItem
function CreateTimeSheetItem(Inputs, Outputs) {
try {
//Creates a timesheet item record. WF Cannot set fields in a specific order
//so record creation may fail when there is field level validation or
//hierarchical picklists.
TheApplication().Utility.logStack("CreateTimeSheetItem", this);
var boAction:BusObject = TheApplication().GetBusObject("Action");
var bcAction:BusComp = boAction.GetBusComp("Action");
var bcTimeSheet:BusComp = boAction.GetBusComp("Time Sheet Daily Hours");
var aDateTime = new Array();;
with (bcAction) {
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Id", Inputs.GetProperty("Activity Id"));
ExecuteQuery(ForwardOnly);
var found = FirstRecord();
TheApplication().Utility.logVars("Activity ("+Inputs.GetProperty("Activity Id")+") Found?", found);
if (found) {
with (bcTimeSheet) {
NewRecord(NewAfter);
if (Inputs.GetProperty("Owner Id") != "") SetFieldValue("Owner Id", Inputs.GetProperty("Owner Id"));
if (Inputs.GetProperty("Start Time") != "") {
TheApplication().Utility.logVars("Default Start Time", GetFieldValue("Start Time"));
SetFieldValue("Start Time", Inputs.GetProperty("Start Time"));
}
if (Inputs.GetProperty("End Time") != "") {
TheApplication().Utility.logVars("Default End Time", GetFieldValue("End Time"));
SetFieldValue("End Time", Inputs.GetProperty("End Time"));
}
if (Inputs.GetProperty("Project") != "") SetFieldValue("Project", Inputs.GetProperty("Project"));
if (Inputs.GetProperty("Item Date") != "") SetFieldValue("Item Date", Inputs.GetProperty("Item Date"));
WriteRecord();
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcTimeSheet = null;
bcAction = null;
boAction = null;
TheApplication().Utility.logUnstack();
}
}

CMI Daily Work InTask BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//Added try catch block by jw920 , on 21-082011 <Code Clean up Process>
try
{
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
switch (MethodName) {
case "DailyClock":
DailyClock(Inputs,Outputs);
break;
case "CreatePayrollActivity":
//C&I 4559 Added new method to create payroll activity for given user by ki795 on 20-Sep-2011
var sLogin:String = Inputs.GetProperty("Login Id");
var sStartDate:Date = Inputs.GetProperty("Planned Start");
var sEndDate:Date = Inputs.GetProperty("Planned End");
CreateActivity(sLogin,sStartDate,sEndDate);
Outputs.SetProperty("Activity Id",sActivityPlanActionId);
break;
//End of changes for C&I 4559 by ki795
case "CreateTimeSheetItem":
CreateTimeSheetItem(Inputs,Outputs);
break;
case "BillableJob":
BillableJob(Inputs,Outputs);
break;
case "IsJobDone":
IsJobDone(Inputs,Outputs);
break;
case "ClearBillableJob":
ClearBillableJob(Inputs,Outputs);
break;
case "ClearNonBillableJob":
ClearNonBillableJob(Inputs,Outputs);
break;
case "ClearDailyClock":
ClearDailyClock(Inputs,Outputs);
break;
case "CheckUndoneJob":
CheckUndoneJob(Inputs,Outputs);
break;
case "NonBillableJob":
NonBillableJob(Inputs,Outputs);
break;
case "CheckDailyClockIn":
CheckDailyClockIn(Inputs,Outputs);
break;
default:
retVal = ContinueOperation;
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Daily Work InTask BS
ClearNonBillableJob
/*
Created By : JF344
Created On : 25-Jan-2011
C&I Number : 4468
Requirement # :
Method Name: ClearDailyClock
Functionality:
Input: None
Output: None
Customization Approval #: NA
*/
function ClearNonBillableJob(Inputs, Outputs)
{
try
{
var bcNonBillable = TheApplication().ActiveBusObject().GetBusComp("CMI Non Billable Job Option");
if(bcNonBillable != "" && bcNonBillable.FirstRecord())
{
with(bcNonBillable)
{
if(GetFieldValue("End Time") != "")
{
//SetFieldValue("RO Control", "N");
SetFieldValue("Comments","");
SetFieldValue("End Time","");
SetFieldValue("Start Time","");
SetFieldValue("Status","");
// SetFieldValue("RO Control", "N");
WriteRecord();
}
}
}
}
catch(e)
{
var err=e.toString()
}
finally
{
bcNonBillable = null;
}
}

CMI Daily Work InTask BS
ClearDailyClock
/*
Created By : JF344
Created On : 25-Jan-2011
C&I Number : 4468
Requirement # :
Method Name: ClearDailyClock
Functionality:
Input: None
Output: None
Customization Approval #: NA
*/
function ClearDailyClock(Inputs, Outputs)
{
try
{
var bcClock = TheApplication().ActiveBusObject().GetBusComp("CMI Daily Clock");
if(bcClock != "" && bcClock.FirstRecord())
{
with(bcClock)
{
if(GetFieldValue("End Time") != "")
{
SetFieldValue("Status","");
SetFieldValue("End Time","");
SetFieldValue("Start Time","");
WriteRecord();
}
}
}
}
catch(e)
{
var err=e.toString()
}
finally
{
bcClock = null;
}
}

CMI Daily Work InTask BS
ClearBillableJob
/*
Created By : Rachel-Zang
Created On : 25-Jan-2011
C&I Number : 4468
Requirement # :
Method Name: ClearBillableJob
Functionality:
Input: None
Output: None
Customization Approval #: NA
*/
function ClearBillableJob(Inputs, Outputs)
{
try
{
var bcBillable = TheApplication().ActiveBusObject().GetBusComp("CMI Billable Job Option");
if(bcBillable != "")
{
with(bcBillable)
{
if(FirstRecord())
{
var sDistance = GetFieldValue("Distance");//CMI<defect#DBUNG00001107> Added to bypass setfield value of Distance<added by jr426 on 26july2011>
var sDistanceType = GetFieldValue("Distance Type");//CMI<defect#DBUNG00001107> Added to bypass setfield value of Distance<added by jr426 on 26july2011>
//SetFieldValue("Confirm SN Flag","");//commetted by woody for defect 309
SetFieldValue("Expense Flag","");
SetFieldValue("Interview Flag","");
SetFieldValue("Note Flag","");
SetFieldValue("Parts Tracker Flag","");
SetFieldValue("Repair Plan Flag","");
//SetFieldValue("Reading","");//commetted by woody for defect 309
//SetFieldValue("Serial # Entry","");//commetted by woody for defect 309
//if Distance is required field this time, need to clear the control profile
TheApplication().SetProfileAttr("CMIMileageRequired", "N");
if(sDistance != "" || sDistanceType != "" )//CMI<defect#DBUNG00001107> Added to bypass setfield value of Distance<added by jr426 on 26july2011>
{//CMI<defect#DBUNG00001107> Added to bypass setfield value of Distance<added by jr426 on 26july2011>
SetFieldValue("Distance","");
SetFieldValue("Distance Type","");
} //CMI<defect#DBUNG00001107> Added to bypass setfield value of Distance<added by jr426 on 26july2011>
SetFieldValue("RO Control", "N");
WriteRecord();
}
}
}
}
catch(e)
{
var err=e.toString();
TheApplication().RaiseErrorText(err);
}finally{
bcBillable = null;//addded by jj638 on 25 may2011
}
}

CMI Daily Work InTask BS
CheckUndoneJob
/*********************************************************
Created By : JF344
Created On : 28-Dec-2010
C&I Number : 4468
Requirement # :
Method Name: BusComp_NewRecord
Functionality: For get some information about login
Input: None
Output: None
Customization Approval #: NA
*********************************************************/
function CheckUndoneJob(Inputs, Outputs)
{
try{
TheApplication().Utility.logStack("CheckUndoneJob", this);
var sLoginId = TheApplication().LoginId();
var bBillable = Inputs.GetProperty("Billable"); //added by lq305
var sExpr = "";
var sActionId = "";
var bcSheet = TheApplication().GetBusObject("Time Sheet Item").GetBusComp("Time Sheet Unassoc Daily Hours");
var sActionType = "";
//when billable is N, query for non billable job
//when billable is Y, query for billable job
//when billable is "", query for both starting with non billable.
TheApplication().Utility.logVars("Billable", bBillable);
if( bBillable == "N" || bBillable =="") {
//CMI DBU: CQ Defect#3218, by KS988 on 19Jan 2012---changed the searc spec
//sExpr = "[CMI Activity Owner Id] = '" +sLoginId +"' AND [End Time] is null AND [Activity Id] is not null AND ([CMI Activity Status] ='Scheduled' OR [CMI Activity Status] = 'In Progress') AND ([CMI Activity Category] = 'Training' or [CMI Activity Category] = 'Internal' or [CMI Activity Category] = 'Admin' or [CMI Activity Category] = 'Supervision')";
sExpr = "[End Time] is null AND [Activity Id] is not null AND ([CMI Activity Status] ='Scheduled' OR [CMI Activity Status] = 'In Progress') AND ([CMI Activity Category] = 'Training' or [CMI Activity Category] = 'Internal' or [CMI Activity Category] = 'Admin' or [CMI Activity Category] = 'Supervision')";
//[CMI Activity Emp Id] = '" +sLoginId +"' AND -> commented out as no need to check act owner.. only TT owner is fine
// No need to use Owner Id as using PersonalView mode
with (bcSheet) {
ClearToQuery();
ActivateField("CMI Activity Type");
SetViewMode(PersonalView);
SetSearchExpr(sExpr);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Open Non Billable Time for Login Id ("+sLoginId+") found?", FirstRecord());
if(FirstRecord()) {
sActionId = GetFieldValue("Activity Id");
sActionType = GetFieldValue("CMI Activity Type");
Outputs.SetProperty("ActionId",sActionId);
Outputs.SetProperty("Billable","N");
Outputs.SetProperty("ActionType",sActionType);
}
}
}
if((bBillable == "Y" || bBillable == "" )&& sActionId == "" ) {
//use the same rule as non billable activity: if End Time is null, then the activity is not done yet.
sExpr = "[CMI Activity Type] ='Service Labor' AND [CMI Activity Owner Id] = '" +sLoginId +"' AND [End Time] is null AND [Activity Id] is not null AND [CMI Activity Status] <> 'Done' AND [CMI Activity Status] <> 'Unscheduled' AND [CMI Activity Status] <> 'Completed' AND [CMI Activity Status] <> 'Cancelled' AND [CMI Activity Status] <> 'Closed'";
with (bcSheet) {
ClearToQuery();
ActivateField("CMI Activity Type");
SetSearchExpr(sExpr);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Open Billable Time for Login Id ("+sLoginId+") found?", FirstRecord());
if(FirstRecord()) {
sActionId = GetFieldValue("Activity Id");
sActionType = GetFieldValue("CMI Activity Type");
Outputs.SetProperty("ActionId",sActionId);
Outputs.SetProperty("Billable","Y");
Outputs.SetProperty("ActionType",sActionType);
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcSheet = null;
if (sActionId != "") TheApplication().Utility.logId("Action", sActionId);
TheApplication().Utility.logUnstack();
}
}

CMI Daily Work InTask BS
CheckDailyClockIn
function CheckDailyClockIn(Inputs,Outputs)
{
try
{
var sTaskWF = TheApplication().GetService("Workflow Process Manager");
var InputPS = TheApplication().NewPropertySet();
var OutputPS = TheApplication().NewPropertySet();
InputPS.SetProperty("ProcessName", "CMI Task Payroll Time Tracker Process");
InputPS.SetProperty("Operation", "Validate");
InputPS.SetProperty("Object Id", TheApplication().LoginId());
sTaskWF.InvokeMethod("RunProcess", InputPS, OutputPS);
var sCreated = OutputPS.GetProperty("CMI Clocked In");
if (sCreated == "Y")
{
Outputs.SetProperty("ClockedInFlag","Y");
var sStartDate = OutputPS.GetProperty("Task Start Date");
var sStartDateTime = sStartDate + " " + OutputPS.GetProperty("Task Start Time");
Outputs.SetProperty("StartDateTime", sStartDateTime);
}
else
{
Outputs.SetProperty("ClockedInFlag","N");
Outputs.SetProperty("hasRecord","1");
}
} catch(e) {
throw(e);
} finally {
sTaskWF = null;
InputPS = null;
OutputPS = null;
}
}

CMI Daily Work InTask BS
CreateActivity
/*******************************************************************************************
Created By :<Arun Chellathurai>
Created On : <09/20/2011>
Method Name:CreateActivity(sLogin)
C&I Number:
Requirement #:
Functionality: Creates a payroll activity for a given login
Input: Login Name ex:- 1-X987Y, Planned Start - 09/30/2011, Planned End -- 10/15/2011
Output: Activity Id created as an global variable - Activity Id
****************************************************************************************** */
function CreateActivity(sLogin,sStartDate,sEndDate)
{
try {
TheApplication().Utility.logStack("CreateActivity", this);
var oContactBusObj:BusObject = TheApplication().GetBusObject("Contact");
var oContactBusCom:BusComp = oContactBusObj.GetBusComp("Contact");
var oActionPlanBusComp:BusComp = oContactBusObj.GetBusComp("Activity Plan");
var oActionTempPickBusComp:BusComp = oActionPlanBusComp.GetPicklistBusComp("Template");
var oActionPlanActionBusComp:BusComp = oContactBusObj.GetBusComp("Activity Plan Action");
var sActivityPlanId:String;
var found;
var sCurRateId;
with (oContactBusCom) {
ActivateField("Primary Organization Id");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sLogin);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
var cDivId= oContactBusCom.GetFieldValue("Primary Organization Id");
TheApplication().Utility.logVars("Contact ("+sLogin+") Found?", found);
if(found) {
with(oActionPlanBusComp) {
// ActivateField("CMI Current Division Id");
NewRecord(NewAfter);
// var cDivId = GetFieldValue("CMI Current Division Id");
TheApplication().Utility.logVars("Division Code", cDivId);
with(oActionTempPickBusComp) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Name",TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Payroll"));
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
Pick();
}
}
var oDivBO:BusObject = TheApplication().GetBusObject("Internal Division");
var oDivBC:BusComp = oDivBO.GetBusComp("Internal Division");
with (oDivBC)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("CMI Rate List Id");
SetSearchSpec("Id",cDivId);
ExecuteQuery(ForwardOnly)
var isDivRec = FirstRecord();
if (isDivRec)
{
sCurRateId = GetFieldValue("CMI Rate List Id");
// this.SetFieldValue("CMI Rate List Id",sCurRateId);
}
}
SetFieldValue("Rate List Id",sCurRateId);
WriteRecord();
sActivityPlanId = GetFieldValue("Id");
// var RateId = GetFieldValue("Rate List Id")
}
TheApplication().Utility.logVars("Activity Plan Id + Rate List", sActivityPlanId+sCurRateId);
if (sActivityPlanId != "" && sActivityPlanId != null) {
with (oActionPlanActionBusComp) {
SetViewMode(AllView);
ActivateField("Contact Full Name");
ActivateField("CMI Owner FullName");
ActivateField("Primary Owner Id");
ClearToQuery();
SetSearchSpec("Parent Activity Id",sActivityPlanId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Activity Found?", found);
if(found) {
SetFieldValue("CMI Owner FullName", GetFieldValue("Contact Full Name"));
SetFieldValue("Primary Owner Id",sLogin);
SetFieldValue("Planned",sStartDate);
SetFieldValue("Planned Completion",sEndDate);
SetFieldValue("CMI Rate List Id", sCurRateId);
WriteRecord();
sActivityPlanActionId = GetFieldValue("Id");
TheApplication().Utility.logVars("Activity Found?", sActivityPlanActionId);
}
}
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oContactBusObj = null;
oContactBusCom = null;
oActionPlanBusComp = null;
oActionTempPickBusComp = null;
oActionPlanActionBusComp = null;
TheApplication().Utility.logUnstack(sActivityPlanActionId);
}
}

CMI Daily Work Task BS
CheckUndoneJob
/*********************************************************
Created By : JF344
Created On : 28-Dec-2010
C&I Number : 4468
Requirement # :
Method Name: BusComp_NewRecord
Functionality: For get some information about login
Input: None
Output: None
Customization Approval #: NA
*********************************************************/
function CheckUndoneJob(Inputs, Outputs)
{
try{
TheApplication().Utility.logStack("CheckUndoneJob", this);
var sLoginId = TheApplication().LoginId();
var bBillable = Inputs.GetProperty("Billable"); //added by lq305
var sExpr = "";
var sActionId = "";
var bcSheet = TheApplication().GetBusObject("Time Sheet Item").GetBusComp("Time Sheet Unassoc Daily Hours");
var sActionType = "";
//when billable is N, query for non billable job
//when billable is Y, query for billable job
//when billable is "", query for both starting with non billable.
TheApplication().Utility.logVars("Billable", bBillable);
if( bBillable == "N" || bBillable =="") {
//CMI DBU: CQ Defect#3218, by KS988 on 19Jan 2012---changed the searc spec
//sExpr = "[CMI Activity Owner Id] = '" +sLoginId +"' AND [End Time] is null AND [Activity Id] is not null AND ([CMI Activity Status] ='Scheduled' OR [CMI Activity Status] = 'In Progress') AND ([CMI Activity Category] = 'Training' or [CMI Activity Category] = 'Internal' or [CMI Activity Category] = 'Admin' or [CMI Activity Category] = 'Supervision')";
sExpr = "[End Time] is null AND [Activity Id] is not null AND ([CMI Activity Status] ='Scheduled' OR [CMI Activity Status] = 'In Progress') AND ([CMI Activity Category] = 'Training' or [CMI Activity Category] = 'Internal' or [CMI Activity Category] = 'Admin' or [CMI Activity Category] = 'Supervision')";
//[CMI Activity Owner Id] = '" +sLoginId +"' AND -> commented out as no need to check act owner.. only TT owner is fine
// No need to use Owner Id as using PersonalView mode
with (bcSheet) {
ClearToQuery();
ActivateField("CMI Activity Type");
SetViewMode(PersonalView);
SetSearchExpr(sExpr);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Open Non Billable Time for Login Id ("+sLoginId+") found?", FirstRecord());
if(FirstRecord()) {
sActionId = GetFieldValue("Activity Id");
sActionType = GetFieldValue("CMI Activity Type");
Outputs.SetProperty("ActionId",sActionId);
Outputs.SetProperty("Billable","N");
Outputs.SetProperty("ActionType",sActionType);
}
}
}
if((bBillable == "Y" || bBillable == "" )&& sActionId == "" ) {
//use the same rule as non billable activity: if End Time is null, then the activity is not done yet.
sExpr = "[CMI Activity Type] ='Service Labor' AND [CMI Activity Owner Id] = '" +sLoginId +"' AND [End Time] is null AND [Activity Id] is not null AND [CMI Activity Status] <> 'Done' AND [CMI Activity Status] <> 'Unscheduled' AND [CMI Activity Status] <> 'Completed' AND [CMI Activity Status] <> 'Cancelled' AND [CMI Activity Status] <> 'Closed'";
with (bcSheet) {
ClearToQuery();
ActivateField("CMI Activity Type");
SetSearchExpr(sExpr);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Open Billable Time for Login Id ("+sLoginId+") found?", FirstRecord());
if(FirstRecord()) {
sActionId = GetFieldValue("Activity Id");
sActionType = GetFieldValue("CMI Activity Type");
Outputs.SetProperty("ActionId",sActionId);
Outputs.SetProperty("Billable","Y");
Outputs.SetProperty("ActionType",sActionType);
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcSheet = null;
if (sActionId != "") TheApplication().Utility.logId("Action", sActionId);
TheApplication().Utility.logUnstack();
}
}

CMI Daily Work Task BS
CheckDailyClockIn
function CheckDailyClockIn(Inputs,Outputs)
{
/*********************************************************
AUTHOR: JR429
Purpose: This function is used for check the person is Clock in,if the employee is not check in,can not do the job.
INPUTS:
OUTPUTS: None
DATE CREATED: 01/Jan/2011
UPDATES: Redesigned by ki795 on 22-Sep-2011 for having same logic all over Task based UI.
*********************************************************/
/*var bcTimeSheet = TheApplication().GetBusObject("Time Sheet Item").GetBusComp("Time Sheet Unassoc Daily Hours");
with(bcTimeSheet)
{
SetViewMode(PersonalView);
ClearToQuery();
//SetSearchExpr("[Activity Id] is null AND [End Time] is null AND [Start Time] is not null AND [Project] = 'Daily Clock'"); //commended by ki795 for Internal Bug # 77
SetSearchExpr("[End Time] is null AND [Start Time] is not null AND [Project] = 'Daily Clock'"); // Removed Activity Id from the SearchSpec by ki795 on 20-Sep
SetSortSpec("Created(DESC)");
ExecuteQuery(ForwardOnly);i need
if(!FirstRecord())//if found, retrive date from time sheet
{
Outputs.SetProperty("hasRecord","1"); // Tiger: can we change it to below logic?
Outputs.SetProperty("ClockedInFlag","N");
}
else
{
Outputs.SetProperty("ClockedInFlag","Y");
var sStartDateTime = GetFieldValue("Item Date") + " " + GetFieldValue("Start Time");
Outputs.SetProperty("StartDateTime", sStartDateTime);
}
}*/
try
{
var sTaskWF = TheApplication().GetService("Workflow Process Manager");
var InputPS = TheApplication().NewPropertySet();
var OutputPS = TheApplication().NewPropertySet();
InputPS.SetProperty("ProcessName", "CMI Task Payroll Time Tracker Process");
InputPS.SetProperty("Operation", "Validate");
InputPS.SetProperty("Object Id", TheApplication().LoginId());
sTaskWF.InvokeMethod("RunProcess", InputPS, OutputPS);
var sCreated = OutputPS.GetProperty("CMI Clocked In");
if (sCreated == "Y")
{
Outputs.SetProperty("ClockedInFlag","Y");
var sStartDate = OutputPS.GetProperty("Task Start Date");
var sStartDateTime = sStartDate + " " + OutputPS.GetProperty("Task Start Time");
Outputs.SetProperty("StartDateTime", sStartDateTime);
}
else
{
Outputs.SetProperty("ClockedInFlag","N");
Outputs.SetProperty("hasRecord","1");
}
}
catch(e)
{
throw(e);
}
/* var sFullname = TheApplication().GetProfileAttr("Full Name");
var sActionType = TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Payroll");
var bcActPayroll:BusComp = TheApplication().GetBusObject("Action").GetBusComp("Action");
var bcActTimeTracker:BusComp = TheApplication().GetBusObject("Action").GetBusComp("Time Sheet Daily Hours");
with(bcActPayroll)
{
ActivateField("Planned");
ActivateField("Activity Id");
SetSearchExpr("[Type] = '" + sActionType +"' AND [Done] is null AND [CMI Owner FullName] ='" + sFullname +"'");
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var sPayRollId = GetFieldValue("Id");
var TestA = GetFieldValue("CMI Owner FullName");
with(bcActTimeTracker)
{
ActivateField("Start Time");
ActivateField("Item Date");
ActivateField("Activity Id");
ActivateField("Project");
SetSearchExpr("[End Time] is null AND [Owner Id] ='" + TheApplication().LoginId() +"' AND [Activity Id] = '" + sPayRollId +"'" );
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var sStartDateTime = GetFieldValue("Item Date") + " " + GetFieldValue("Start Time");
Outputs.SetProperty("StartDateTime", sStartDateTime);
Outputs.SetProperty("ClockedInFlag","Y");
}
else
{
Outputs.SetProperty("ClockedInFlag","N");
Outputs.SetProperty("hasRecord","1");
}
}
}
else
{
Outputs.SetProperty("ClockedInFlag","N");
Outputs.SetProperty("hasRecord","1");
}
}*/
}
/* } //ki795 commented try catch block as preinvoke method has a try catch block on 23-Sep-2011
catch(e)
{//added by jj638 on 25 may2011
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally
{
bcActPayroll = null;
bcActTimeTracker = null;
}
}*/

CMI Daily Work Task BS
addToTimesheet
function addToTimesheet(sTimeTrackerId)
{
//added by lq305 - for TT entry association with Timesheet
if(sTimeTrackerId != "")
{
try{
var bsTimeTracker = TheApplication().GetService("CMI Time Tracker BS") ;
var psInputs = TheApplication().NewPropertySet()
var psOutputs = TheApplication().NewPropertySet()
psInputs.SetProperty("TimeTrackerId", sTimeTrackerId) ;
bsTimeTracker.InvokeMethod("CMIAssignTT", psInputs, psOutputs) ;
}
catch(e){
} finally {
if(defined(bsTimeTracker)) bsTimeTracker = null ;
if(defined(psInputs)) psInputs = null ;
if(defined(psOutputs)) psOutputs = null ;
}
}
}

CMI Daily Work Task BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//Try catch added by shanmukh for code clean up 08/20/2011
try
{
if(MethodName == "NonBillableJob")
{
NonBillableJob(Inputs,Outputs);
return (CancelOperation);
}
if(MethodName == "CheckUndoneJob")
{
CheckUndoneJob(Inputs,Outputs);
return (CancelOperation);
}
if(MethodName == "CheckDailyClockIn")
{
CheckDailyClockIn(Inputs,Outputs);
return (CancelOperation);
}
return (ContinueOperation);
}//end of try
catch(e)
{
throw(e);
}//end of catch
}

CMI Daily Work Task BS
Service_PreCanInvokeMethod
function Service_PreCanInvokeMethod (MethodName, &CanInvoke)
{
try
{
if(MethodName == "CheckDailyClockIn")
{
CanInvoke = "TRUE";
return (CancelOperation);
}
if(MethodName == "CheckUndoneJob")
{
CanInvoke = "TRUE";
return (CancelOperation);
}
if(MethodName == "NonBillableJob")
{
CanInvoke = "TRUE";
return (CancelOperation);
}
}//end of try
catch(e)
{
throw(e);
}
return (ContinueOperation);
}

CMI Daily Work Task BS
NonBillableJob
/*********************************************************
Created By : JF344
Created On : 11-Nov-2010
C&I Number : 4468
Requirement # :
Method Name: NonBollableJOb
Functionality: For get some information about login
Input: None
Output: None
Customization Approval #: NA
*********************************************************/
function NonBillableJob(Inputs,Outputs)
{
// process non billable job branch
try
{
var sLastTimeSheetId = Inputs.GetProperty("Last Time Sheet Id"); //remain the id of last started time sheet record.
var sActionId = Inputs.GetProperty("Action Id");
var sStatus = Inputs.GetProperty("Status");
var sComments = Inputs.GetProperty("Comments");
var sStartTime = Inputs.GetProperty("Start Time");
var sEndTime = Inputs.GetProperty("End Time");
var sSheetComments = "";
var sJobStatus = "";
if(sStatus == TheApplication().InvokeMethod("LookupValue","CMI_DAILY_JOB_STATUS","Job Started"))
sJobStatus = "Start";
else sJobStatus = "End";
if(sActionId != null && sActionId != "") //Added by KP194 for TAM review comment#5 on 02/06/2012
{
var boAction = TheApplication().GetBusObject("Action");
var bcAction = boAction.GetBusComp("Action");
with (bcAction)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sActionId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var bcTimeSheet = boAction.GetBusComp("Time Sheet Unassoc Daily Hours");
var sActivityType = bcAction.GetFieldValue("Type"); //lq305 - 7/16/2013
with (bcTimeSheet)
{
ActivateField("Item Date");
ActivateField("External Comments");
ActivateField("CMI Record Source");
if(sJobStatus == "Start")
{
NewRecord(NewAfter);
SetFieldValue("Project",sActivityType); //lq305 - 7/16/2013
//SetFieldValue("Project","Work");//set default work type
//SetFieldValue("Start Time", sStartTime);
SetFieldValue("CMI Record Source", "Task UI");
SetFieldValue("External Comments",sComments);
SetFieldValue("Item Date",sStartTime);
SetFieldValue("Owner Id",TheApplication().LoginId());
}
else if(sJobStatus == "End")
{
var sLoginId1 = TheApplication().LoginId();
SetViewMode(AllView);
ClearToQuery();
//SetSearchSpec("Id",sLastTimeSheetId);
SetSearchExpr("[Owner Id] = '"+ sLoginId1 + "' AND [End Time] is null");
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
SetFieldValue("End Time",sEndTime);
sSheetComments = GetFieldValue("External Comments");
if(sComments != "" && sSheetComments != "")
sComments = sSheetComments + " " + TheApplication().LoginName() +": " + sComments;
else if(sComments == "")
sComments = sSheetComments;
else if(sSheetComments == "")
sComments = TheApplication().LoginName() +": " + sComments;
SetFieldValue("External Comments",sComments);
SetFieldValue("Item Date",sStartTime);
SetFieldValue("Owner Id",TheApplication().LoginId());
}
}
WriteRecord();
//added by lq305 - for adding TT to TS - jul 14 2013
if(sJobStatus == "Start")
{
addToTimesheet(GetFieldValue("Id")) ;
}
}//end-with
}//end-if
}//end-with
} // end if
}//end-try
catch(e)
{
var err = e.toString();
TheApplication().RaiseErrorText(e.toString());
}
finally{
bcAction = null;
boAction = null;
bcTimeSheet = null;
}
}

CMI Default Labor Normal
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
// Add try catch block by jw920 ,on 21/08/11 <Code Clean Up Process>
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if(MethodName == "DefaultLaborNormal")
{
DefaultLaborNormal();
return(CancelOperation);
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Default Labor Normal
DefaultLaborNormal
//Added strong type declaration and changed the defaulting logic for Bug # DBUNG00001382 by ki795 on 27 Oct 2011
function DefaultLaborNormal()
{
try {
TheApplication().Utility.logStack("DefaultLaborNormal", this);
var boActive:BusObject = TheApplication().ActiveBusObject();
var bcLine:BusComp;
var process = true;
var viewName = TheApplication().GetProfileAttr("Me.ActiveViewName");
if (viewName == "CMI Labor Quote Line Item View") {
bcLine = boActive.GetBusComp("Quote Item");
} else if (viewName == "CMI Labor Order Entry - Line Item View") {
bcLine = boActive.GetBusComp("Order Entry - Line Items");
} else {
process = false;
}
if (process) {
var bcProduct:BusComp = bcLine.GetPicklistBusComp("Product");
var isRec;
with(bcProduct) {
SetViewMode(AllView);
SetNamedSearch("Applet Search Spec Named Search","");
ClearToQuery();
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor"));
SetSearchSpec("CMI Sub Type", TheApplication().InvokeMethod("LookupValue", "CMI_SUB_TYPE_LOV", "Labor"));
SetSearchSpec("Category", TheApplication().InvokeMethod("LookupValue", "PRODUCT_CATEGORY", "Default"));
ExecuteQuery(ForwardOnly);
isRec = FirstRecord();
if(isRec) {
Pick();
}
}
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
bcProduct = null;
bcLine = null;
boActive = null;
TheApplication().Utility.logUnstack();
}
}

CMI Default SRT Last Step
SetLastStepId
/*****************************************************************************************************************
Created By : jf344
Created On : 16-Dec-10
C&I Number : 4466
Requirement # :
Method Name: SetLastStepId
Functionality:
Input: None
Output: None
Customization Approval #: NA
******************************************************************************************************************/
function SetLastStepId(Inputs, Outputs)
{
try
{
var bcActiveSRT = TheApplication().ActiveBusObject().GetBusComp("CMI SRT");
var sActiveSRTId = bcActiveSRT.GetFieldValue("Id");
var sActiveLastNum = bcActiveSRT.GetFieldValue("CMI Last Step Cal");
var sStepId = "No Match Row Id";
var bcSRTStep = TheApplication().GetBusObject("CMI SRT").GetBusComp("CMI SRT Steps");
with(bcSRTStep)
{
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Header Id", sActiveSRTId);
SetSearchSpec("Step Num", sActiveLastNum);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sStepId = GetFieldValue("Id");
}
}
bcActiveSRT.SetFieldValue("Last Step Id", sStepId);
bcActiveSRT.WriteRecord();
}
catch(e){
throw(e);
}
finally
{
bcSRTStep = null;
bcActiveSRT = null;//added by jj638 on 25 may2011
}
}

CMI Default SRT Last Step
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
// add try catch block, by jw920 on 20/082011 <Code Clean Up Process
try
{
if(MethodName == "DefaultSRTLastStep")
{
DefaultSRTStep();
return(CancelOperation);
}
if(MethodName == "SetLastStepId")
{
SetLastStepId(Inputs, Outputs);
return CancelOperation;
}
}
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
// End of try catch block
return(ContinueOperation);
}

CMI Default SRT Last Step
DefaultSRTStep
/*****************************************************************************************************************
Created By : Jacky-Huang
Created On : 17-Nov-2010
C&I Number : 4466
Requirement # :
Method Name: DefaultSRTStep
Functionality:
Input: None
Output: None
Customization Approval #: NA
******************************************************************************************************************/
function DefaultSRTStep()
{
try
{
var sBO = TheApplication().ActiveBusObject();
var sBC = sBO.GetBusComp("Quote Item");
var sQuoteItemId = sBC.GetFieldValue("Id");
var sLastStepId = sBC.GetFieldValue("CMI Last Step Id");
var sSRTStepBC = sBC.GetPicklistBusComp("CMI SRT Step Description");
with(sSRTStepBC)
{
SetViewMode("AllView");
ClearToQuery();
SetSearchSpec("Id", sLastStepId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
Pick();
}
}
sBC.WriteRecord();
}
catch(e)
{
throw(e);
}
finally
{
sSRTStepBC = null;
sBC = null;
sBO = null;
}
}

CMI Default Source Location
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//Add try catch block by jw920,on 22/08/11 <Code Clean up Process>
try
{
if(MethodName == "DefaultSourceLocation")
{
DefaultSourceLoc();
return(CancelOperation);
}
}
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}//End of try catch block
return(ContinueOperation);
}

CMI Default Source Location
DefaultSourceLoc
function DefaultSourceLoc()
{
try
{
var ActiveDiv = TheApplication().GetProfileAttr("Primary Division Id");
var sBO = TheApplication().ActiveBusObject();
var sBC = sBO.GetBusComp("Quote");
var sQuoteId = sBC.GetFieldValue("Id");
var sSourceInvLoc;
var sSrcLocBC;
with(sBC)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("Source Inventory Location");
ActivateField("Source Inventory Location Id");
SetSearchSpec("Id", sQuoteId);
ExecuteQuery(ForwardOnly);
var isRec = FirstRecord();
if(isRec)
{
var sBOIntDiv = TheApplication().GetBusObject("Internal Division");
var sIntDivBC = sBOIntDiv.GetBusComp("Internal Division");
with(sIntDivBC)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("CMI Default Inventory Location Id");
SetSearchSpec("Id", ActiveDiv);
ExecuteQuery(ForwardOnly);
var isDivRec = FirstRecord();
if(isDivRec)
{
sSourceInvLoc = GetFieldValue("CMI Default Inventory Location Id");
}
}
if(sSourceInvLoc != null && sSourceInvLoc != "")
{
sSrcLocBC = sBC.GetPicklistBusComp("Source Inventory Location");
with(sSrcLocBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sSourceInvLoc);
ExecuteQuery();
if(FirstRecord())
{
Pick();
}
//SetFieldValue("Source Inventory Location Id", sSourceInvLoc);
}
WriteRecord();
}// end of if(sSourceInvLoc != null && sSourceInvLoc != "")
}
}
}
catch(e)
{
throw(e);
}
finally
{
sSrcLocBC = null;
sIntDivBC = null;
sBOIntDiv = null;
sBC = null;
sBO = null;
}
}

CMI Discount Percent Toolkit
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: David Shao
DESCRIPTION:
INPUTS:
OUTPUTS:
DATE CREATED:
UPDATES:
*********************************************************/
//Add try/catch block by jr418 on 24May,2011
try
{
if(MethodName == "PreQuoteUpdateDiscountCheck"){
//added by jr418 on May 19 2011
var sIgnoreProductType = TheApplication().GetProfileAttr("CMI DBU Quote Query Ignore ProdType");
TheApplication().SetProfileAttr("CMI DBU Quote Query Ignore ProdType", "N");
var boQuote = TheApplication().ActiveBusObject();
var bcQuoteItem = boQuote.GetBusComp("Quote Item");
var bcQuoteItemWarranty = TheApplication().GetBusObject("Quote").GetBusComp("CMI Quote Item Warranty");
var bcQuoteItemWarrantyOlder = boQuote.GetBusComp("CMI Quote Item Warranty");
var sWarrantyId;
var isRecord;
var iLineItem;
var sWPct = 0;
var sTWPct = 0;
var ProAttQId = TheApplication().GetProfileAttr("CMIQItemId");
if(ProAttQId != ""){
iLineItem = ProAttQId;
}else{
iLineItem = bcQuoteItem.GetFieldValue("Id");
}
bcQuoteItemWarrantyOlder.ActivateField("CMI Percent Covered");
var tempValue = bcQuoteItemWarrantyOlder.GetFieldValue("CMI Percent Covered");
var tempId = bcQuoteItemWarrantyOlder.GetFieldValue("Id");
if(tempValue=="" || tempValue == null){
tempValue = 0;
}
with(bcQuoteItemWarranty)
{
SetViewMode(AllView);
ActivateField("CMI Percent Covered");
ActivateField("Parent Id");
ClearToQuery();
SetSearchSpec("Parent Id",iLineItem);
SetSearchSpec("Id","<>'"+tempId+"'");
ExecuteQuery();
isRecord = FirstRecord();
while(isRecord)
{
sWarrantyId = GetFieldValue("Id");
sWPct = ToNumber(GetFieldValue("CMI Percent Covered"));
sTWPct = sTWPct + sWPct;
isRecord = NextRecord();
}
}
if((ToNumber(tempValue)+ToNumber(sTWPct))>100){
//added by jr418 on May 19 2011
TheApplication().SetProfileAttr("CMI DBU Quote Query Ignore ProdType", sIgnoreProductType);
//Fix defect DBUNG00000291, change error msg when total warranty >100%, by JR419 on 15/06/2011
TheApplication().RaiseErrorText("Total of Warranty % should be >= 0% and <= 100%");
}
//added by jr418 on May 19 2011
TheApplication().SetProfileAttr("CMI DBU Quote Query Ignore ProdType", sIgnoreProductType);
return (CancelOperation);
}
if(MethodName == "PreOrderUpdateDiscountCheck"){
var boOrder = TheApplication().ActiveBusObject();
if(boOrder == null)
{
return (CancelOperation);
}
if(boOrder.Name() != "Order Entry (Sales)")
{
return (CancelOperation);
}
var bcOrderItem = boOrder.GetBusComp("Order Entry - Line Items");
var bcItemWarrantyOlder = boOrder.GetBusComp("CMI Order Line Item Warranty");
var sWarrantyId;
var isRecord;
var iLineItem;
var sWPct = 0;
var sTWPct = 0;
var ProAttQId = TheApplication().GetProfileAttr("CMIOItemId");
if(ProAttQId != ""){
iLineItem = ProAttQId;
}else{
iLineItem = bcOrderItem.GetFieldValue("Id");
}
var bcItemWarranty = TheApplication().GetBusObject("Order Entry (Sales)").GetBusComp("CMI Order Line Item Warranty");
bcItemWarrantyOlder.ActivateField("CMI Percent Covered");
var tempValue = bcItemWarrantyOlder.GetFieldValue("CMI Percent Covered");
var tempId = bcItemWarrantyOlder.GetFieldValue("Id");
if(tempValue=="" || tempValue == null){
tempValue = 0;
}
with(bcItemWarranty){
SetViewMode(AllView);
ActivateField("CMI Percent Covered");
ActivateField("Parent Id");
ClearToQuery();
SetSearchSpec("Parent Id",iLineItem);
SetSearchSpec("Id","<>'"+tempId+"'");
ExecuteQuery();
isRecord = FirstRecord();
while(isRecord)
{
sWarrantyId = GetFieldValue("Id");
sWPct = ToNumber(GetFieldValue("CMI Percent Covered"));
sTWPct = sTWPct + sWPct;
isRecord = NextRecord();
}
}
var tempSum = ToNumber(tempValue)+ToNumber(sTWPct);
if((ToNumber(tempValue)+ToNumber(sTWPct))>100){
//Fix defect DBUNG00000291, change error msg when total warranty >100%, by JR419 on 15/06/2011
TheApplication().RaiseErrorText("Total of Warranty % should be >= 0% and <= 100%");
}
return (CancelOperation);
}
if(MethodName == "UpdateOrderDiscount"){
var boOrder = TheApplication().ActiveBusObject();
var bcOrderItem = boOrder.GetBusComp("Order Entry - Line Items");
var bcItemWarranty = boOrder.GetBusComp("CMI Order Line Item Warranty");
var sWarrantyId;
var isRecord;
var iLineItem;
var sWPct = 0;
var sTWPct = 0;
var ProAttQId = TheApplication().GetProfileAttr("CMIOItemId");
if(ProAttQId != ""){
iLineItem = ProAttQId;
}else{
iLineItem = bcOrderItem.GetFieldValue("Id");
}
with(bcItemWarranty){
SetViewMode(AllView);
ActivateField("CMI Percent Covered");
ActivateField("Parent Id");
ClearToQuery();
SetSearchSpec("Parent Id",iLineItem);
ExecuteQuery();
isRecord = FirstRecord();
while(isRecord)
{
sWarrantyId = GetFieldValue("Id");
sWPct = ToNumber(GetFieldValue("CMI Percent Covered"));
sTWPct = sTWPct + sWPct;
isRecord = NextRecord();
}
}
bcOrderItem.ActivateField("Discount Percent");
bcOrderItem.SetFieldValue("Discount Percent", sTWPct);
bcOrderItem.WriteRecord();
return (CancelOperation);
}
if(MethodName == "DeleteOrderDiscount"){
var iLineItem1 = TheApplication().GetProfileAttr("CMIParentItemId");
var tempId = TheApplication().GetProfileAttr("OrderWarrantyId");
var oBO = TheApplication().GetBusObject("Order Entry (Sales)");
var oBC = oBO.GetBusComp("CMI Order Line Item Warranty");
var sWPct = 0;
var sTWPct = 0;
with(oBC){
SetViewMode(AllView);
ActivateField("CMI Percent Covered");
ActivateField("Parent Id");
ClearToQuery();
SetSearchSpec("Parent Id", iLineItem1);
SetSearchSpec("Id", "<>'"+tempId+"'");
ExecuteQuery();
isRecord = FirstRecord();
while (isRecord)
{
sWPct = ToNumber(GetFieldValue("CMI Percent Covered"));
sTWPct = sTWPct + sWPct;
isRecord = NextRecord();
}
var oBCQI = oBO.GetBusComp("Order Entry - Line Items");
with(oBCQI){
SetViewMode(AllView);
ActivateField("Discount Percent");
ClearToQuery();
SetSearchSpec("Id", iLineItem1);
ExecuteQuery();
if(FirstRecord())
{
SetFieldValue("Discount Percent", sTWPct);
WriteRecord();
}
}
/*
var sBS = TheApplication().GetService("SIS OM PMT Service");
var sIP = TheApplication().NewPropertySet();
var sOP = TheApplication().NewPropertySet();
sIP.SetProperty("Business Object Name","Order Entry (Sales)");
sIP.SetProperty("Business Component Name","Order Entry - Line Items");
sBS.InvokeMethod("Refresh Business Component",sIP,sOP); */
return (CancelOperation);
}
}
}catch (e)
{throw e;}
finally
{
sIgnoreProductType = null;
boQuote = null;
bcQuoteItem = null;
bcQuoteItemWarranty = null;
bcQuoteItemWarrantyOlder =null;
sWarrantyId = null;
isRecord = null;
iLineItem = null;
sWPct = null;
sTWPct = null;
tempValue = null;
tempId = null;
boOrder = null;
bcOrderItem = null;
bcItemWarranty = null;
ProAttQId = null;
iLineItem1 = null;
//Added by shanmukh for code clean up 08/26/2011
bcItemWarrantyOlder = null;
oBC = null;
oBCQI = null;
oBO = null;
}
return (ContinueOperation);
}

CMI Error Code
CallLookupCode
/**********************************************************************************************************************
Created By : JX050
Created On : 5-Sep-2011
Method Name: function CallLookupCode()
C&I Number: 4457 & Req#S271
Functionality: This function is used for displaying a message from Message Category Objects using Lookup Message
Customization Approval #: NA
Input: Name of Message Category ,Language Code
Output: Text message in Message category
************************************************************************************************************************/
function CallLookupCode(Inputs, Outputs)
{
try
{
TheApplication().Utility.logStack("CallLookupCode", this);
var sKey = Inputs.GetProperty("sKey");
var sQuoteId = Inputs.GetProperty("sQuoteId");
var sReturn = TheApplication().LookupMessage("User Defined Errors",sKey);
var sWriteIn = "N";
//Instantiate Quote Item BC and verify if there is any line item with Write In Identifier = "Yes"
var oQuoteItem = TheApplication().GetBusObject("Quote").GetBusComp("Quote Item (Simple)");
with(oQuoteItem) {
ActivateField("CMI Write In Identifier");
ActivateField("CMI External Prod Id");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Quote Id", sQuoteId);
SetSearchSpec("CMI External Prod Id", "is null");
SetSearchSpec("CMI Write In Identifier", "Yes");
ExecuteQuery();
var hasRecord = FirstRecord();
TheApplication().Utility.logVars("Write-In found on Quote ("+sQuoteId+")?", hasRecord);
if (hasRecord) {
TheApplication().Utility.logVars("Line ("+GetFieldValue("Id")+")", GetFieldValue("CMI External Prod Id"));
sWriteIn= "Y";
}
}//end with(oQuoteItem)
if(sWriteIn == "Y") {// If write in exists get the alert message in local langauge
Outputs.SetProperty("Msg", sReturn);
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oQuoteItem = null;
sReturn = null;
sKey = null;
TheApplication().Utility.logUnstack(Outputs.GetProperty("Msg"));
}
}

CMI Error Code
CallErrorCode
/*************************************************************************************************************************
Created By : jw920
Created On : 25th July 2011
Method Name: function CallErrorCode()
C&I Number: 4454 & Req#082
Functionality: This function is used for displaying a message from Message Category Objects
Customization Approval #: NA
Input: Name of Message Category ,Language Code
Output: Text message in Message category
************************************************************************************************************************/
function CallErrorCode(Inputs, Outputs)
{
try
{
TheApplication().Utility.logStack("CallErrorCode", this);
var sMsgCatBC = TheApplication().GetBusObject("Repository Details").GetBusComp("Repository Message Locale");
var sErrorCode = Inputs.GetProperty("sErrorCode");
var sLanCode = Inputs.GetProperty("sLanCode");
var hasRec = false;
var sText;
with(sMsgCatBC) {
SetViewMode(AllView);
ActivateField("Parent Name");
ActivateField("Text");
ActivateField("Language Code");
ClearToQuery();
SetSearchSpec("Parent Name", sErrorCode);
SetSearchSpec("Language Code", sLanCode);
ExecuteQuery();
hasRec = FirstRecord();
TheApplication().Utility.logVars(sLanCode+" Message ("+sErrorCode+") Found?", hasRec);
if(hasRec) {
sText = GetFieldValue("Text");
}//end of if
}//end of with(sMsgCatBC)
Outputs.SetProperty("sErrorText",sText);
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sMsgCatBC = null;
TheApplication().Utility.logUnstack(sText);
}
}

CMI Error Code
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/**********************************************************************************************************************
Created By : JW920
Created On : 25/7/2011
C&I Number: 4457
Requirement #: S271
Functionality: To display the proper messages,using message category
Input: Name of Message Category ,Language Code
Output: Text message in Message category
************************************************************************************************************************/
// Added by jw920 on 25/7, Desc : called error message from Message category objects
try
{
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
switch (MethodName) {
case "CallErrorCode":
CallErrorCode(Inputs, Outputs);
break;
// Added by JX050 as part of C&I 4457 on 5th Sep 2011,Desc : to retrieve message in user defined meassages
case "CallLookupCode":
CallLookupCode(Inputs, Outputs);
break;
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Error Handling BS
GetApplicationError
/*************************************************************************************************************************
Created By : Pankaj Sinha
Created On : 14th January 2010
Method Name: function Service_PreInvokeMethod
C&I Number : NA
Requirement # : NA
Functionality: This Business Service has been written to get the Application error; occurred from any object and
log it into error Table.
Input: Error Message, Error Code, Object Type, Object Name, Object Id
Output: Status
Customization Approval #: NA
************************************************************************************************************************/
function GetApplicationError(Inputs,Outputs)
{
try {
TheApplication().Utility.logStack("GetApplicationError", this);
var sErrMsg = Inputs.GetProperty("Error Message");
var sErrCode = Inputs.GetProperty("Error Code");
var sObjectType = Inputs.GetProperty("Object Type")
var sObjectName = Inputs.GetProperty("Object Name");
var sObjectId = Inputs.GetProperty("EntityReferenceId");
var sEntity :String= Inputs.GetProperty("EntityName");
var BoError = TheApplication().GetBusObject("CMI Error Log");
var BcError = BoError.GetBusComp("CMI Error Log Summary");
var sLogName = TheApplication().LoginName();
var sessionId = TheApplication().Utility.GetSessionId();
if(sEntity.length >30) {//added by KM330
var sEntityNew:String = sEntity.substr(0,29);
sEntity = sEntityNew;
}
// TheApplication().Utility.logVars("Object ("+sObjectType+")", sObjectName , "Error", sErrMsg, "Entity (Id)", sEntity+" ("+sObjectId+")");
TheApplication().Utility.logStep("".rPad(100, "*"),0);
TheApplication().Utility.logStep("*** - ERROR - Object ("+sObjectType+"): "+sObjectName+" - "+sErrCode,0);
TheApplication().Utility.logStep("*** "+sErrMsg.replace(/\n/g, "\n"+"*** "),0);
TheApplication().Utility.logStep("".rPad(100, "*")+"\n",0);
with (BcError) {
SetViewMode(AllView);
NewRecord(NewBefore);
SetFieldValue("CMI Error Code",sErrCode);
SetFieldValue("CMI Error Message",sErrMsg);
SetFieldValue("CMI Object Type",sObjectType);
SetFieldValue("CMI Object Name",sObjectName);
SetFieldValue("CMI Status",sEntity);
SetFieldValue("CMI Type",sObjectId);
SetFieldValue("CMI Login Name",sLogName);
SetFieldValue("CMI Session Id", sessionId);
WriteRecord();
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
BcError = null;
BoError = null;
TheApplication().Utility.logUnstack();
}
}

CMI Error Handling BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : Pankaj Sinha
Created On : 14th January 2010
Method Name: function Service_PreInvokeMethod
C&I Number : NA
Requirement # : NA
Functionality: This Business Service has been written to get the Application error; occurred from any object and
log it into error Table.
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
switch(MethodName)
{
case ("GetApplicationError"):
GetApplicationError(Inputs, Outputs);
return (CancelOperation);
break;
}
return (ContinueOperation);
}
catch(e)
{
//TheApplication().RaiseErrorText("An exception occurred. " + "\r\nERROR: " + e.errText + "\r\nSTACK: " + e.toString());
throw e;
}
finally
{
//object Deallocation
}
}

CMI Generate Claim Number BS
GenClaimSeq
function GenClaimSeq(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("GenClaimSeq", this);
var oClaimBO = TheApplication().GetBusObject("CMI Claim Sequence Generation");
var oClaimSeqBC = oClaimBO.GetBusComp("CMI Claim Sequence Generation");
var sOrderId = Inputs.GetProperty("Order Id");
var sWarId = Inputs.GetProperty("Warranty Id");
var sDivId = Inputs.GetProperty("Division Id");
var ClaimSeqNum;
with(oClaimSeqBC) {
ActivateField("CMI Cycle Flag");
ActivateField("CMI Claim Sequence Number");
ActivateField("CMI Sequence Number Date");
ActivateField("CMI Division Id");
ActivateField("CMI Order Id");
ClearToQuery();
SetSearchSpec("CMI Division Id", sDivId);
SetSearchSpec("CMI Cycle Flag", "N");
SetSortSpec("CMI Claim Sequence Number(DESCENDING)");
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Claims for Div ("+sDivId+") found?", FirstRecord());
if (FirstRecord()) {
ClaimSeqNum = ToNumber(GetFieldValue("CMI Claim Sequence Number"));
TheApplication().Utility.logVars("Current Claim #", ClaimSeqNum);
if(ClaimSeqNum >= 65000) {
//Call function to set Cycle Flag to Y for the current set b/w 10001 and 65000
SetCycleFlag(ClaimSeqNum);
ClaimSeqNum = 10000;
}
ClaimSeqNum = ToNumber(ClaimSeqNum) + 1;
} else {
ClaimSeqNum = 10001;
}
TheApplication().Utility.logVars("Next Claim #", ClaimSeqNum);
if(ClaimSeqNum > 10000 && ClaimSeqNum <= 65000) {
NewRecord(NewAfter);
SetFieldValue("CMI Claim Sequence Number", ToNumber(ClaimSeqNum));
SetFieldValue("CMI Order Id", sOrderId);
SetFieldValue("CMI Warranty Id", sWarId);
SetFieldValue("CMI Division Id", sDivId);
WriteRecord();
Outputs.SetProperty("errCode", 0);
Outputs.SetProperty("ClaimSeqNum", GetFieldValue("CMI Claim Sequence Number"));
}
}
} catch(e){
if(e.errCode == "7668094") {
Outputs.SetProperty("errCode", 1);
Outputs.SetProperty("ClaimSeqNum", "");
} else
TheApplication().Utility.RaiseError(e);
} finally {
oClaimSeqBC = null;
oClaimBO = null;
TheApplication().Utility.logUnstack(Outputs.GetProperty("ClaimSeqNum"));
}
}

CMI Generate Claim Number BS
SetCycleFlag
function SetCycleFlag(ClaimSeqNum)
{
try
{
ClaimSeqNum = ToNumber(ClaimSeqNum) + 1;
var oBS = TheApplication().GetService("Workflow Process Manager");
var Inputs = TheApplication().NewPropertySet();
var Outputs = TheApplication().NewPropertySet();
Inputs.SetProperty("ProcessName", "CMI Claim Sequence Set Cycle Flag");
Inputs.SetProperty("MaxSeqNum", ClaimSeqNum);
oBS.InvokeMethod("RunProcess", Inputs, Outputs);
}
catch(e)
{
throw(e);
}
finally
{
oBS = null;
Inputs = null;
Outputs = null;
}
}

CMI Generate Claim Number BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if (MethodName == "GenerateClaimSeq") {
GenClaimSeq(Inputs, Outputs);
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Generate Time Tracker
ProcessTimeRecords
function ProcessTimeRecords (sId, sStop, sStart, sBCName, sSRId)
{
/*********************************************************
AUTHOR: Anand Shanmugam, Oracle Corporation
DESCRIPTION: Takes the Activity Id , Start and Stop params as input and
updates the Time Sheet Daily Hours BC
INPUTS: Row Id, sStop, sStart, sBCName
OUTPUTS:
DATE CREATED:
UPDATES:
*********************************************************/
try
{//try
var oBO = TheApplication().GetBusObject("Action");
var oBCAction = oBO.GetBusComp(sBCName);
var oBCTimeSheet = oBO.GetBusComp("Time Sheet Unassoc Daily Hours");
oBCTimeSheet.ActivateField("Service Request Id");
//Query A
with (oBCAction)
{//withoBCAction
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec ("Id", sId);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{ //if1
with (oBCTimeSheet)
{//withoBCTimeSheet
if (sStop == "Yes")
{//if2
ClearToQuery();
ActivateField("End Time");
SetSearchExpr("[End Time] IS NULL");
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
var dSysDate = Clib.localtime(Clib.time());
var sSysdate = ( dSysDate.tm_mon + 1 ) + "/" + dSysDate.tm_mday + "/" + (dSysDate.tm_year+1900) + " "+ dSysDate.tm_hour + ":" + dSysDate.tm_min + ":" + dSysDate.tm_sec;
// TheApplication().TraceOn("c:\\eScript_trace.txt","allocation","all");
// TheApplication().Trace("Time Value : " + sSysdate);
// TheApplication().RaiseErrorText("The Current date is " + dToday );
SetFieldValue("End Time", sSysdate );
WriteRecord();
}
}
if ( sStart == "No")
{
}
else
{
NewRecord(NewAfter);
var dNow = GetFieldValue("Start Time");
SetFieldValue("Project", sStart);
SetFieldValue("Item Date", dNow);
SetFieldValue("Billing Rate Type", "Normal");
SetFieldValue("Service Request Id", sSRId);
WriteRecord();
}
}//withoBCTimeSheet
}//if1
}//withoBCAction
}//try
catch(e)
{
// TheApplication().Trace("Error Message : " + e.toString());
// TheApplication().TraceOff();
TheApplication().RaiseErrorText(e.toString());
throw(e);
}
finally
{
oBCAction = null;
oBCTimeSheet = null;
oBO = null;
}
}

CMI Generate Time Tracker
IsFutureDate
//DBUNG00002870 added this fucntion to determine if the end date is a future date to handle time difference less than 24 hrs but spaning accross dates 10-Nov-2011 3 PM login and 11-Nov-2011 10 AM logout by ki795 on 11-Nov-2011
function IsFutureDate(StartDate,EndDate)
{
var sIsFuture;
try
{
var sEndMon = ToInteger(EndDate.getMonth()+1);
var sEndDay = ToInteger(EndDate.getDate());
var sEndYear = ToInteger(EndDate.getFullYear());
var sStartMon = ToInteger(StartDate.getMonth()+1);
var sStartDay = ToInteger(StartDate.getDate());
var sStartYear = ToInteger(StartDate.getFullYear());
if ((sEndYear < sStartYear)||((sEndYear==sStartYear)&&(sEndMon < sStartMon))||((sEndYear==sStartYear)&&(sEndMon==sStartMon)&&(sEndDay <= sStartDay)))
{
sIsFuture = "No";
}
else
{
sIsFuture = "Yes";
}
}
catch(e)
{
throw(e);
}
if (sIsFuture == "No")
return(0);
else
return(1);
}

CMI Generate Time Tracker
GetCurrentEndTime
function GetCurrentEndTime(strTime)
{
/*********************************************************
AUTHOR: JR426
Purpose: This function is used for transfer the time format to MM/DD/YY HH/MM/SS.
INPUTS:
OUTPUTS: None
DATE CREATED: 2011-6-27
UPDATES:
//var sEndTime = ( dSysDate.tm_mon + 1 ) + "/" + dSysDate.tm_mday + "/" + (dSysDate.tm_year+1900) + " "+ dSysDate.tm_hour + ":" + dSysDate.tm_min + ":" + dSysDate.tm_sec;
*********************************************************/
//try catch added by shanmukh for code clean up 08/27/2011
try
{
var v_Time = strTime;
var sMonth = ToString(v_Time.tm_mon + 1);
if (sMonth.length == 1)
sMonth = "0" + sMonth;
var sDay = ToString(v_Time.tm_mday);
if (sDay.length == 1)
sDay = "0" + sDay;
var sHours = ToString(v_Time.tm_hour);
if (sHours.length == 1)
sHours = "0" + sHours;
var sMinutes = ToString(v_Time.tm_min);
if (sMinutes.length == 1)
sMinutes = "0" + sMinutes;
var sSeconds = ToString(v_Time.tm_sec);
if (sSeconds.length == 1)
sSeconds = "0" + sSeconds;
var v_TimeStr;
v_TimeStr = sMonth +"/"+ sDay +"/" + (v_Time.tm_year+1900) + " " + sHours+":"+sMinutes+":"+sSeconds;
v_Time = null;
}
catch(e)
{
throw(e);
}
return v_TimeStr;
}

CMI Generate Time Tracker
GetCurrentTime
function GetCurrentTime(strTime)
{
/*********************************************************
AUTHOR: JR426
Purpose: This function is used for transfer the time format to MM/DD/YY HH/MM/SS.
INPUTS:
OUTPUTS: None
DATE CREATED: 2011-6-27
UPDATES:
*********************************************************/
//Try catch added by shanmukh for code clean up 08/20/2011
try
{
var v_Time = strTime;
var sMonth = ToString(v_Time.getMonth() + 1);
if (sMonth.length == 1)
sMonth = "0" + sMonth;
var sDay = ToString(v_Time.getDate());
if (sDay.length == 1)
sDay = "0" + sDay;
var sHours = ToString(v_Time.getHours());
if (sHours.length == 1)
sHours = "0" + sHours;
var sMinutes = ToString(v_Time.getMinutes());
if (sMinutes.length == 1)
sMinutes = "0" + sMinutes;
var sSeconds = ToString(v_Time.getSeconds());
if (sSeconds.length == 1)
sSeconds = "0" + sSeconds;
var v_TimeStr;
v_TimeStr = sMonth +"/"+ sDay +"/" + v_Time.getFullYear() + " " + sHours+":"+sMinutes+":"+sSeconds;
v_Time = null;
//return v_TimeStr; //commented by shanmukh for code clean up 08/20/2011
}//end of try
catch(e)
{
throw(e); //RaiseErrorText statement not used since return is at the last, also verified that method calling this function has a try catch
}//end of catch
return v_TimeStr; //added by shanmukh for code clean up 08/20/2011
}

CMI Generate Time Tracker
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: Anand Shanmugam - Oracle Corporation
DESCRIPTION: The Business Service Updates and Creates Time Tracker records based on the
Activity Status change
INPUTS: There is no mandatory inputs since the service is run in Run Time Events
But the Inputs are passed as Business Service Context: "BCName", "Action",
"StartParameter", "Travel", "StopParameter", "No"
OUTPUTS: None
DATE CREATED: 2/1/2010
UPDATES:
*********************************************************/
if (MethodName == "ProcessTimeRecords") {
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var context_string = Inputs.GetProperty("Context");
var context_array = context_string.split(", ");
var sBCName = context_array[1];
var sStart = context_array[3];
var sStop = context_array[5];
sBCName = sBCName.replace(/\"/g,'');
sStart = sStart.replace(/\"/g,'');
sStop = sStop.replace(/\"/g,'');
var sActionId = TheApplication().GetProfileAttr("CMI TT Update Action Action Id");
var sSRId = "";
var oBO = TheApplication().GetBusObject("Action");
var oBCAction = oBO.GetBusComp(sBCName);
var oBCTimeSheet = oBO.GetBusComp("Time Sheet Unassoc Daily Hours")
//var sTimeItemId = "";
var sProjId = "";
var project = "";
var sTimeTrackerId = "" ;
//Query A
with (oBCAction) {
//ActivateField("Primary Service Request Id");
ActivateField("Activity SR Id");
ActivateField("Description");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec ("Id", sActionId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Activity ("+sActionId+") found?", FirstRecord(), "Start/Stop", sStart+" / "+sStop);
if (FirstRecord()) { //if1
TheApplication().Utility.logId(oBCAction);
//sSRId = GetFieldValue("Primary Service Request Id");
sSRId = GetFieldValue("Activity SR Id");
with (oBCTimeSheet) {//withoBCTimeSheet
ActivateField("Service Request Id");
if (sStop == "Yes") {//if2
ClearToQuery();
ActivateField("End Time");
ActivateField("Item Date");
ActivateField("Project");
ActivateField("Billable Flag");
SetSearchExpr("[End Time] IS NULL");
ExecuteQuery(ForwardOnly);
if (FirstRecord()) {
//JR426 added for Time Tracker Cross Days Issue ---Start
sProjId = GetFieldValue("Project Id");
project = GetFieldValue("Project");
var dSysDate = Clib.localtime(Clib.time());
var sEndTime = GetCurrentEndTime(dSysDate);
var sStartTime = GetFieldValue("Item Date"); //DBUNG00002870 changed the get field value from Created to Item Date by ki795 on 11-Nov-2011
var strEndTime = new Date(sEndTime);
var strStartTime = new Date(sStartTime);
var strdiff =strEndTime.getTime()-strStartTime.getTime();
var strdiffDay = ToString(strdiff/1000/60/60/24);
var strdiffDayNumber = Math.floor(strdiff/1000/60/60/24);
var sFutureDate = IsFutureDate(strStartTime,strEndTime);//DBUNG00002870 added future date function to check if the end date is future date by ki795 on 11-Nov-2011
if(strdiffDayNumber != 0 && strdiffDayNumber >0 && sFutureDate == 1) {//if strdiffDayNumber != 0, than means the technician wrok cross the day.we need create the time sheet item for other days.
TheApplication().Utility.logVars("Future Date", sFutureDate);
var strStartSecond = ToNumber(sStartTime.substring(11,13))*3600 + ToNumber(sStartTime.substring(14,16))* 60 + ToNumber(sStartTime.substring(17,19));
var strEndSecond = ToNumber(sEndTime.substring(11,13))*3600 + ToNumber(sEndTime.substring(14,16))* 60 + ToNumber(sEndTime.substring(17,19));
var strDiffSecond = strEndSecond - strStartSecond;
var strDayNumber = 0;
var sForEndTime = "";
var sNexTime = "";
var sNextEndTime = "";
var sNextStartDate = "";
var sNextEndDate = "";
if(strDiffSecond >= 0) {//compare the time between start date and end date, if larger than and equal 0,the difference number add 1, else add 2.
strDayNumber = ToNumber(strdiffDay.substring(0,2)) + 1;
} else {
strDayNumber = ToNumber(strdiffDay.substring(0,2)) + 2;
}
for(var i=0;i<strDayNumber;i++) {//use the strDayNumber to add the time sheet item.
with(oBCTimeSheet) {
ActivateField("Start Time");
ActivateField("End Time");
ActivateField("Project");
ActivateField("Project Id");
ActivateField("Item Date");
sForEndTime = new Date(sStartTime.substring(0,10)+" "+"23:59:59");
if(i==0) {//when first loop, the time sheet item had created when clock in,find the record and set the end time.
//check if already clock in
ClearToQuery();
SetSearchExpr("[End Time] is null");
SetSortSpec("Created(Desc)");
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
SetFieldValue("End Time", GetCurrentTime(sForEndTime));
}
WriteRecord();
}
sNexTime = sForEndTime.getTime() + 1000;//next day start time
sNextEndTime = sForEndTime.getTime() + 86400000;//next day end time.
sNextStartDate = new Date(sNexTime);
sNextEndDate = new Date(sNextEndTime);
sStartTime = GetCurrentTime(sNextStartDate);
if(ToString(i) != ToString(ToNumber(strDayNumber)-1)) {//Create record for time sheet item.
NewRecord(NewAfter);
//SetFieldValue("Project Id", sProjId); 'gbay_04/25/13
SetFieldValue("Project", project);//gbay_04/25/13
SetFieldValue("Service Request Id", sSRId);//'gbay_04/25/13
SetFieldValue("Start Time",sStartTime);
SetFieldValue("CMI Record Source", "Task UI"); //lq305-7-7-13 to identify source of TT
//SetFieldValue("Billable Flag", "Y"); //lq305-7-7-13 Billable is true for all Labor activities
if(i==ToNumber(strDayNumber)-2) {//if the record is for clock out, set the user's clock time,else set the the the day's end time.
//SetFieldValue("End Time",sEndTime);
InvokeMethod("SetEndTime");
} else {
SetFieldValue("End Time",GetCurrentTime(sNextEndDate));
SetFieldValue("Item Date",GetCurrentTime(sNextEndDate));
}
WriteRecord();
if(project == "Work" || project == "Labor" || project == "Travel")
{
sTimeTrackerId = GetFieldValue("Id");
addToTimesheet(sTimeTrackerId) ;
}
}
}
}
} else {
with(oBCTimeSheet) {
ActivateField("Start Time");
//check if already clock in
ClearToQuery();
SetSearchExpr("[End Time] is null");
SetSortSpec("Created(Desc)");
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
InvokeMethod("SetEndTime");
WriteRecord();
}
}
}
//JR426 added for Time Tracker Cross Days Issue ---End
//InvokeMethod("SetEndTime");//Steve 20110102: fix the time tracker error.
//WriteRecord();
}
}
if ( sStart == "No") {
} else {
NewRecord(NewAfter);
var dNow = GetFieldValue("Start Time");
SetFieldValue("Project", sStart);
SetFieldValue("Item Date", dNow);
SetFieldValue("Billing Rate Type", "Normal");
SetFieldValue("Service Request Id", sSRId);
SetFieldValue("CMI Record Source", "Task UI");
//SetFieldValue("Billable Flag", "Y"); //lq305-7-7-13 Billable is true for all Labor activities
WriteRecord();
if(sStart == "Work" || sStart == "Labor" || sStart == "Travel")
//CQ DBUNG00012490-RM - 09/12/13- changed the variable from sPorject to sStart for Travel
{
sTimeTrackerId = GetFieldValue("Id");
addToTimesheet(sTimeTrackerId) ;
}
}
}//withoBCTimeSheet
}//if1
}//withoBCAction
var boActive:BusObject = TheApplication().ActiveBusObject();
var bcTimeSheet:BusComp = null;
if (boActive != null) {
bcTimeSheet = boActive.GetBusComp("Time Sheet Daily Hours");
if (bcTimeSheet != null) {
bcTimeSheet.InvokeMethod("RefreshBusComp");
}
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
bcTimeSheet = null;
boActive = null;
oBCTimeSheet = null;
oBCAction = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
return (CancelOperation);
}
}

CMI Generate Time Tracker
addToTimesheet
function addToTimesheet(sTimeTrackerId)
{
//added by lq305 - for TT entry association with Timesheet
if(sTimeTrackerId != "")
{
try{
var bsTimeTracker = TheApplication().GetService("CMI Time Tracker BS") ;
var psInputs = TheApplication().NewPropertySet()
var psOutputs = TheApplication().NewPropertySet()
psInputs.SetProperty("TimeTrackerId", sTimeTrackerId) ;
bsTimeTracker.InvokeMethod("CMIAssignTT", psInputs, psOutputs) ;
}
catch(e){
} finally {
if(defined(bsTimeTracker)) bsTimeTracker = null ;
if(defined(psInputs)) psInputs = null ;
if(defined(psOutputs)) psOutputs = null ;
}
}
}

CMI Generate Warranty Payments
(declarations)
var sOrderId;//CMI DBU: Release # 2, C&I 4609.created by jq486

CMI Generate Warranty Payments
CMIGenWarrantyPay
/*************************************************************************************************************************
Created By : Damon Liu (JR430)
Created On : 2011-09-06
C&I Number : 4609
Functionality: Method creating Warrnty Payments as per S139
************************************************************************************************************************/
function CMIGenWarrantyPay(sOrderId)
{
try
{
TheApplication().Utility.logStack("CMIGenWarrantyPay", this);
var sBO:BusObject = TheApplication().GetBusObject("CMI Claims");
var sClaimBC:BusComp = sBO.GetBusComp("INS Claims");
var sClaimPayBC:BusComp = sBO.GetBusComp("INS Claims Payments");
var sClaimOrdersBC:BusComp = sBO.GetBusComp("CMI Claim Orders");
var isClaimRec:bool;
//Strong Typing not used intentionally by KM326 to fix C&I 4609 Bug # 285 on 10/06/2011
var sTotalPart;
var sTotalLabor;
var sTotalMisc;
//Strong Typing not used intentionally by KM326 to fix C&I 4609 Bug # 285 on 10/06/2011
var sCurcyCd:String;
var sClaimId;
var strSearch1 = TheApplication().InvokeMethod("LookupValue", "CMI_EARLY_CREDIT", "Issued");
var strSearch2 = TheApplication().InvokeMethod("LookupValue", "CMI_EARLY_CREDIT", "No Early Credit");
TheApplication().SetProfileAttr("CMIExcludePaymentChk","Y");//Inactivated Script-31 Jan 2011-Dinesh
//Added by KM326 to fix C&I 4609 Bug # 285 on 10/06/2011
//Strong Typing not used intentionally
var sVarianceFlag = "";
var sCMIEarlyCredit = "";
var sBS = "";
var sInputProp:PropertySet = TheApplication().NewPropertySet();
var sOutputProp:PropertySet = TheApplication().NewPropertySet();
var sOrderBO:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var sOrderBC = sOrderBO.GetBusComp("Order Entry - Orders");
with(sOrderBC) {
ActivateField("CMI Parts Total Local");
ActivateField("CMI Labor Total Local");
ActivateField("CMI Misc Total Local");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sOrderId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Order ("+sOrderId+") found?", FirstRecord());
if(FirstRecord()) {
sTotalPart = GetFieldValue("CMI Parts Total Local");
sTotalLabor = GetFieldValue("CMI Labor Total Local");
sTotalMisc = GetFieldValue("CMI Misc Total Local");
}
}
//Added by KM326 to fix C&I 4609 Bug # 285 on 10/06/2011
with(sClaimOrdersBC) {
ActivateField("CMI Order Id");
ActivateField("CMI Claim Id");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Order Id",sOrderId);
ExecuteQuery(ForwardOnly);
var isOrderRec = FirstRecord();
TheApplication().Utility.logVars("Claim/Order found?", isOrderRec);
if(isOrderRec) {
sClaimId = GetFieldValue("CMI Claim Id");
}
}
var strSearch = "[Id] = '" + sClaimId + "' AND ([CMI Early Credit] = '" + strSearch1 + "' OR [CMI Early Credit] = '" + strSearch2 + "')";
with(sClaimBC) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("CMI Early Credit");
ActivateField("CMI Cummins Part");
ActivateField("CMI Other Claimable");
ActivateField("CMI Total Labor");
ActivateField("Currency Code");
SetSearchExpr(strSearch);//CMI DBU: Added by jq486, C&I 4609 tuning.
//SetSearchSpec("Id", sClaimId);//CMI DBU: Commented by jq486, C&I 4609 tuning.
//SetSearchSpec("CMI Early Credit", TheApplication().InvokeMethod("LookupValue", "CMI_EARLY_CREDIT", "Issued"));//CMI DBU: Commented by jq486, C&I 4609 tuning.
ExecuteQuery(ForwardOnly);
isClaimRec = FirstRecord();
TheApplication().Utility.logVars("Claim ("+sClaimId+") found?", isClaimRec);
if(isClaimRec) {
//Commeted by KM326 to fix C&I 4609 Bug # 285 on 10/06/2011
//sTotalPart = GetFieldValue("CMI Cummins Part");
//sTotalLabor = GetFieldValue("CMI Total Labor");
//sTotalMisc = GetFieldValue("CMI Other Claimable");
sCurcyCd = GetFieldValue("Currency Code");
//Added by KM326 to fix C&I 4609 Bug # 285 on 10/05/2011
sCMIEarlyCredit = GetFieldValue("CMI Early Credit");
TheApplication().Utility.logVars("Total Parts", sTotalPart);
if(sTotalPart != "" && sTotalPart != null && sTotalPart != 0) {//Modified by KM326 to fix C&I 4609 Bug # 285 on 10/05/2011 to add !=0 condition
with(sClaimPayBC) {
InvokeMethod("SetAdminMode", "TRUE");
NewRecord(NewAfter);
SetFieldValue("Claim Id", sClaimId);
SetFieldValue("Payment Type Code", TheApplication().InvokeMethod("LookupValue", "CMI_PAYMENT_TYPE", "Warranty Credit Payment"));
SetFieldValue("CMI Payment Credit Type", "Parts");
SetFieldValue("Payment Amount", sTotalPart);
SetFieldValue("Currency Code", sCurcyCd);
SetFieldValue("Payment Status", TheApplication().InvokeMethod("LookupValue", "FUNDRQ_STATUS", "Verified"));
WriteRecord();
//Added by KM326 to fix C&I 4609 Bug # 285 on 10/05/2011
sVarianceFlag = "Y";
}//end of with
}//end of if(sTotalPart .valueOf()!= "" && sTotalPart.valueOf() != null)
TheApplication().Utility.logVars("Total Labor", sTotalLabor);
if(sTotalLabor != "" && sTotalLabor != null && sTotalLabor != 0) {//Modified by KM326 to fix C&I 4609 Bug # 285 on 10/05/2011 to add !=0 condition
with(sClaimPayBC) {
InvokeMethod("SetAdminMode", "TRUE");
NewRecord(NewAfter);
SetFieldValue("Claim Id", sClaimId);
SetFieldValue("Payment Type Code", TheApplication().InvokeMethod("LookupValue", "CMI_PAYMENT_TYPE", "Warranty Credit Payment"));
SetFieldValue("CMI Payment Credit Type", "Labor");
SetFieldValue("Payment Amount", sTotalLabor);
SetFieldValue("Currency Code", sCurcyCd);
SetFieldValue("Payment Status", TheApplication().InvokeMethod("LookupValue", "FUNDRQ_STATUS", "Verified"));
WriteRecord();
//Added by KM326 to fix C&I 4609 Bug # 285 on 10/05/2011
sVarianceFlag = "Y";
}//end of with
}//end of if(sTotalLabor.valueOf()!= "" && sTotalLabor.valueOf() != null)
TheApplication().Utility.logVars("Total Misc", sTotalMisc);
if(sTotalMisc != "" && sTotalMisc != null && sTotalMisc != 0) { //Modified by KM326 to fix C&I 4609 Bug # 285 on 10/05/2011 to add !=0 condition
with(sClaimPayBC) {
InvokeMethod("SetAdminMode", "TRUE");
NewRecord(NewAfter);
SetFieldValue("Claim Id", sClaimId);
SetFieldValue("Payment Type Code", TheApplication().InvokeMethod("LookupValue", "CMI_PAYMENT_TYPE", "Warranty Credit Payment"));
SetFieldValue("CMI Payment Credit Type", "Misc");
SetFieldValue("Payment Amount", sTotalMisc);
SetFieldValue("Currency Code", sCurcyCd);
SetFieldValue("Payment Status", TheApplication().InvokeMethod("LookupValue", "FUNDRQ_STATUS", "Verified"));
WriteRecord();
//Added by KM326 to fix C&I 4609 Bug # 285 on 10/05/2011
sVarianceFlag = "Y";
}//end of with
}//end of if(sTotalMisc.valueOf()!= "" && sTotalMisc.valueOf() != null)
}//end of if(isClaimRec)
}// end of With(sClaimsBC)
//Added by KM326 to fix C&I 4609 Bug # 285 on 10/05/2011
TheApplication().Utility.logVars("Variance Created?", sVarianceFlag, "Early Credit", sCMIEarlyCredit);
if(sVarianceFlag == "Y" && sCMIEarlyCredit == strSearch2) {
TheApplication().SetProfileAttr("CMIWarCreditClaimId", sClaimId);
sBS = TheApplication().GetService("CMI Warranty Credit Updates BS");
sBS.InvokeMethod("CMICreateWarrantyVariance", sInputProp, sOutputProp);
TheApplication().SetProfileAttr("CMIWarCreditClaimId", "");
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().SetProfileAttr("CMIExcludePaymentChk",null);
sClaimOrdersBC = null;
sClaimPayBC = null;
sClaimBC = null;
sBO = null;
sInputProp = null;
sOutputProp = null;
sBS = null;
sOrderBC = null;
sOrderBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Generate Warranty Payments
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
// Add try Catch block by jw920 on 20/10/2011 <Code Clean up>
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if (MethodName == "CMIGenWarrantyPay") {
//var sClaimId = Inputs.GetProperty("CMIClaimId");//CMI DBU: Release # 2, C&I 4609.commented by jq486
//CMIGenWarrantyPay(sClaimId);//CMI DBU: Release # 2, C&I 4609.commented by jq486
sOrderId = Inputs.GetProperty("CMIOrderId"); //CMI DBU: Release # 2, C&I 4609.added by jq486
CMIGenWarrantyPay(sOrderId);//CMI DBU: Release # 2, C&I 4609.added by jq486
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Gotoview Allocation
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: Ismail Mohideen - Oracle Corporation
DESCRIPTION: This Business service is used to goto allocation view when the status
of the Activity is changed to "Work Complete"
OUTPUTS: None
DATE CREATED: 3/1/2010
UPDATES:
*********************************************************/
if (MethodName == "Gotoview")
{
try{
var allocBO = TheApplication().ActiveBusObject();
var allocBC = allocBO.GetBusComp("Action");
var allocId = allocBC.GetFieldValue("Id");
allocBO = TheApplication().GetBusObject("Action");
var allocBO2 = TheApplication().GetBusObject("Action");
var allocBC2 = allocBO2.GetBusComp("Action");
with (allocBC2)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", allocId);
ExecuteQuery(ForwardBackward);
}
TheApplication().GotoView("CMI Activity Allocation View",allocBO2);
}catch(e){//added by jj638
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally{
allocBC = null;
allocBO = null;
allocBC2 = null;
allocBO2 = null;
}
return (CancelOperation);
}
else
return (ContinueOperation);
}

CMI ILOG Integration BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if(MethodName == "CloseiLog")
{
var inpPS = TheApplication().NewPropertySet();
var outPS = TheApplication().NewPropertySet();
var bs = TheApplication().GetService("SIS OM PMT Service");//jq 486: Changed the BS to overcome the refresh issue
var sId = TheApplication().ActiveBusObject().GetBusComp("Service Request").GetFieldValue("Id");
inpPS.SetProperty("Business Component Name","Service Request");
inpPS.SetProperty("Business Object Name", "Service Request");
inpPS.SetProperty("Go to View Name","FINS Service Request Complaints View");
//inpPS.SetProperty("Row Id",sId);
//inpPS.SetProperty("Row Id",sId);
//outPS = bs.InvokeMethod("GotoView",inpPS,outPS);
outPS = bs.InvokeMethod("Refresh Business Component",inpPS,outPS);
return(CancelOperation);
}
return (ContinueOperation);
}
catch(e)
{
throw(e)
}
finally
{
sId = null;
inpPS = null;
outPS = null;
bs = null;
}
}

CMI ISS Approval Bus Service
ServiceQuoteGA
function ServiceQuoteGA(Inputs,Outputs)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS:
OUTPUTS:
Purpose: Generate Quote APproval record when setting status to Waiting Approavl
DATE CREATED:
UPDATES:
Purpose:
*********************************************************/
try{ // Service Quote Generate Approval when setting status to Waiting For Approval
var sPositionType = TheApplication().GetProfileAttr("Primary Position Type");
var sPositionId = TheApplication().GetProfileAttr("Primary Position Id");
var sParentPosId = TheApplication().GetProfileAttr("CMI Parent Position Id");
var sParentPosPrimaryEmployeeId = TheApplication().GetProfileAttr("CMI Parent Position Primary Employee Id");
var sParentPos = TheApplication().GetProfileAttr("CMI Parent Position Name");
var sParentPosType = TheApplication().GetProfileAttr("CMI Parent Position Type");
if(sParentPosType != TheApplication().InvokeMethod("LookupValue","POSITION_TYPE","Service Supervisor") || sParentPosPrimaryEmployeeId == "")
return;
//get Service Superviser
var bo = TheApplication().ActiveBusObject();
var bc = bo.GetBusComp("Quote");
var sQuoteName = bc.GetFieldValue("Name");
var sQuoteId = bc.GetFieldValue("Id");
var bsUInbox = TheApplication().GetService("Universal Inbox");
var psIn = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();
psIn.SetType("InboxInfo");
psIn.SetProperty("InboxName",sQuoteName);
psIn.SetProperty("InboxTypeName","Quote");
psIn.SetProperty("InboxPartyId", TheApplication().LoginId());
psIn.SetProperty("ObjectId", sQuoteId);
psIn.SetProperty("OwnerPartyId",sParentPosPrimaryEmployeeId);
bsUInbox.InvokeMethod("CreateInboxEx",psIn,psOut);
}catch(e){//added by jj638
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally{
//Added by shanmukh for code clean up 08/27/2011
bc = null;
bo = null;
psIn = null;
psOut = null;
bsUInbox = null;
}
}

CMI ISS Approval Bus Service
ServiceApproval
function ServiceApproval(Inputs,Outputs)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS:
OUTPUTS:
DATE CREATED: 31/Aug/2010
UPDATES:
Purpose: Service Quote Approval Process
*********************************************************/
try
{
// var sItemId = Inputs.GetProperty("Item Id");
var sQuoteId = Inputs.GetProperty("Quote Id");
var sCurInboxOwnerId = Inputs.GetProperty("CMI Inbox Owner Id");
var sActionLIC = Inputs.GetProperty("ActionLIC");
var bFinalPass = "Y";
var bAll = "N";
var sItemTaskStatus;
//ignore other actions for current record
if(sActionLIC != "Rejected" && sActionLIC != "Approved")
{
return;
}
var boInbox = TheApplication().GetBusObject("UInbox Items");
var bcInboxOwner = boInbox.GetBusComp("UInbox Item Task");
var nItemTaskNumber;
// make item inactive
with(bcInboxOwner)
{
ActivateField("Task Owner Id");
ActivateField("Active Flag");
ActivateField("Action");
ClearToQuery();
SetViewMode (AllView);
SetSearchSpec("Id",sCurInboxOwnerId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
SetFieldValue("Active Flag","N");
WriteRecord();
}
}
var bcQuote = TheApplication().GetBusObject("Quote").GetBusComp("Quote");
with(bcQuote)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Status");
//Changed "CMI Status" to "Status" by More Zhang on 18-May-11
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardOnly);
if(!FirstRecord())
return;
//only Awaiting Approval status quote can be approved
if(GetFieldValue("Status") != TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Awaiting Approval"))
//Changed "CMI Status" to "Status" by More Zhang on 18-May-11
return;
if(sActionLIC == "Rejected")
{
SetFieldValue("Status", TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Internal NotApproved"));
//Changed "CMI Status" to "Status" by More Zhang on 18-May-11
}
else if(sActionLIC == "Approved")
{
SetFieldValue("Status", TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Approved"));
//Changed "CMI Status" to "Status" by More Zhang on 18-May-11
}
WriteRecord();
}
}
catch(e)
{
var a = e.toString();
TheApplication().RaiseErrorText(a);
}
finally
{
bcQuote = null;
bcInboxOwner = null;
boInbox = null;
}
}

CMI ISS Approval Bus Service
QuoteReadySendMail
function QuoteReadySendMail(Inputs,Outputs)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS:
OUTPUTS:
Purpose: send mail to approvers for notification
DATE CREATED:
UPDATES:
Purpose:
*********************************************************/
var sQuoteId = Inputs.GetProperty("Quote Id");
//if invoked by runtime event, get quote id by profile
if(sQuoteId == "")
sQuoteId = TheApplication().GetProfileAttr("QuoteReadySendMailQuoetId");
var sProfile = ""; // for temporary use. need to update this when we get env
var sPackageList = "";
try
{
//analyse the parameter
var context_string = Inputs.GetProperty("Context");
var context_array = context_string.split(", ");
sProfile = context_array[1];
sProfile = sProfile.replace(/\"/g,'');
if(sProfile == "") sProfile = "DBUNextGen_CRP";
sPackageList = context_array[3];
sPackageList = sPackageList.replace(/\"/g,'');
if(sPackageList == "") sPackageList = "CMI Parts Quote Approval Notification";
var bsMail = TheApplication().GetService("Outbound Communications Manager");
var psIn = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();
psIn.SetProperty("CommProfileOverride", sProfile);
psIn.SetProperty("PackageNameList",sPackageList);
psIn.SetProperty("SourceIdList",sQuoteId);
psIn.SetProperty("RecipientGroup","Quote Contact");
bsMail.InvokeMethod("CreateRequest", psIn, psOut);
}
catch(e)
{
var test = e.toString();
TheApplication().RaiseErrorText(test);
}
finally
{
psIn=null;
psOut = null
bsMail = null;
sQuoteId =null;//added jj638 on 25may2011
}
}

CMI ISS Approval Bus Service
InactivateOwnerTask_Seq
function InactivateOwnerTask_Seq(Inputs, Outputs)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS:
OUTPUTS:
DATE CREATED:
UPDATES:
Purpose: //in sequential aproval, need to inactivate all approver's inbox message except for the first approver, and set approval sequence as well
*********************************************************/
try{
var sItemId;
var psApprover;
if(Inputs.GetChild(0).GetType() == "ItemOutput")//this child is inbox item return by UInbox service
{
sItemId = Inputs.GetChild(0).GetProperty("InboxItemId");
psApprover = Inputs.GetChild(1);
}
else if(Inputs.GetChild(1).GetType() == "ItemOutput")
{
sItemId = Inputs.GetChild(1).GetProperty("InboxItemId");
psApprover = Inputs.GetChild(0);
}
else
return;
var bcItemTask = TheApplication().GetBusObject("UInbox Item Task").GetBusComp("UInbox Item Task");
with (bcItemTask)
{
ClearToQuery();
ActivateField("CMI Sequence");
ActivateField("CMI Visiable Flag");
ActivateField("Task Owner Id");
SetViewMode(AllView);
SetSearchSpec("Item Id",sItemId);
ExecuteQuery(ForwardOnly);
var sCur = FirstRecord();
while (sCur)
{
var sOwnerId = GetFieldValue("Task Owner Id");
var sSeq = GetSeq(psApprover,sOwnerId);
SetFieldValue("CMI Sequence",sSeq);
if(sSeq == 0) //first approver will be displayed in Inbox
SetFieldValue("CMI Visiable Flag","Y");
else
SetFieldValue("CMI Visiable Flag","N");
WriteRecord();
sCur =NextRecord();
}
WriteRecord();
}
}catch(e){//added by jj638
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally{
bcItemTask = null;
}
}

CMI ISS Approval Bus Service
GetSeq
function GetSeq(Approvers, sApproverId)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS:
OUTPUTS:
DATE CREATED:
UPDATES:
Purpose: get approvers's sequence from Approvers according to his id
*********************************************************/
try{
var iReturn = 0;
var sProp = Approvers.GetFirstProperty();
while(iReturn < Approvers.GetChildCount())
{
if(Approvers.GetChild(iReturn).GetValue() == sApproverId)
{
return iReturn;
}
else
{
iReturn ++;
}
}
if(iReturn >= Approvers.GetChildCount()) // not found
return -1;
}catch(e){//added by jj638
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}finally{}
}

CMI ISS Approval Bus Service
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS:
OUTPUTS:
DATE CREATED:
UPDATES:
Purpose: Entry function
*********************************************************/
//try catch added by shanmukh for code clean up 08/19/2011
try
{
if(MethodName=="CheckApproval")
{
CheckApproval(Inputs,Outputs);
return CancelOperation;
}
if(MethodName == "GetApprovers")
{
GetApprovers(Inputs, Outputs);
return CancelOperation;
}
if(MethodName == "GetQuote")
{
GetQuote(Inputs, Outputs);
return CancelOperation;
}
if(MethodName == "CreateParams")
{
CreateParams(Inputs, Outputs);
return CancelOperation;
}
if(MethodName == "CheckAllApprovers")
{
CheckAllApprovers(Inputs, Outputs);
return CancelOperation;
}
if(MethodName == "CheckSequential")
{
CheckSequential(Inputs,Outputs);
return CancelOperation;
}
if(MethodName == "InactivateOwnerTask_Seq")
{
InactivateOwnerTask_Seq(Inputs,Outputs)
return CancelOperation;
}
if(MethodName == "SendMail")
{
SendMail(Inputs,Outputs)
return CancelOperation;
}
if(MethodName == "ServiceQuoteGA")
{
ServiceQuoteGA(Inputs,Outputs);
return CancelOperation;
}
if(MethodName == "ServiceApproval")
{
ServiceApproval(Inputs,Outputs);
return CancelOperation;
}
if(MethodName == "QuoteReadySendMail")
{
QuoteReadySendMail(Inputs,Outputs);
return CancelOperation;
}
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}//end of catch
return (ContinueOperation);
}

CMI ISS Approval Bus Service
GetPosLevelByType
function GetPosLevelByType(sPosType)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS: sPosId
OUTPUTS:
DATE CREATED:
UPDATES:
Purpose: get position level by its Type. Position Level is difined in LOV as Order By
*********************************************************/
try
{ //check input variable
if(sPosType == "")
return -1;
//get approval position level
// var bcLov = TheApplication().GetBusObject("List Of Values").GetBusComp("List Of Values");//Commented by ko981 on 12/16/2011
var bcLov = TheApplication().GetBusObject("List of Values Query").GetBusComp("List of Values Query");// From Oracle Review#17 Added by ko981 on 12/16/2011
with(bcLov)
{
ClearToQuery();
ActivateField("Value");
ActivateField("Order");
SetSearchSpec("Type", "CMI_APPROVAL_POS");
SetSearchSpec("Value", sPosType);
SetSearchSpec("Active", "Y");// From Oracle Review#17 Added by ko981 on 12/16/2011
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
return GetFieldValue("Order");
}
}
return -1;
}
catch(e)
{
return -1;
}
finally
{
bcLov = null;
}
}

CMI ISS Approval Bus Service
BuildApproverId
function BuildApproverId(sPosType, sApproverId, psApprovers)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS: sPosType, sApproverId, psApprovers
OUTPUTS: psApprovers
DATE CREATED: 31/Aug/2010
UPDATES:
Purpose: psApprovers will contain all approvers' Type initially. if sPosType occurs in psApprovers, need to set approver id to psApprovers
*********************************************************/
try{
var i = 0;
while(i < psApprovers.GetChildCount())
{
if(psApprovers.GetChild(i).GetType() == sPosType)
{
psApprovers.GetChild(i).SetValue(sApproverId);
break;
}
i++;
}
}catch(e){//added by jj638
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally{}
}

CMI ISS Approval Bus Service
GetQuote
function GetQuote(Inputs, Outputs)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS: Quote Id
OUTPUTS: Name,Primary Employee Pos Id,Sales Rep Position Id,Primary Employee Position Level
DATE CREATED:
UPDATES:
Purpose: get basic quote infomation from id
*********************************************************/
try{
var sQuoteId = Inputs.GetProperty("Quote Id");
var bcQuote = TheApplication().GetBusObject("Quote").GetBusComp("Quote");
with(bcQuote)
{
ActivateField("Name");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
Outputs.SetProperty("Name", GetFieldValue("Name"));
Outputs.SetProperty("Primary Employee Pos Id", GetFieldValue("Sales Rep Position Id"));
var sPosId = GetFieldValue("Sales Rep Position Id");
Outputs.SetProperty("Primary Employee Position Level",GetPosLevelById(sPosId));
}
}
}catch(e){//added by jj638
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally{
bcQuote = null;
}
}

CMI ISS Approval Bus Service
CheckAllApprovers
function CheckAllApprovers(Inputs, Outputs)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS:
OUTPUTS:
DATE CREATED: 31/Aug/2010
UPDATES:
Purpose: Invoked in wf CMI ISS Post Approval Workflow (Quote)
When one level approver approve the quote, need to check if the quote need furthre approval.
If yes, send a message to next level approver. Otherwise, set status to approved.
*********************************************************/
try
{
var sItemId = Inputs.GetProperty("Item Id");
var sQuoteId = Inputs.GetProperty("Quote Id");
var sSeq = Inputs.GetProperty("CMI Sequential Flag");
var sCurInboxOwnerId = Inputs.GetProperty("CMI Inbox Owner Id");
var sActionLIC = Inputs.GetProperty("ActionLIC");
var sLatestSeq = 0;
if(sSeq == "") sSeq = "Y";
var bFinalPass = "Y";
var bAll = "N";
var sItemTaskStatus;
//ignore other actions for current record
if(sActionLIC != "Rejected" && sActionLIC != "Approved")
{
return;
}
var boInbox = TheApplication().GetBusObject("UInbox Items");
var bcInboxOwner = boInbox.GetBusComp("UInbox Item Task");
var nItemTaskNumber;
var bcQuote = TheApplication().GetBusObject("Quote").GetBusComp("Quote");
with(bcQuote)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Status");
//Changed "CMI Status" to "Status" by More Zhang on 18-May-11
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardOnly);
// only qutoe with status = Awaiting Approval - Manager can be updated to new status
if(!FirstRecord())
return;
if(GetFieldValue("Status") != TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Awaiting Approval"))
//Changed "CMI Status" to "Status" by More Zhang on 18-May-11
return;
}
with(bcInboxOwner)
{
ActivateField("CMI Visiable Flag");
ActivateField("CMI Sequence");
ActivateField("Task Owner Id");
ActivateField("Active Flag");
ActivateField("Action");
ClearToQuery();
SetViewMode (AllView);
SetSearchSpec("Item Id",sItemId);
SetSortSpec("CMI Sequence(ASC)");
ExecuteQuery(ForwardOnly);
nItemTaskNumber = bcInboxOwner.CountRecords();
var curItem = FirstRecord();
var i = 0;
while(curItem)
{//check whether all records are approved.
if(sCurInboxOwnerId == GetFieldValue("Id"))
{
SetFieldValue("Action",TheApplication().InvokeMethod("LookupValue","UINBOX_STATUS_TYPE",sActionLIC));
SetFieldValue("Active Flag","N");
}
sItemTaskStatus = GetFieldValue("Action");
if(sItemTaskStatus == TheApplication().InvokeMethod("LookupValue","UINBOX_STATUS_TYPE","Rejected"))
{
bFinalPass = "N";
WriteRecord();
break;
}
else if(sItemTaskStatus == TheApplication().InvokeMethod("LookupValue","UINBOX_STATUS_TYPE","Approved"))
i = i+1;
//sequential logic: make it visiable to next approver
if(sSeq == "Y")// sequential approval logic
{
if(sCurInboxOwnerId == GetFieldValue("Id"))
{
sLatestSeq= parseInt(GetFieldValue("CMI Sequence"));
}
else if(parseInt(GetFieldValue("CMI Sequence")) == sLatestSeq + 1) //
{
SetFieldValue("CMI Visiable Flag","Y");
}
}
curItem = NextRecord();
}
//WriteRecord();
if(i == nItemTaskNumber && bFinalPass == "Y")
bcQuote.SetFieldValue("CMI Status", TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Approved"));
//Changed "Status" to "CMI Status" by JW919 on 22-July-11
//Changed "CMI Status" to "Status" by More Zhang on 18-May-11
if(bFinalPass == "N")
bcQuote.SetFieldValue("CMI Status", TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Internal NotApproved"));
//Changed "Status" to "CMI Status" by JW919 on 22-July-11
//Changed "CMI Status" to "Status" by More Zhang on 18-May-11
}
bcQuote.WriteRecord();
Outputs.SetProperty("Final Quote Status", bcQuote.GetFieldValue("Status"));
//Changed "CMI Status" to "Status" by More Zhang on 18-May-11
}
catch(e)
{
var a = e.toString();
TheApplication().RaiseErrorText(a);//added by JJ638 on May 25, 2011
}
finally
{
bcQuote = null;
bcInboxOwner = null;
boInbox = null;
}
}

CMI ISS Approval Bus Service
CheckApproval
function CheckApproval(Inputs,Outputs)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS: Message Code ,Appraise Pos Id
OUTPUTS: Pos Level ,Approval Needed Flag
DATE CREATED: 31/Aug/2010
UPDATES:
Purpose: get approval level according to message code
*********************************************************/
try
{
var sReturnCode = Inputs.GetProperty("Message Code");
var sAppraiseePosId = Inputs.GetProperty("Appraise Pos Id");
var sNeededAppLvl = "";
//get position level needed for approval
var boMsg = TheApplication().GetBusObject("FINS Validation History");
var bcMsg = boMsg.GetBusComp("ISS Validation Message");
with(bcMsg)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Pos Level");
SetSearchSpec("Message Source","Quote Approval");
SetSearchSpec("Message Level","Quote");
SetSearchSpec("Message Code",sReturnCode);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sNeededAppLvl = GetFieldValue("CMI Pos Level");
}
}
//no needed approval if current login level is high enough
if(parseInt(GetPosLevelById(sAppraiseePosId)) >= parseInt(sNeededAppLvl))
Outputs.SetProperty("Approval Needed Flag","N");
else
Outputs.SetProperty("Approval Needed Flag","Y");
Outputs.SetProperty("Pos Level", sNeededAppLvl);
}
catch(e)
{
throw(e);
}
finally
{
bcMsg = null;
boMsg = null;
sReturnCode = null;//added by jj638 on 25May2011
sAppraiseePosId =null;//added by jj638 on 25May2011
}
}

CMI ISS Approval Bus Service
CheckSequential
function CheckSequential(Inputs,Outputs)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS: Approval Level Name
OUTPUTS: Sequential
DATE CREATED:
UPDATES:
Purpose: check if the quote approval process is sequential
*********************************************************/
try{
Outputs.SetProperty("Sequential","Y");//set default to Sequential
var sApprovalName = Inputs.GetProperty("Approval Level Name");
if(sApprovalName == "")
{
return;
}
var bcApproval = TheApplication().GetBusObject("FINS Approval").GetBusComp("FINS Approval Level");
with (bcApproval)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Approval Hierarchy Type");
SetSearchSpec("Approval Level",sApprovalName);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var sApprovalType = GetFieldValue("Approval Hierarchy Type");
if(sApprovalType == TheApplication().InvokeMethod("LookupValue","APPROVAL_DECISION_TYPE","Parallel"))
Outputs.SetProperty("Sequential","N");
}
}
}catch(e){//added by jj638
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally{
bcApproval =null;
}
return;
}

CMI ISS Approval Bus Service
RemoveEmptyApproverId
function RemoveEmptyApproverId(psApprovers)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS:
OUTPUTS:
DATE CREATED:
UPDATES:
Purpose: Need to remove nodes whose approverid is blank from psApprovers in case some position does not have related user
*********************************************************/
try{
var i=0;
while(i < psApprovers.GetChildCount())
{
if(psApprovers.GetChild(i).GetValue() == "")
psApprovers.RemoveChild(i);
else
i++;
}
}catch(e){//added by jj638
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}finally{}
}

CMI ISS Approval Bus Service
F_LookupName
function F_LookupName(sType,sVal)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS: sType,sType
OUTPUTS:
DATE CREATED:
UPDATES:
Purpose: Get LIC according to Type and Value
*********************************************************/
try{
if(sType == "" || sVal == "")
return "";
var bcLov = TheApplication().GetBusObject("List Of Values").GetBusComp("List Of Values");
with(bcLov)
{
var sSearchSpec = "[Type] = '"+sType+"' and [Value] = '"+sVal+"' and [Language] = '"+ TheApplication().GetProfileAttr("Language")+"'";
ClearToQuery();
SetSearchExpr(sSearchSpec);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
return GetFieldValue("Name");
else
return "";
}
}catch(e){
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally
{
bcLov = null; //Added by shanmukh for code clean up 08/19/2011
}
}

CMI ISS Approval Bus Service
GetApprovers
function GetApprovers(Inputs,Outputs)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS: Appraisee Pos Id, Pos Level Needed,
OUTPUTS: All approvers' position type and user id
DATE CREATED:
UPDATES:
Purpose: get Appraisee and Appraiser position level
*********************************************************/
try{
var InputsCopy = Inputs.Copy();
var psAppraisees = TheApplication().NewPropertySet();
psAppraisees.SetType("Appraisee");
var sAppraiseePosId = InputsCopy.GetProperty("Appraisee Pos Id");
var sAppraiseeId = "";
var sPosLevel = InputsCopy.GetProperty("Pos Level Needed");
var sAppraiseeLvl = "";
var bcPosition = TheApplication().GetBusObject("Position").GetBusComp("Position");
with (bcPosition)
{
ActivateField("Division");
ActivateField("Position Type");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sAppraiseePosId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var sAppraiseePosType = GetFieldValue("Position Type");
sAppraiseeLvl = GetPosLevelByType(GetFieldValue("Position Type"));
var sDivision = GetFieldValue("Division");
var sDivisionId = GetFieldValue("Division Id");
sAppraiseeId = GetFieldValue("Primary Employee Id");
}
if (sAppraiseeLvl == "" ||sAppraiseePosType == "")
TheApplication().RaiseErrorText("Can NOT get Approval Level for user with position id:'"+sAppraiseePosId+"'");
}
//find all approver position types
// var boLOV = TheApplication().GetBusObject("List Of Values");//Commented by ko981 on 12/16/2011
// var bcLOV = boLOV.GetBusComp("List Of Values");//Commented by ko981 on 12/16/2011
var boLOV = TheApplication().GetBusObject("List of Values Query");// From Oracle Review#17 Added by ko981 on 12/16/2011
var bcLOV = boLOV.GetBusComp("List of Values Query");// From Oracle Review#17 Added by ko981 on 12/16/2011
with(bcLOV)
with(bcLOV)
{
ClearToQuery();
ActivateField("Value");
// SetSearchExpr("[Type] = 'CMI_APPROVAL_POS' AND [Order By] <= "+ sPosLevel +" And [Order By] > "+ sAppraiseeLvl);//Commented by ko981 on 12/16/2011
SetSearchExpr("[Type] = 'CMI_APPROVAL_POS' AND [Active] = 'Y' AND [Order] <= "+ sPosLevel +" And [Order] > "+ sAppraiseeLvl);// From Oracle Review#17 Added by ko981 on 12/16/2011
SetSortSpec("Order(ASC)");
ExecuteQuery(ForwardOnly);
var bHasRecord = FirstRecord();
// var Outputs = TheApplication().NewPropertySet();
while (bHasRecord)
{
//Send message to this position approver
var sPositionType = GetFieldValue("Value");
var psApprover = TheApplication().NewPropertySet();
psApprover.SetType(sPositionType);
psAppraisees.AddChild(psApprover);
bHasRecord = NextRecord();
}
}
//get appraisee's approval pos level from lov
var sPosId = sAppraiseePosId;
while (sPosId != "")
{
bcPosition.ActivateField("Parent Position Id");
bcPosition.ActivateField("CMI Parent Employee Id");
bcPosition.ActivateField("CMI Parent Position Type");
bcPosition.ClearToQuery();
bcPosition.SetViewMode(AllView);
bcPosition.SetSearchSpec("Id",sPosId);
bcPosition.ExecuteQuery(ForwardOnly);
if(bcPosition.FirstRecord())
{
var sParPosId = bcPosition.GetFieldValue("Parent Position Id");
var sParApproverId = bcPosition.GetFieldValue("CMI Parent Employee Id");
var sParPosType = bcPosition.GetFieldValue("CMI Parent Position Type");
BuildApproverId(sParPosType, sParApproverId, psAppraisees);
}
sPosId = sParPosId;
}
//locate branch manager as approver if needed
var sBranchManager = TheApplication().InvokeMethod("LookupValue","CMI_APPROVAL_POS","Branch Manager");
with(bcPosition)
{
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Division Id",sDivisionId);
SetSearchSpec("Position Type",sBranchManager);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
BuildApproverId(sBranchManager,GetFieldValue("Primary Employee Id"),psAppraisees);
}
//clear empty approvers from apprvoer list
RemoveEmptyApproverId(psAppraisees);
psAppraisees.SetProperty(sAppraiseePosType,sAppraiseeId);
//Outputs.AddChild(psApprovers);
psAppraisees.SetType("Approvers");
Outputs.AddChild(psAppraisees);
}catch(e)
{ if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally{
bcPosition = null ;
bcLOV = null;
boLOV = null;
//Added by shanmukh for code clean up 08/27/2011
psAppraisees = null;
psApprover = null;
}
}

CMI ISS Approval Bus Service
GetPosLevelById
function GetPosLevelById(sPosId)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS: sPosId
OUTPUTS:
DATE CREATED:
UPDATES:
Purpose: get position level by its id.
*********************************************************/
try
{
var sLevel = -1;
var bcPosition = TheApplication().GetBusObject("Position").GetBusComp("Position");
with(bcPosition)
{
ActivateField("Position Type");
ClearToQuery();
SetSearchSpec("Id", sPosId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sLevel = GetPosLevelByType(GetFieldValue("Position Type"));
}
}
return sLevel;
}
catch(e)
{
return -1;
}
finally
{
bcPosition = null;
}
}

CMI ISS Approval Bus Service
CreateParams
function CreateParams(Inputs,Outputs)
{
/*********************************************************
AUTHOR: build by jf344,
INPUTS:
OUTPUTS:
DATE CREATED:
UPDATES:
Purpose: create parameter which will be used for UInbox Service
*********************************************************/
try{
var psMessage = TheApplication().NewPropertySet();
psMessage.SetType("InboxInfo");
var psItem = TheApplication().NewPropertySet();
var psOwner ;
var psAppraisee = Inputs.GetChild(0);// appraisee info
psItem.SetType("InboxItemInfo");
psItem.SetProperty("ObjectId", Inputs.GetProperty("ObjectId"));
psItem.SetProperty("InboxName",Inputs.GetProperty("InboxName"));
psItem.SetProperty("InboxTypeName", Inputs.GetProperty("InboxTypeName"));
psItem.SetProperty("InboxPartyId", psAppraisee.GetProperty(psAppraisee.GetFirstProperty()));
var i=0;
while (i<psAppraisee.GetChildCount()) {
psOwner = TheApplication().NewPropertySet();
psOwner.SetType("InboxOwnerInfo");
psOwner.SetProperty("OwnerPartyId",psAppraisee.GetChild(i).GetValue());
psItem.AddChild(psOwner);
i++;
}
psMessage.AddChild(psItem);
Outputs.AddChild(psItem)
}catch(e){//added by jj638
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally{
psAppraisee = null;
psOwner = null;
psItem = null;
psMessage = null;
}
}

CMI Invoice Reconciliation Process BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation
switch (MethodName) {
case "ParseXML":
ParseXML (Inputs, Outputs);
break;
}
} catch(e){
Outputs.SetProperty("Error Code", "1");
Outputs.SetProperty("Error Message", e.message);
TheApplication().Utility.RaiseError(e);
} finally {
bcQuote = null;
boQuote = null;
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Invoice Reconciliation Process BS
Ret_UpdateQuantity
/***************************************************************************************************************
Created By : JF344
Created On : sOrderId4-Mar-2011
****************************************************************************************************************/
function Ret_UpdateQuantity(sOrderId, sSRId, sQuoteId, mainFound) {
try {
TheApplication().Utility.logStack("Ret_UpdateQuantity", this);
if(sOrderId == "" || sSRId == "") return;
var boOrder:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var bcOrder:BusComp = boOrder.GetBusComp("Order Entry - Orders");
var bcOrderItem:BusComp = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
var sLineType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Internal Return Line");
var bDeleteOrder = "";
var sZero = 0;
var found;
var sMainAssblyId = "";
//Get fields from the Quote in order to set them on the Order
var defaultInv = bcQuote.GetFieldValue("Source Inventory Location Id");
var divisionId = bcQuote.GetFieldValue("CMI Primary Division Id");
TheApplication().Utility.logVars("Default Inventory", defaultInv);
with(bcOrder) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Order ("+sOrderId+") found?", found);
if(found) {
//Update fields for Main assembly since it does not exist on the parts tracker
if (mainFound) {
with(bcOrderItem) {
ClearToQuery();
ActivateField("Destination Inventory Loc Id");
ActivateField("Source Inventory Loc Id");
ActivateField("Quantity Requested");
ActivateField("CMI Actual Quantity");
ActivateField("CMI Serial Number");
SetViewMode(AllView);
SetSearchSpec("CMI Main Assembly Flag", "Y");
SetSearchSpec("Order Header Id", sOrderId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Main Assembly on Order?", found);
if(FirstRecord()) {
sMainAssblyId = GetFieldValue("Id");
SetFieldValue("Quantity Requested", GetFieldValue("CMI Actual Quantity"));
TheApplication().Utility.logVars("Division Id ", divisionId);
//Changed the function from GetInventoryLocId LC657
SetFieldValue("Source Inventory Loc Id", GetDirtyInventoryLocId("WIP",divisionId));
SetFieldValue("Destination Inventory Loc Id", GetDirtyInventoryLocId("FG",divisionId));
WriteRecord();
}
}
}
}
}
var bcAction:BusComp = boQuote.GetBusComp("Action (Quote Order)");
var bcPartTracker:BusComp = boQuote.GetBusComp("FS Activity Parts Movement");
//Instantiate the Part Tracker and loop through each record to insure it exists on the return
//Order if the Picked Quantity is greater than the Used Quantity
with(bcAction) {
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker"));
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker Found?", found);
if(found) { //process part tracker
with(bcPartTracker) {
ClearToQuery();
ActivateField("Trunk Invloc Id");
ActivateField("Used Quantity");
ActivateField("CMI Parts Allocated");
ActivateField("CMI Return");
ActivateField("CMI Return Quantity");
ActivateField("CMI Unit of Measure");
SetViewMode(AllView);
ExecuteQuery(ForwardOnly);
var bHasRecord = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker Item Found?", bHasRecord);
while(bHasRecord) {
var sTrunkInvlocId = GetFieldValue("Trunk Invloc Id");
var sQtyUsed = GetFieldValue("Used Quantity");
var sReturn = GetFieldValue("CMI Return");
var sReturnQty = GetFieldValue("CMI Return Quantity");
var sQtyAllocated = GetFieldValue("CMI Parts Allocated");
var sQtyReturn = parseInt(sQtyAllocated) - parseInt(sQtyUsed);
var sOILId;
TheApplication().Utility.logVars("PT - Picked(P) / Used(U) / (P-U)",sQtyAllocated+" / "+sQtyUsed+" / "+sQtyReturn);
if(sQtyReturn <0) sQtyReturn = 0;
var sProdId = GetFieldValue("Product Id");
TheApplication().Utility.logStep(GetFieldValue("Product Name")+" ("+sProdId+") - Return: "+sReturnQty);
with(bcOrderItem) {
ClearToQuery();
ActivateField("Destination Inventory Loc Id");
ActivateField("Source Inventory Loc Id");
ActivateField("Quantity Requested");
ActivateField("CMI Serial Number");
//LC657 Added for Tkt#Tkt#INC000004816819
ActivateField("Covered Quote Item Id");
//Nag; 9/9/2013; Added for 1.2 release, Req# 77
ActivateField("CMI Parts Movement Picked Qty");
SetViewMode(AllView);
SetSearchExpr("[Product Id] = '" + sProdId + "' AND [Quantity Requested] = '" + sZero + "'");
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Line for Product Found?", found);
//If matching line item is found, update it, otherwise create a new record
if(FirstRecord()) {
sOILId = GetFieldValue("Id");
//LC657 Added for updating Picked qty for Rebuild items
var sCoveredQuoteItemId = GetFieldValue("Covered Quote Item Id");
TheApplication().Utility.logVars("MainAssemblyId / ParentOrderItemId / sQtyAllocated",sMainAssblyId+" / "+sCoveredQuoteItemId+" / "+sQtyAllocated);
if (sMainAssblyId != null && sMainAssblyId != "")
if (sMainAssblyId == sCoveredQuoteItemId) //Added this if condition to retain main Assembly LC657 Tkt#INC000004816819
{
Ret_UpdateMainAssembly(boOrder,bcOrder,sOrderId,sMainAssblyId, sOILId,sQtyAllocated,divisionId,mainFound);
}
//For Cores, find the linked dirty core line and update the qty or delete
if (sReturn != "") { //will either be 'No Return' or 'Core'
Ret_UpdateDirtyCore(sOrderId, sOILId, sReturnQty, sTrunkInvlocId, sReturn, divisionId,sQtyAllocated);
}
//If the order item is all used, there is no need show in the return order.
if(sQtyReturn == 0) {
DeleteRecord();
} else {
SetFieldValue("Source Inventory Loc Id", sTrunkInvlocId);
SetFieldValue("Destination Inventory Loc Id", defaultInv);
SetFieldValue("Quantity Requested", sQtyReturn);
//Nag; 9/9/2013; Added for 1.2 release, Req# 77
SetFieldValue("CMI Parts Movement Picked Qty", sQtyAllocated);
WriteRecord();
}
//} //end if sMainAssblyId
//Part Tracker item exists without corresponding Order Line. If Part Tracker line has a
//return quantity create the Return Order line item
} else if (sQtyReturn > 0) {
NewRecord(NewAfter);
SetFieldValue("CMI Actual Quantity",sQtyReturn);
SetFieldValue("Product Id",sProdId);
SetFieldValue("Quantity Requested",sQtyReturn);
SetFieldValue("Extended Quantity Requested",sQtyReturn);
SetFieldValue("Action Code", TheApplication().InvokeMethod("LookupValue", "DELTA_ACTION_CODE", "New"));
SetFieldValue("CMI Action Code", TheApplication().InvokeMethod("LookupValue", "DELTA_ACTION_CODE", "New"));
SetFieldValue("CMI Quantity Quoted", 0);
SetFieldValue("CMI Unit of Measure", bcPartTracker.GetFieldValue("CMI Unit of Measure"));
SetFieldValue("CMI Line Type","Service Internal Return Line");
SetFieldValue("Source Inventory Loc Id", sTrunkInvlocId);
SetFieldValue("Destination Inventory Loc Id", defaultInv);
//Nag; 9/9/2013; Added for 1.2 release, Req# 77
SetFieldValue("CMI Parts Movement Picked Qty", sQtyAllocated);
WriteRecord();
}
}
bHasRecord = NextRecord();
}
}
}
}
//Jn705: Added to delete the return order if no line item exists
with(bcOrderItem) {
ClearToQuery();
SetSearchSpec("Order Header Id", sOrderId);
ExecuteQuery(ForwardOnly);
bDeleteOrder = FirstRecord();
}
TheApplication().Utility.logVars("Order Items Found?", bDeleteOrder);
//Only query for the order if it is necessary to delete it
if(!bDeleteOrder) {
with(bcOrder) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Order ("+sOrderId+") found?", found);
if(found) {
DeleteRecord();
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPartTracker = null;
bcAction = null;
bcOrderItem = null;
bcOrder = null;
boOrder = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS
Gen_UpdateOrderItem
function Gen_UpdateOrderItem(bcOrderItem, orderId, prodId, sourceId, usedQty, serialNum, partTrkReturn, returnQty, quoteQty, priceListId, rebuild)
{
/*************************************************************************************************************************
Created By : ix964
Created On : 21-Dec-10
Functionality: Update each order line with correct quantities from the part tracker line
************************************************************************************************************************/
try {
TheApplication().Utility.logStack("Gen_UpdateOrderItem", this);
var sTotalQty = 0;
var sSearch = "";
var bErrorFlag = "N";
var sZERO = 0;
var sParentId="";//Added by KM330 for defect 2687
var sRootProductDef = "";//Added by KM330 for defect 2687
var bHasOrderItem;
var sStrSearch, mainAssembly;
var core = TheApplication().InvokeMethod("LookupValue", "CMI_RETURN", "Core");
var returnType = "";
var sOLIId;
//All Order Items are created with a 0 Actual Quantity from the signal except for Main assembly which
//takes the Quantity Requested from the quote. Query matches order lines created from quote by Product.
with(bcOrderItem) {
ActivateField("Adjusted List Price");
ActivateField("Net Price");
ActivateField("Line Number");
ActivateField("Cost");
ActivateField("Asset Id");
ActivateField("Product Id");
ActivateField("Quantity Requested");
ActivateField("Extended Quantity Requested");
ActivateField("CMI Actual Quantity");
ActivateField("CMI Serial Number");
ActivateField("CMI Quantity Quoted");
ActivateField("Destination Inventory Loc Id");
ActivateField("Source Inventory Loc Id");
ActivateField("CMI Return");
ActivateField("CMI Line Type");
ActivateField("Parent Order Item Id");
ActivateField("Root Product Def Type Code");
ActivateField("Covered Quote Item Id");
ActivateField("CMI Covered Main Assembly Flag");
ActivateField("CMI Main Assembly Flag");
ActivateField("CMI Product Return");
SetViewMode(AllView);
ClearToQuery();
sSearch = "[Product Id] = '" + prodId + "' AND [CMI Actual Quantity] = '" + sZERO + "' AND [Parent Order Item Id] IS NULL";
SetSearchExpr(sSearch);
ExecuteQuery(ForwardBackward);
bHasOrderItem = FirstRecord();
TheApplication().Utility.logVars("Line Found?", bHasOrderItem);
if(bHasOrderItem) {
returnType = GetFieldValue("CMI Product Return");
sParentId = GetFieldValue("Parent Order Item Id");
sRootProductDef = GetFieldValue("Root Product Def Type Code");
var sLineType = GetFieldValue("CMI Line Type");
var reconType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type");
var reconReturnType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type");
var noReturn = TheApplication().InvokeMethod("LookupValue", "CMI_RETURN", "No Return");
sOLIId = GetFieldValue("Id");
var covItemId = GetFieldValue("Covered Quote Item Id");
var covMainAsby = GetFieldValue("CMI Covered Main Assembly Flag");
TheApplication().Utility.logStep("Line "+GetFieldValue("Line Number")+" ("+sOLIId+") - Product Def/Parent Id: "+sRootProductDef+" / "+sParentId);
if((sRootProductDef!="Customizable" && sRootProductDef!= "Bundle") || (sParentId == null || sParentId == "")) {
SetFieldValue("Quantity Requested", usedQty);
SetFieldValue("Extended Quantity Requested", usedQty);
SetFieldValue("CMI Actual Quantity", usedQty);
SetFieldValue("CMI Return", partTrkReturn);
SetFieldValue("Source Inventory Loc Id", sourceId);
SetFieldValue("Destination Inventory Loc Id", ""); //Jq487: added for fixing defect 833
SetFieldValue("CMI Quantity Quoted", quoteQty);//By JQ487: for fixing defect 4827, 4831
TheApplication().Utility.logVars("Serial #", serialNum);
if (serialNum != "") {
SetFieldValue("CMI Serial Number", serialNum);
}
WriteRecord();
//For Core Parents and dirty Cores of a Main Assembly, find the related lines.
TheApplication().Utility.logVars("Product Return Type", returnType, "Covered Item - Id/Main Assembly", covItemId+" / "+covMainAsby);
if ((returnType == core) || (covItemId != "" && covMainAsby == "Y")) {
//For Main assembly's, parent is not on the Parts Tracker, just the Dirty Core
//Update Clean Core inventory by querying by product id of the dirty core
//Also need to include the Main Assembly in the query so quantity can be updated
if (covItemId != "" && covMainAsby == "Y") {
sStrSearch = "([Parent Order Item Id] = '" + covItemId + "' AND [Product Id] = '"+prodId+"') OR [Id] = '" + covItemId + "'";
} else {
//For non main assemblys, Query for the Recon Return and Recon related lines
sStrSearch = "[Covered Quote Item Id] = '" + sOLIId + "' OR [Parent Order Item Id] = '" + sOLIId + "'";
}
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr(sStrSearch);
ExecuteQuery(ForwardBackward);
bHasOrderItem = FirstRecord();
TheApplication().Utility.logVars("Dependent Line Found?", bHasOrderItem);
while(bHasOrderItem) {
c; // By: jv351 to fix defect 521/259/530
mainAssembly = GetFieldValue("CMI Main Assembly Flag");
sLineType = GetFieldValue("CMI Line Type");
//For non main assemblies, if the Return on Parts Tracker = No Return,
//the dirty core should be removed from the Sales Order. Otherwise just update
TheApplication().Utility.logVars("PT Return/Line Type/Main Asbly", partTrkReturn+" / "+sLineType+" / "+mainAssembly);
if(covMainAsby != "Y" && covItemId != "" &&
partTrkReturn == noReturn && sLineType == reconReturnType) {
DeleteRecord();
bHasOrderItem = FirstRecord();
} else {
Gen_ProcessDependentLines(bcOrderItem, sLineType, sourceId, mainAssembly,
covMainAsby, usedQty, returnQty, quoteQty);
bHasOrderItem = NextRecord();
}
}//end while (bHasOrderItem)
} //end if search for dependent lines
}//end if parent record or non customizeable product
} else {//can't find the Order Item so create a new one
var price = null;
var cost = null;
TheApplication().Utility.logVars("Price List Id", priceListId);
if(priceListId != "" && priceListId != null) {
var sOut = TheApplication().NewPropertySet();
Gen_GetPriceList(priceListId, prodId, sOut);
cost = sOut.GetProperty("Cost");
price = sOut.GetProperty("Price");
}
NewRecord(NewAfter);//crate new line item
SetFieldValue("CMI Serial Number", serialNum);
SetFieldValue("Quantity Requested", usedQty);
SetFieldValue("Extended Quantity Requested", usedQty);
SetFieldValue("CMI Actual Quantity", usedQty);
SetFieldValue("CMI Quantity Quoted", 0);
SetFieldValue("CMI Return", partTrkReturn);
if (price != null) {
SetFieldValue("Adjusted List Price", price);
SetFieldValue("Net Price", price);
}
if (cost != null) {
SetFieldValue("Cost", cost);
}
SetFieldValue("Source Inventory Loc Id", sourceId);
var bcPickProduct:BusComp = GetPicklistBusComp("Product");
with(bcPickProduct) {
SetViewMode(AllView);
ActivateField("CMI Return");
ClearToQuery();
SetSearchSpec("Product ID", prodId);
ExecuteQuery(ForwardBackward);
var haveProduct = FirstRecord();
TheApplication().Utility.logVars("Product Found?", haveProduct);
if(haveProduct) {
returnType = GetFieldValue("CMI Return");
Pick();
}
}//end with
//THere is a WriteRecord at the conculsion of WriteRecord
Gen_ProcessLine(bcOrderItem, rebuild)
// WriteRecord();
//Check if the Part Tracker item added is a core
TheApplication().Utility.logVars("Product Return Type", returnType);
if (returnType == core) {
//If a Core, need to add clean/dirty core items to the order
sOLIId = GetFieldValue("Id");
TheApplication().SetProfileAttr("Order Line Item Id", sOLIId);
TheApplication().SetProfileAttr("Order Id", orderId);
var svc = TheApplication().GetService("CMI Add Core Product");
svc.InvokeMethod("AddCoreOrder", TheApplication().NewPropertySet(), TheApplication().NewPropertySet());
var sStrElseSearch = "[Covered Quote Item Id] = '" + sOLIId + "' OR [Parent Order Item Id] = '" + sOLIId + "'";
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr(sStrElseSearch);
ExecuteQuery(ForwardBackward);
bHasOrderItem = FirstRecord();
TheApplication().Utility.logVars("Clean/Dirty Lines Found", bHasOrderItem);
while(bHasOrderItem) {
sLineType = GetFieldValue("CMI Line Type");
//If the Return on Parts Tracker = No Return, the dirty core should be removed
//from the Sales Order. Otherwise just update
TheApplication().Utility.logVars("PT Return/Line Type", partTrkReturn+" / "+sLineType);
if(partTrkReturn == noReturn && sLineType == reconReturnType) {
DeleteRecord();
bHasOrderItem = FirstRecord();
} else {
Gen_ProcessDependentLines(bcOrderItem, sLineType, sourceId, "", "",
usedQty, returnQty, quoteQty);
bHasOrderItem = NextRecord();
}
}//end while (bHasOrderItem)
} //end if core added
}//end else (order item not found)
}//end with(bcOrderItem)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPickProduct=null;
sOut = null;
svc = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS
Ret_UpdateDirtyCore
//Added by KM326 for 4455 on 22/11/2011
// This function is used to update or delete the dirty core created via datamap depending upon
// the CMI Return and CMI Return Quantity field values in Parts Tracker
function Ret_UpdateDirtyCore(sOrderId, sOILId, sReturnQty, sTrunkInvlocId, sReturn, divisionId,sQtyAllocated)
{
try {
TheApplication().Utility.logStack("Ret_UpdateDirtyCore", this);
var oBOOrderDirty:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var OBCOrderItemDirty:BusComp = oBOOrderDirty.GetBusComp("Order Entry - Line Items (Simple)");
var sCore = TheApplication().InvokeMethod("LookupValue", "CMI_RETURN", "Core");
var found;
with(OBCOrderItemDirty) {
ActivateField("Quantity Requested");
ActivateField("Source Inventory Loc Id");
ActivateField("Destination Inventory Loc Id");
ActivateField("CMI Parts Movement Picked Qty");
ClearToQuery();
SetSearchSpec("Order Header Id",sOrderId);
SetSearchSpec("Covered Quote Item Id",sOILId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Dirty Core Line Found?", found);
if(found) {
TheApplication().Utility.logVars("Return - Type/Qty", sReturn+" / "+sReturnQty);
if(sReturn == sCore && sReturnQty != 0) {
SetFieldValue("Source Inventory Loc Id", sTrunkInvlocId);
SetFieldValue("Destination Inventory Loc Id", GetDirtyInventoryLocId("Dirty Core",divisionId));
SetFieldValue("Quantity Requested", sReturnQty);
//LC657 CQ#12382
SetFieldValue("CMI Parts Movement Picked Qty", sQtyAllocated);
WriteRecord();
} else {
DeleteRecord();
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
OBCOrderItemDirty = null;
oBOOrderDirty = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS
Ret_QuoteToReturnOrder
/***************************************************************************************************************
Created By : JF344
Created On : 28-Feb-11
C&I Number :
Requirement # :
Method Name: uoteToReturnOrder
Functionality:
Input: None
Output: None
Customization Approval #: NA
******************************************************************************************************************/
function Ret_QuoteToReturnOrder(sQuoteId)
{
try {
TheApplication().Utility.logStack("Ret_QuoteToReturnOrder", this);
//Use the global source quote object which is already instantiated
var bcQuoteItem:BusComp = boQuote.GetBusComp("Quote Item (Simple)");
var bcAction:BusComp = boQuote.GetBusComp("Action (Quote Order)");
var bcPartsTracker:BusComp = boQuote.GetBusComp("FS Activity Parts Movement");
var sPartsTracker = TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker");
var createReturnOrder = false;
var quoteFound = false;
var found = false;
var mainFound = false;
//If the Quote has a Main Assembly, a return order must be created for it regardless of Parts Tracker
//Quantities
with(bcQuoteItem) {
SetViewMode(AllView);
ActivateField("Extended Quantity Requested");
ClearToQuery();
SetSearchSpec("CMI Main Assembly Flag","Y");
ExecuteQuery(ForwardOnly);
mainFound = FirstRecord();
TheApplication().Utility.logVars("Main Assembly found?", mainFound);
}
//if no Main Assembly present, determine if Return order is needed by checking used qty on parts tracker
if (!mainFound) {
with(bcAction) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Type", sPartsTracker);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker found?", found);
if(found) {
with(bcPartsTracker) {
ActivateField("CMI Parts Allocated");
ActivateField("Used Quantity");
ActivateField("CMI Return Quantity");
SetViewMode(AllView);
ClearToQuery();
ExecuteQuery(ForwardOnly);
var sHaveParts = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker Item found?", sHaveParts);
while(sHaveParts) {
var sPickedQty = GetFieldValue("CMI Parts Allocated");
var sUsedQty = GetFieldValue("Used Quantity");
//Added by KM326 for 4455 on 22/11/2011
var sReturnQuantity = GetFieldValue("CMI Return Quantity");
TheApplication().Utility.logVars("Used/Picked/Return", sUsedQty+" / "+sPickedQty+" / "+sReturnQuantity);
if(ToNumber(sUsedQty) < ToNumber(sPickedQty) || sReturnQuantity != 0) {//|| sReturnQuantity != 0 by KM326 for 4455 on 22/11/2011
createReturnOrder = true;
sHaveParts = false;
} else sHaveParts = NextRecord();
}//while(sHaveParts)
}//with(bcPartsTracker)
}//if(FirstRecord())
}// with(bcAction)
}
TheApplication().Utility.logVars("Create Return Order", createReturnOrder);
if(createReturnOrder || mainFound) {
var sSRId = bcQuote.GetFieldValue("Service Request Id");
//lc657 CQ#12328
TheApplication().SetProfileAttr("CMIReturnOrderCreation", "Y");
//Set a profile attribute to prevent the refresh in the signal when called from script
TheApplication().SetProfileAttr("SkipRefresh", "TRUE");
bcQuote.InvokeMethod("AutoOrderReturnQuote");
Ret_UpdateQuantity(TheApplication().GetSharedGlobal("DTUSharedGlobalDestId"),sSRId, sQuoteId, mainFound);
}//end if(createReturnOrder)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcQuoteItem = null;
bcAction = null;
bcPartsTracker = null;
TheApplication().SetProfileAttr("SkipRefresh", "");
TheApplication().SetProfileAttr("CMIReturnOrderCreation", "");
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS
Respec_UpdateOrderLine
function Respec_UpdateOrderLine(sOrderId)
{
/*******************************************************************************************
Created By :<JQ487>
Created On : <08/02/2011>
Method Name:AddLabor
C&I Number: 4657
Requirement #: Enhancement S138
Functionality: This BS will query for Time Tracker records in Service labor activity and based on
technicians billable product will create a new labor record with product same as billable product
from technician. also it queries the quote, from which order is generated, for labor line items
and adds the sum of their Requested Quantity to "Quoted Quantity" of first labor record in Order.
Input:
Output:
****************************************************************************************** */
try{
TheApplication().Utility.logStack("Respec_UpdateOrderLine", this);
var bcQuoteItem:BusComp = boQuote.GetBusComp("Quote Item (Simple)");
var boOrder:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var bcOrder:BusComp = boOrder.GetBusComp("Order Entry - Orders");
var bcOrderItem:BusComp = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
var bcAction:BusComp = boQuote.GetBusComp("Action (Quote Order)");
var bcProduct:BusComp;
var sSRId:String = "";
var sActionId:String = "";
var sQtySum:Number = 0;
var sProdType:String = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
var sRbtResource = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Rebuild Resource");
//Adde by KM326 to fix 721/651 on 02-12-2011
var sPrevTotalDurHr = 0;
var sPrevTotalCost = 0;
var prevOwnerId = "";
var sOwnerId:String = "";
//Querying Quote Item BC to Sum the total of the Requested Quantity for all labor lines on the quote and storing in a variable
with(bcQuoteItem) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("Product");
ActivateField("Quantity Requested");
SetSearchSpec("Product Type", sProdType);
ExecuteQuery(ForwardBackward);
var isRec = FirstRecord();
TheApplication().Utility.logVars("First Labor Item found?", isRec);
while(isRec) {
var sQty = GetFieldValue("Quantity Requested");
TheApplication().Utility.logStep("Add "+GetFieldValue("Product")+" Hours: "+sQty+" + "+sQtySum);
sQtySum += ToNumber(sQty);
isRec = NextRecord();
}//end while(isRec)
}//end with(bcQuoteItem)
//Instantiate the order. When Order lines for billing products are created, certain values will predefault from the header
with(bcOrder) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
var orderFound = FirstRecord();
TheApplication().Utility.logVars("Order ("+sOrderId+") found?", orderFound);
}//end with(bcOrder)
//Find the Service Labor activity based on Quote ID
with(bcAction) {
SetViewMode(AllView);
ActivateField("Rate List Id");
ActivateField("CMI Owner FullName");
ClearToQuery();
SetSortSpec("Primary Owner Id(ASCENDING)"); //KM326 to fix bug 721/651 on 02-12-2011
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Service Labor"));
ExecuteQuery(ForwardBackward);
var isRec1 = FirstRecord();
while(isRec1) {
TheApplication().Utility.logStep("Service Labor Activity ("+GetFieldValue("Id")+") Owner: "+GetFieldValue("CMI Owner FullName"));
sOwnerId = GetFieldValue("Primary Owner Id");
if (prevOwnerId != sOwnerId && sOwnerId != "") {
prevOwnerId = sOwnerId;
Respec_CheckPosition(sOwnerId, GetFieldValue("Rate List Id"));
}
if(sProdId == null || sProdId == "") {
isRec1 = bcAction.NextRecord();
} else {
Respec_TimeTrackerCheck(GetFieldValue("Id"));
if(orderFound) {
with(bcOrderItem) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("Product");
ActivateField("CMI Price Override");
ActivateField("Quantity Requested");
ActivateField("Extended Quantity Requested");
ActivateField("Cost");
ActivateField("Net Price");
ActivateField("Product Id");
ActivateField("CMI Line Type");
ActivateField("CMI Actual Quantity");
ActivateField("Unit Price");
SetSearchSpec("Product Id", sProdId);
ExecuteQuery(ForwardOnly);
var olisRec = FirstRecord();
TheApplication().Utility.logVars("Order Line found?", olisRec);
//For subsequent Service Labor activities, the billing product line will just need to be updated
if(olisRec) {
sPrevTotalDurHr = sPrevTotalDurHr + sTotalDurHr;
sPrevTotalCost = sPrevTotalCost + sTotalCost;
//Updating the quantity field on the labor item with the sum of
//the duration field from the time tracker record
SetFieldValue("CMI Actual Quantity", ToNumber(sPrevTotalDurHr));
SetFieldValue("Quantity Requested", ToNumber(sPrevTotalDurHr));
SetFieldValue("Extended Quantity Requested", ToNumber(sPrevTotalDurHr));
//Updating the cost and Manual Price Override on the labor item
//with the cost field from the time tracker record
SetFieldValue("CMI Price Override", ToNumber(sPrevTotalCost));
SetFieldValue("Cost", ToNumber(sCostListCost));
SetFieldValue("Net Price", ToNumber(sCostListCost));
SetFieldValue("Unit Price", ToNumber(sCostListCost));
sCost = 0;
sDurHr = 0;
sTotalCost = 0;
sTotalDurHr = 0;
sProdId = "";
isRec1 = bcAction.NextRecord();
} else {
//The first time each Billing Product is found, a new order line will be created
NewRecord(NewAfter);
bcProduct = GetPicklistBusComp("Product");
with(bcProduct) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Product ID", sProdId);
ExecuteQuery(ForwardOnly);
var isPickBCRec = FirstRecord();
if(isPickBCRec) Pick();
}//end with(sProd)
//Updating the quantity field on the labor item with the sum of
//the duration field from the time tracker record
SetFieldValue("CMI Actual Quantity", ToNumber(sTotalDurHr));
SetFieldValue("Quantity Requested", ToNumber(sTotalDurHr));
SetFieldValue("Extended Quantity Requested", ToNumber(sTotalDurHr));
//Updating the cost and Manual Price Override on the labor item
//with the cost field from the time tracker record
SetFieldValue("CMI Price Override", sTotalCost);
SetFieldValue("Cost", ToNumber(sCostListCost));
SetFieldValue("Net Price",ToNumber(sCostListCost));//added by km330 for defect 651,on 30/11/2011
SetFieldValue("Unit Price", ToNumber(sCostListCost));
SetFieldValue("CMI Line Type", sRbtResource);
WriteRecord();
sPrevTotalDurHr = sTotalDurHr;
sPrevTotalCost = sTotalCost;
sCost = 0;
sDurHr = 0;
sTotalCost = 0;
sTotalDurHr = 0;
sProdId = "";
isRec1 = bcAction.NextRecord();
}//end else
}//end with(bcOrderItem)
}//end if
}
}//end While
}//end (bcAction)
//Querying Order Item BC again to Update the field Quoted
//Quantity on first labor line that was added via the previous
//step with the total of the requested quantity
with(bcOrderItem) {
SetViewMode(AllView);
ActivateField("Order Header Id");
ActivateField("CMI Quantity Quoted");
ActivateField("CMI Order Status");
ClearToQuery();
SetSearchSpec("Order Header Id", sOrderId);
SetSearchSpec("Product Type", TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor"));
ExecuteQuery(ForwardBackward);
TheApplication().Utility.logVars("Labor Line found?", FirstRecord());
if(FirstRecord()) {
SetFieldValue("CMI Quantity Quoted", sQtySum);
WriteRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcProduct = null;
bcAction = null;
bcQuoteItem = null;
bcOrder = null;
bcOrderItem = null;
boOrder = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS
Respec_TimeTrackerCheck
function Respec_TimeTrackerCheck(sSerLabId)
{
/*******************************************************************************************
Created By :<JQ487>
Created On : <08/02/2011>
Method Name:AddLabor
C&I Number: 4657
Requirement #: Enhancement S138
Functionality: This BS will query for Time Tracker records in Service labor activity
Input:
****************************************************************************************** */
try{
TheApplication().Utility.logStack("Respec_TimeTrackerCheck", this);
var boAction:BusObject = TheApplication().GetBusObject("Action");
var bcTimeSheetHrs:BusComp = boAction.GetBusComp("Time Sheet Daily Hours");
with(bcTimeSheetHrs) {
SetViewMode(AllView);
ActivateField("Time Cost");
ActivateField("CMI Time Cost - Calc");
ActivateField("Elasped Time in Hours");
ActivateField("Elasped Time in Time");
ClearToQuery();
SetSearchSpec("Activity Id", sSerLabId);
ExecuteQuery(ForwardBackward);
var isRec = FirstRecord();
while(isRec) {//this loop will sum the Duration and Cost on Time tracker record and will update it on Labor record on order item
sCost = GetFieldValue("Time Cost");
sDurHr = GetFieldValue("Elasped Time in Hours");
TheApplication().Utility.logVars("Elasped Hours / Time / Cost / Converted", GetFieldValue("Elasped Time in Hours")+" / "+
GetFieldValue("Elasped Time in Time")+" / "+GetFieldValue("Time Cost")+" / "+GetFieldValue("CMI Time Cost - Calc"));
sTotalCost = ToNumber(sTotalCost) + ToNumber(sCost);
sTotalDurHr = ToNumber(sTotalDurHr) + ToNumber(sDurHr);
isRec = NextRecord();
}
}//end (bcOrder)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
boAction = null;
bcTimeSheetHrs = null;
TheApplication().Utility.logUnstack(sTotalDurHr+" / "+sTotalCost);
}
}

CMI Invoice Reconciliation Process BS
Respec_CheckPosition
function Respec_CheckPosition(sOwnerId, sRateListId)
{
/*******************************************************************************************
Created By :<JQ487>
Created On : <08/02/2011>
Method Name:AddLabor
C&I Number: 4657
Requirement #: Enhancement S138
Functionality: This BS will query for Billable product associated with Technician.
****************************************************************************************** */
try{
TheApplication().Utility.logStack("Respec_CheckPosition", this);
var boPosition:BusObject = TheApplication().GetBusObject("Position");
var bcPosition:BusComp = boPosition.GetBusComp("Position");
var boRateList:BusObject = TheApplication().GetBusObject("PS Rate List");
var bcRateList:BusComp = boRateList.GetBusComp("PS Rate List");
var boCostList:BusObject = TheApplication().GetBusObject("Cost List");
var bcCostList:BusComp = boCostList.GetBusComp("Cost List");
var bcCostListItem:BusComp = boCostList.GetBusComp("Cost List Item");
var sCostListId = "";
var product;
// TheApplication("Test Active Position", TheApplication().PositionName()+" ("+TheApplication().PositionId()+")");
with(bcPosition) {
SetViewMode(AllView);
ActivateField("Billing Product Id");
ActivateField("Billing Product");
ClearToQuery();
SetSearchSpec("Employee Id", sOwnerId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Position for Employee("+sOwnerId+") found?", FirstRecord());
if(FirstRecord()) {
//modified by km326 for C&I 4657 on 08-12-2011
product = GetFieldValue("Billing Product");
sProdId = GetFieldValue("Billing Product Id");
//commented by km326 for C&I 4657 on 08-12-2011
}
}//end (bcPosition)
TheApplication().Utility.logVars("Product (Id)", product+" ("+sProdId+")");
if(sProdId != null && sProdId != "") {
with(bcRateList) {
SetViewMode(AllView);
ActivateField("Cost List Id");
ClearToQuery();
SetSearchSpec("Id", sRateListId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Rate List ("+sRateListId+") found?", FirstRecord());
if(FirstRecord()) {
sCostListId = GetFieldValue("Cost List Id");
with(bcCostList) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sCostListId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Cost List ("+sCostListId+") found?", FirstRecord());
if(FirstRecord()) {
with(bcCostListItem) {
SetViewMode(AllView);
ActivateField("Product Id");
ActivateField("Standard Cost");
ClearToQuery();
SetSearchSpec("Price List Id", sCostListId);
SetSearchSpec("Product Id", sProdId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("First Cost Item found?", FirstRecord());
if(FirstRecord()) {
sCostListCost = GetFieldValue("Standard Cost");
}
}
}
}
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPosition = null;
boPosition = null;
bcCostListItem = null;
bcRateList = null;
bcCostList = null;
boRateList = null;
boCostList = null;
TheApplication().Utility.logUnstack(sCostListCost);
}
}

CMI Invoice Reconciliation Process BS
ParseXML
function ParseXML(Inputs, Outputs)
{
/*********************************************************
AUTHOR: JU982,
C&I:4469
Enhancement: S126,146
DESCRIPTION: The below function will parse Siebel message returned from ILog and pass Quote Id to Generate Order function
DATE CREATED: 11 Sep 2011
*********************************************************/
try {
TheApplication().Utility.logStack("ParseXML", this);
var psPSR = TheApplication().NewPropertySet();
var psRSR = TheApplication().NewPropertySet();
var psQuote = TheApplication().NewPropertySet();
var sInput = TheApplication().NewPropertySet();
var sOutput = TheApplication().NewPropertySet();
var sPendingInvoice:String = TheApplication().InvokeMethod("LookupValue" ,"SR_SUB_STATUS", "Pending Invoice");
var oSRBO:BusObject = TheApplication().GetBusObject("Service Request");
var oSRBC:BusComp = oSRBO.GetBusComp("Service Request");
var sPSRId = Inputs.GetProperty("CMI Parent SR Id");
var sInvokeLevel = Inputs.GetProperty("CMI Invoke Level");
var sRSRId;
var cntRSR;
var cntQuote;
var sQuoteId;
//Initialize outputs
Outputs.SetProperty("Error Code", "");
Outputs.SetProperty("Error Message", "");
var svc = TheApplication().GetService("Workflow Process Manager");
psRSR = Inputs.GetChild(0).GetChild(0).GetChild(0).GetChild(0);
cntRSR = psRSR.GetChildCount();
for(i=0; i<cntRSR ; i++) {
sRSRId = psRSR.GetChild(i).GetProperty("Id");
psQuote = psRSR.GetChild(i).GetChild(0);
cntQuote = psQuote.GetChildCount();
for(j=0; j<cntQuote; j++) {
sQuoteId = psQuote.GetChild(j).GetProperty("Id");
// Call Generate order BS function and pass Quote id as an input;
GenerateOrderQuote (sQuoteId);
}
// Update RSR status to Pending For Invoice
// Added sInvokeLevel == "Parent SR" to fix defect 527 by ju982 on 11152011
if(sInvokeLevel == "Related SR" || sInvokeLevel == "Parent SR") {
sInput.SetProperty("ProcessName", "CMI Update SR Sub Status and IRN");
sInput.SetProperty("Object Id", sRSRId);
sInput.SetProperty("CMI SR Sub Status", sPendingInvoice);
sInput.SetProperty("CMI IRN Flag", "N");
svc.InvokeMethod("RunProcess", sInput, sOutput);
}// End of If sInvokeLevel= Related SR
}// end of for i loop
// Update PSR sub status
if(sInvokeLevel == "Parent SR") {
sInput = TheApplication().NewPropertySet();
sOutput = TheApplication().NewPropertySet();
sInput.SetProperty("ProcessName", "CMI Update SR Sub Status and IRN");
sInput.SetProperty("Object Id", sPSRId);
sInput.SetProperty("CMI SR Sub Status", sPendingInvoice);
sInput.SetProperty("CMI IRN Flag", "N");
svc.InvokeMethod("RunProcess", sInput, sOutput);
}// End of If sInvokeLevel= Parent SR
} catch(e){
// TheApplication().Utility.logStep("ParseXML");
TheApplication().Utility.RaiseError(e);
} finally {
oSRBC=null;
sInvokeLevel=null;
psPSR = null;
psRSR = null;
psQuote = null;
sInput = null;
sOutput = null;
oSRBO=null;
svc = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS
GetInventoryLocId
function GetInventoryLocId(inventoryType,divisionId) {
try {
TheApplication().Utility.logStack("GetInventoryLocId", this, 4);
var boInventory:BusObject = TheApplication().GetBusObject("FS Inventory Location Mgmt");
var bcInventory:BusComp = boInventory.GetBusComp("FS Inventory Location");
var sInvLocId = "";
with(bcInventory) {
SetViewMode(AllView);
ActivateField("Inventory Type");
ActivateField("Primary Organization Id");
ClearToQuery();
SetSearchSpec("Inventory Type", inventoryType);
SetSearchSpec("Primary Organization Id", divisionId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
sInvLocId = GetFieldValue("Id");
TheApplication().Utility.logVars(inventoryType+" - Inventory Location Id", sInvLocId);
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcInventory = null;
boInventory = null;
TheApplication().Utility.logUnstack(sInvLocId, 4);
}
return (sInvLocId);
}

CMI Invoice Reconciliation Process BS
GetDirtyInventoryLocId
function GetDirtyInventoryLocId(inventoryType,divisionId) {
try {
TheApplication().Utility.logStack("GetDirtyInventoryLocId", this, 4);
var boInventory:BusObject = TheApplication().GetBusObject("FS Inventory Location Mgmt");
var bcInventory:BusComp = boInventory.GetBusComp("FS Inventory Location");
var sInvLocId = "";
with(bcInventory) {
SetViewMode(AllView);
ActivateField("Inventory Type");
ActivateField("CMI Primary Division Id");
ClearToQuery();
SetSearchSpec("Inventory Type", inventoryType);
SetSearchSpec("CMI Primary Division Id", divisionId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
sInvLocId = GetFieldValue("Id");
TheApplication().Utility.logVars(inventoryType+" - Inventory Location Id", sInvLocId);
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcInventory = null;
boInventory = null;
TheApplication().Utility.logUnstack(sInvLocId, 4);
}
return (sInvLocId);
}

CMI Invoice Reconciliation Process BS
GenerateOrderQuote
function GenerateOrderQuote(sQuoteId)
{
/*********************************************************
AUTHOR: JQ487,
C&I:4469
Enhancement: S126,147
DESCRIPTION: The below function will call CMI Invoice Reconciliation Create Order WF based on
Quote Id passed as in input to this function
DATE CREATED: 09 Sep 2011
*********************************************************/
try {
TheApplication().Utility.logStack("GenerateOrderQuote", this);
/* var sWFMgr = TheApplication().GetService("Workflow Process Manager");
var sInput = TheApplication().NewPropertySet();
//MJB 6/4/12 The wrapper service was part of an old design that had the capability to reexecute
//the generate order process if an error occurred in the middle. This service will now roll back
//If an error occurs so it is unnecessary and will be faster to skip it
// sInput.SetProperty("ProcessName","CMI Invoice Reconciliation Create Order Wrapper WF");
sInput.SetProperty("ProcessName","CMI Invoice Reconciliation Create Order WF");
sInput.SetProperty("Object Id", sQuoteId);
sWFMgr.InvokeMethod("RunProcess", sInput, Outputs);
*/
var boOrder:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var bcOrder:BusComp = boOrder.GetBusComp("Order Entry - Orders");
var found = false;
//Create the Order via Data Map
var sOrderId = Gen_QuoteToOrder(sQuoteId);
//Instantiate the newly created order activating any necessary fields
found = Gen_InstantiateOrder(sOrderId, boOrder, bcOrder);
if(found) {
//Sync the Order lines with the Parts Tracker
Gen_UpdateLineType(boOrder, bcOrder, sOrderId);
}
//If there is a main assembly or Part Tracker items with a Used Qty less than the Picked Qty, create a Return Order
Ret_QuoteToReturnOrder(sQuoteId);
//Delete lines from the sales order that after syncing with the parts tracker ended up with a 0 Actual Qty
CheckOrderPartsNotUsed(sOrderId);
//For Respec SRs, the actual hours clocked against the service labor activities need to be determined
//to update the labor quantity on the order for each Technician billing product used
var srSubType = bcQuote.GetFieldValue("CMI SR Sub Type");
TheApplication().Utility.logVars("SR Sub Type", srSubType);
if (srSubType == "Respec") {
Respec_UpdateOrderLine(sOrderId);
}
//Once all changes to the order are made, refresh the stamped order total
if(found) {
bcOrder.InvokeMethod("SetRefreshRollups")
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcOrder = null;
boOrder = null;
// sInput = null;
// sWFMgr = null;
TheApplication().Utility.logUnstack(sOrderId);
}
}

CMI Invoice Reconciliation Process BS
Ret_UpdateMainAssembly
function Ret_UpdateMainAssembly(boOrder,bcOrder,sOrderId,sMainAssblyId, sOILId,sQtyAllocated,divisionId,mainFound)
{
TheApplication().Utility.logStack("Ret_UpdateMainAssembly", this);
try {
var boOrderMainAsbly:BusObject = TheApplication().GetBusObject("Order Entry");
var bcOrderHeaderAsbly:BusComp = boOrderMainAsbly.GetBusComp("Order Entry - Orders");
var oOrderLinesMainAsbly:BusComp = boOrderMainAsbly.GetBusComp("Order Entry - Line Items (Simple)");
var sfound;
with (bcOrderHeaderAsbly)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
with (oOrderLinesMainAsbly)
{
ClearToQuery();
ActivateField("CMI Parts Movement Picked Qty");
SetViewMode(AllView);
//SetSearchSpec("CMI Main Assembly Flag", "Y");
SetSearchSpec("Id", sMainAssblyId);
ExecuteQuery(ForwardOnly);
sfound = FirstRecord();
TheApplication().Utility.logVars("Main Assembly Line on Order?", sfound);
if(sfound) {
SetFieldValue("CMI Parts Movement Picked Qty", sQtyAllocated);
WriteRecord();
}
}
}
}
} //end try
catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oOrderLinesMainAsbly = null;
bcOrderHeaderAsbly = null;
boOrderMainAsbly = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS
Gen_UpdatePartsOnOrder
/******************************************
Created By : IX964
Created On : Dec 21, 2011
Method Name: UpdatePartsOnOrder
C&I Number:
Requirement #:
Functionality: This method is to update order part line item with parts movement data.
Input: OrderId, QuoteNumber
Output:
******************************************/
function Gen_UpdatePartsOnOrder(boAction, bcAction, boOrder, bcOrder, sOrderId) {
try {
TheApplication().Utility.logStack("Gen_UpdatePartsOnOrder", this);
var bcActionParts = boAction.GetBusComp("FS Activity Parts Movement");
var bcOrderItem = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
with(bcActionParts) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("Product Name");
ActivateField("Product Id");
ActivateField("Used Quantity");
ActivateField("Write In Serial Number");
ActivateField("CMI Return");
ActivateField("CMI Return Quantity");
ActivateField("CMI Quoted Quantity");
ActivateField("Trunk Invloc Id");
SetSearchSpec("Used Quantity", "> 0");
//Sort so that quoted items processed first so they will find matches on the order and
//unquoted items will result in an inserted order line
SetSortSpec("CMI Quoted Quantity (DESC)");
ExecuteQuery(ForwardBackward); //Change to forwardbackward to insure unique product records
var bHasPartsMove = FirstRecord();
TheApplication().Utility.logVars("1st Part line Found?", bHasPartsMove);
while(bHasPartsMove) {
var sProductId = GetFieldValue("Product Id");
TheApplication().Utility.logStep("Process Part ("+sProductId+"): "+GetFieldValue("Product Name"));
Gen_UpdateOrderItem(bcOrderItem,
sOrderId,
sProductId,
GetFieldValue("Trunk Invloc Id"), //Source Inventory Id
ToNumber(GetFieldValue("Used Quantity")),
GetFieldValue("Write In Serial Number"),
GetFieldValue("CMI Return"), //Part Tracker Return
GetFieldValue("CMI Return Quantity"),
GetFieldValue("CMI Quoted Quantity"),
bcOrder.GetFieldValue("Price List Id"),
bcOrder.GetFieldValue("CMI IsRebuild"))
bHasPartsMove = NextRecord();
}// end while(bHasPartsMove)
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcOrderItem = null;
bcActionParts=null;
TheApplication().Utility.logUnstack();
}
}//end function

CMI Invoice Reconciliation Process BS
Gen_ProcessLine
function Gen_ProcessLine(bcOrderItem, sIsRebuild)
{
try {
TheApplication().Utility.logStack("Gen_ProcessLine", this);
with (bcOrderItem) {
var sProdType = GetFieldValue("Product Type");
var sMainAssembly = GetFieldValue("CMI Main Assembly Flag");
var sLIType = GetFieldValue("CMI Line Type");
var sWriteInIdentifier = GetFieldValue("CMI Write In Identifier");//KM330 for defect 592
TheApplication().Utility.logStep("Process Line "+GetFieldValue("Line Number")+" ("+GetFieldValue("Product")+") Prod Type / Main / WriteIn / Line Type : "+sProdType+" / "+sMainAssembly+" / "+sWriteInIdentifier+" / "+sLIType);
if(sIsRebuild=="Y") {//Rebuild process
if (sProdType == "Misc" || sProdType == "Labor") {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Rebuild Resource"));
} else if(sMainAssembly == "Y") {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Rebuild Assembly"));
} else {
if((sLIType == null) || (sLIType == "") || (sWriteInIdentifier == "Yes")) {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Rebuild Material"));
}
}
} else {
if ((sProdType == "Misc") || (sProdType == "Labor")) {
if(sWriteInIdentifier == "Yes") {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Order Line Component"));
} else {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Order Line Charges"));
}
} else {
if((sLIType == null) || (sLIType == "") || (sWriteInIdentifier == "Yes")) {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Order Line Component"));
}
}
}//End C&I 4657 Enhancement# S138
WriteRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS
Gen_UpdateLineType
/*******************************************************************************************
Created By :< Aaron Liu>
Created On : <2/21/2011>
Method Name:UpdateLineType(Inputs,Outputs)
C&I Number:
Requirement #:
Functionality: UpdateLineType
Update -- Replaced Status with CMI Status for SetFieldValue to bypass the statemodel validation by ki795 on 3-Nov-2011 for bug # DBUNG00000314
****************************************************************************************** */
function Gen_UpdateLineType(boOrder, bcOrder, sOrderId) {
try {
TheApplication().Utility.logStack("UpdateLineType", this);
var bcOrderItem:BusComp = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
var bcOrderAction:BusComp;
var bcAssocOrder:BusComp;
var oQuoteBO:BusObject;
var oActionBC:BusComp;
var Parts = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Part");
var Misc = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Misc");
var Labor = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
var sIsRebuild = bcOrder.GetFieldValue("CMI IsRebuild");
var sSRId = bcOrder.GetFieldValue("Service Request Id");
var sQuoteId = bcOrder.GetFieldValue("Quote Id");
var sQuoteNum = bcOrder.GetFieldValue("Quote Number");//<CMI DBU><CQ Def: DBUNG00001449><By JQ486 on 29th Aug 2011>
var found;
//Translate and set Line Types
TheApplication().Utility.logVars("Rebuild", sIsRebuild);
with(bcOrderItem) {
ActivateField("CMI Main Assembly Flag");
ActivateField("Product Type");
ActivateField("Line Number");
ActivateField("Product");
ActivateField("CMI Line Type");
ActivateField("CMI Write In Identifier");//KM330 for defect592
SetViewMode(AllView);
ClearToQuery();
ExecuteQuery(ForwardBackward);
found = FirstRecord();
TheApplication().Utility.logVars("First Order Line found?", found);
while(found) {
//C&I 4657 Enhancement# S138
Gen_ProcessLine(bcOrderItem, sIsRebuild);
found = NextRecord();
}//end while(haveRecord)
}//end with(bcOrderItem)
//Query for Parts Tracker and Service Labor Activities
oQuoteBO = TheApplication().GetBusObject("Quote");
oActionBC = oQuoteBO.GetBusComp("Action (Quote Order)");
bcOrderAction = boOrder.GetBusComp("Order Activities");
var completed = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Completed");
var done = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Done");
var sDoneTravel:String = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Done Travel");
var sRepairComplete:String = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Repair Complete");
var sDiagComplete:String = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Diagnostics Complete");
var sUnScheduled:String = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Unscheduled");
var sScheduled:String = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Scheduled");
var partsTracker:String = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Parts Tracker");
var toolSchedule:String = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Tool Schedule");
var serviceLabor:String = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Service Labor");
var sActStatus:String;
var sActType;
with(oActionBC) {
ActivateField("Order Id");
ActivateField("Type");
ActivateField("Status");
ActivateField("Rate List");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Quote Number",sQuoteNum);//<CMI DBU><CQ Def: DBUNG00001449><Added Querying with Quote Number><By JQ486 on 29th Aug 2011>
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("First Activity found?", found);
while(found) {
sActType = GetFieldValue("Type");
TheApplication().Utility.logStep("Process Activity ("+GetFieldValue("Id")+"): "+sActType);
//Associate the order
SetFieldValue("Order Id", sOrderId);
bcOrderAction.NewRecord(NewBefore);
bcOrderAction.SetFieldValue("Order Id", sOrderId);
bcOrderAction.SetFieldValue("Activity Id", GetFieldValue("Id"));
bcOrderAction.WriteRecord();
//Close the Activities
if(sActType == partsTracker) {
SetFieldValue("Status", completed);
} else {
//Change the status to complete only if the previous status is Done Travel,
//Repair Complete or Diagnostic Complete as per s256
sActStatus = GetFieldValue("Status");
TheApplication().Utility.logVars("Activity Status", sActStatus);
if(sActStatus.valueOf() == sDoneTravel.valueOf() || sActStatus.valueOf() == sRepairComplete.valueOf() || sActStatus.valueOf() == sDiagComplete.valueOf()) {//added .valueOf(), jq486, 23 sep 2011.
SetFieldValue("Status", completed);
}
if(sActType == toolSchedule) {
if(sActStatus.valueOf() == sUnScheduled.valueOf() || sActStatus.valueOf() == sScheduled.valueOf()) {//added .valueOf(), jq486, 23 sep 2011.
SetFieldValue("Status", completed);
}
}
}
WriteRecord();
var sCurrentStatus = GetFieldValue("Status");
TheApplication().Utility.logVars("Before Completed Status", sCurrentStatus);
//Bypass cost calculation on activities in Cancelled /Done / non completed
// status by ki795 on 4-Nov-2011
if (sCurrentStatus == completed && sActType != partsTracker) {
TheApplication().Utility.logVars("Rate List", GetFieldValue("Rate List"));
InvokeMethod("RefreshRecord");
InvokeMethod("CompleteActivity");
}
sActStatus = GetFieldValue("Status");
TheApplication().Utility.logVars("Before Done Status", sCurrentStatus);
if(sActStatus.valueOf() == completed) {
InvokeMethod("RefreshRecord");
SetFieldValue("Status", done);
WriteRecord();
}
//For each Parts Tracker record, sync used qty with the new order
if (sActType == partsTracker) {
Gen_UpdatePartsOnOrder(oQuoteBO, oActionBC, boOrder, bcOrder, sOrderId);
}
found = NextRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcOrderAction = null;
bcAssocOrder = null;
bcOrderItem = null;
oActionBC = null;
oQuoteBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS
(declarations)
/*Global Varibles*/
var boQuote:BusObject = TheApplication().GetBusObject("Quote");
var bcQuote:BusComp = boQuote.GetBusComp("Quote");
var sParentSRId:String;
var sRelatedSRId:String;
var sQuoteId:String;
var sInvokeLevel:String;
var i:Number;
var j:Number;
var cntRSR:String;
var cntQuote:String;
var sPSRId:String;
var sRSRId:String;
//Respec - Add Labor
var sCost:Number = 0;
var sDurHr:Number = 0;
var sTotalCost:Number = 0;
var sTotalDurHr:Number = 0;
var sProdId = "";
var sCostListCost = 0;

CMI Invoice Reconciliation Process BS
CheckOrderPartsNotUsed
function CheckOrderPartsNotUsed(sOrderId)
{
try
{
TheApplication().Utility.logStack("CheckOrderPartsNotUsed", this);
var boOrder = TheApplication().GetBusObject("Order Item");
var bcOrderItem = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
var sMisc = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Misc");
var sLabor = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
with (bcOrderItem)
{
SetViewMode(AllView);
ActivateField("Product");
ActivateField("Product Type");
ActivateField("CMI Actual Quantity");
ActivateField("Line Number");
ClearToQuery();
/* var searchst = "[Order Header Id] = '" + sOrderId + "' AND [CMI Main Assembly Flag] <> 'Y' AND " +
"[CMI Actual Quantity] = 0 AND [Product Type] <> '" + sMisc + "' AND [Product Type] <> '" + sLabor + "'";
*/
/*CRQ000000111571 03MAR14 HF lq447, removed MISC type in above line*/
var searchst = "[Order Header Id] = '" + sOrderId + "' AND [CMI Main Assembly Flag] <> 'Y' AND " +
"[CMI Actual Quantity] = 0 AND ([Product Type] <> '" + sMisc + "' OR [Product] = 'Write-In Service') AND [Product Type] <> '" + sLabor + "'";
SetSearchExpr(searchst);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Empty Lines (" + sOrderId + ") found?", FirstRecord());
while (FirstRecord())
{
TheApplication().Utility.logVars("Delete #/Line/Product/Type", GetFieldValue("Id") + "/" + GetFieldValue("Line Number") + "/" + GetFieldValue("Product") + "/" + GetFieldValue("Product Type"));
DeleteRecord();
}
} //end with(bcOrderItem)
}
catch (e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
bcOrderItem = null;
boOrder = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS
Gen_QuoteToOrder
function Gen_QuoteToOrder(sQuoteId)
{
try {
TheApplication().Utility.logStack("Gen_QuoteToOrder", this);
var sOrderId;
//Instantiate the global source quote
with (bcQuote) {
SetViewMode(AllView);
ActivateField("Status");
ActivateField("Quote Number");
ActivateField("Service Request Id");
ActivateField("CMI SR Sub Type");
ActivateField("CMI SR Business Unit");
ActivateField("CMI Primary Division Id");
ActivateField("CMI Default Inventory Location Id");
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardOnly);
//Set a profile attribute to prevent the refresh in the signal when called from script
TheApplication().SetProfileAttr("SkipRefresh", "TRUE");
bcQuote.InvokeMethod("AutoOrderSalesQuote");
//Profile Attribute set in Order Entry - Orders new record event
sOrderId = TheApplication().GetProfileAttr("OrderId")
}// end with
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().SetProfileAttr("SkipRefresh", "");
TheApplication().Utility.logUnstack(sOrderId);
}
return (sOrderId);
}

CMI Invoice Reconciliation Process BS
Gen_InstantiateOrder
function Gen_InstantiateOrder(sOrderId, boOrder, bcOrder)
{
try {
TheApplication().Utility.logStack("Gen_InstantiateOrder", this);
TheApplication().Utility.logVars("Order Id", sOrderId);
var found;
with(bcOrder) {
ActivateField("CMI IsRebuild");
ActivateField("Service Request Id");
ActivateField("Quote Id");
ActivateField("Quote Number");
ActivateField("Price List Id");
ActivateField("CMI IsRebuild");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(found);
}
return(found);
}

CMI Invoice Reconciliation Process BS
Gen_GetPriceList
function Gen_GetPriceList(sPriceListId, sProductId, sOut)
{
/*************************************************************************************************************************
Created By : ix964
Created On : 7-Jan-11
Method Name:
Functionality:
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
//try catch added by shanmukh for code clean up 08/27/2011
try {
TheApplication().Utility.logStack("Gen_GetPriceList", this);
var sCost;
var price;
var boPrice = TheApplication().GetBusObject("Admin Price List");
var bcPrice = boPrice.GetBusComp("Price List");
var bcPriceItem = boPrice.GetBusComp("Price List Item");
with(bcPrice) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sPriceListId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
with(bcPriceItem) {
ActivateField("Cost");
ActivateField("Original List Price");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Product Id", sProductId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
sCost = GetFieldValue("Cost");
price = GetFieldValue("Original List Price");
}
sOut.SetProperty("Cost", sCost);
sOut.SetProperty("Price", price);
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPriceItem = null;
bcPrice = null;
boPrice = null;
TheApplication().Utility.logUnstack(price);
}
}

CMI Invoice Reconciliation Process BS
Gen_ProcessDependentLines
function Gen_ProcessDependentLines(bcOrderItem, sLineType, sInventoryId, mainAssembly, covMainAsby, sUsedQuantity, sReturnQty, sQuoteQty) {
try {
TheApplication().Utility.logStack("Gen_ProcessDependentLines", this);
var reconType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type");
var reconReturnType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type");
var sTotalQty;
with(bcOrderItem) {
TheApplication().Utility.logVars("Main Assembly", mainAssembly);
if (sLineType == reconReturnType) {
//If this is the clean core for a main assembly, the return quantity from
//the parts tracker will be 0 so use the Used Quantity instead
if (covMainAsby == "Y") {
sTotalQty = sUsedQuantity * -1;
} else {
sTotalQty = sReturnQty * -1;
}
TheApplication().Utility.logVars("Set Actual Qty To", sTotalQty,4);
SetFieldValue("CMI Actual Quantity", sTotalQty);
SetFieldValue("CMI Quantity Quoted", (sQuoteQty * -1));
SetFieldValue("Source Inventory Loc Id", "");
SetFieldValue("Destination Inventory Loc Id", sInventoryId);
SetFieldValue("Extended Quantity Requested", sTotalQty);
SetFieldValue("Quantity Requested", sTotalQty);
} else if (sLineType == reconType) {
SetFieldValue("CMI Actual Quantity", sUsedQuantity); // By: jq487 to fix defect 521/491/530
SetFieldValue("CMI Quantity Quoted", sQuoteQty);//By JQ487: for fixing defect 4827, 4831
SetFieldValue("Source Inventory Loc Id", sInventoryId);
SetFieldValue("Destination Inventory Loc Id", "");
SetFieldValue("Extended Quantity Requested", sUsedQuantity); // By: jq487 to fix defect 521/491/530
SetFieldValue("Quantity Requested", sUsedQuantity);
} else if (mainAssembly == "Y") {
TheApplication().Utility.logVars("Set Actual Qty To", sUsedQuantity,4);
SetFieldValue("CMI Actual Quantity", sUsedQuantity); // By: jq487 to fix defect 521/491/530
SetFieldValue("CMI Quantity Quoted", sQuoteQty);//By JQ487: for fixing defect 4827, 4831
SetFieldValue("Destination Inventory Loc Id", "");
SetFieldValue("Extended Quantity Requested", sUsedQuantity); // By: jq487 to fix defect 521/491/530
SetFieldValue("Quantity Requested", sUsedQuantity);
}
WriteRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS_c
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation
switch (MethodName) {
case "ParseXML":
ParseXML (Inputs, Outputs);
break;
}
} catch(e){
Outputs.SetProperty("Error Code", "1");
Outputs.SetProperty("Error Message", e.message);
TheApplication().Utility.RaiseError(e);
} finally {
bcQuote = null;
boQuote = null;
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Invoice Reconciliation Process BS_c
Ret_UpdateQuantity
/***************************************************************************************************************
Created By : JF344
Created On : sOrderId4-Mar-2011
****************************************************************************************************************/
function Ret_UpdateQuantity(sOrderId, sSRId, sQuoteId, mainFound) {
try {
TheApplication().Utility.logStack("Ret_UpdateQuantity", this);
if(sOrderId == "" || sSRId == "") return;
var boOrder:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var bcOrder:BusComp = boOrder.GetBusComp("Order Entry - Orders");
var bcOrderItem:BusComp = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
var sLineType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Internal Return Line");
var bDeleteOrder = "";
var sZero = 0;
var found;
var sMainAssblyId = "";
//Get fields from the Quote in order to set them on the Order
var defaultInv = bcQuote.GetFieldValue("Source Inventory Location Id");
var divisionId = bcQuote.GetFieldValue("CMI Primary Division Id");
TheApplication().Utility.logVars("Default Inventory", defaultInv);
with(bcOrder) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Order ("+sOrderId+") found?", found);
if(found) {
//Update fields for Main assembly since it does not exist on the parts tracker
if (mainFound) {
with(bcOrderItem) {
ClearToQuery();
ActivateField("Destination Inventory Loc Id");
ActivateField("Source Inventory Loc Id");
ActivateField("Quantity Requested");
ActivateField("CMI Actual Quantity");
ActivateField("CMI Serial Number");
SetViewMode(AllView);
SetSearchSpec("CMI Main Assembly Flag", "Y");
SetSearchSpec("Order Header Id", sOrderId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Main Assembly on Order?", found);
if(FirstRecord()) {
sMainAssblyId = GetFieldValue("Id");
SetFieldValue("Quantity Requested", GetFieldValue("CMI Actual Quantity"));
TheApplication().Utility.logVars("Division Id ", divisionId);
//Changed the function from GetInventoryLocId LC657
SetFieldValue("Source Inventory Loc Id", GetDirtyInventoryLocId("WIP",divisionId));
SetFieldValue("Destination Inventory Loc Id", GetDirtyInventoryLocId("FG",divisionId));
WriteRecord();
}
}
}
}
}
var bcAction:BusComp = boQuote.GetBusComp("Action (Quote Order)");
var bcPartTracker:BusComp = boQuote.GetBusComp("FS Activity Parts Movement");
//Instantiate the Part Tracker and loop through each record to insure it exists on the return
//Order if the Picked Quantity is greater than the Used Quantity
with(bcAction) {
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker"));
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker Found?", found);
if(found) { //process part tracker
with(bcPartTracker) {
ClearToQuery();
ActivateField("Trunk Invloc Id");
ActivateField("Used Quantity");
ActivateField("CMI Parts Allocated");
ActivateField("CMI Return");
ActivateField("CMI Return Quantity");
ActivateField("CMI Unit of Measure");
SetViewMode(AllView);
ExecuteQuery(ForwardOnly);
var bHasRecord = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker Item Found?", bHasRecord);
while(bHasRecord) {
var sTrunkInvlocId = GetFieldValue("Trunk Invloc Id");
var sQtyUsed = GetFieldValue("Used Quantity");
var sReturn = GetFieldValue("CMI Return");
var sReturnQty = GetFieldValue("CMI Return Quantity");
var sQtyAllocated = GetFieldValue("CMI Parts Allocated");
var sQtyReturn = parseInt(sQtyAllocated) - parseInt(sQtyUsed);
var sOILId;
TheApplication().Utility.logVars("PT - Picked(P) / Used(U) / (P-U)",sQtyAllocated+" / "+sQtyUsed+" / "+sQtyReturn);
if(sQtyReturn <0) sQtyReturn = 0;
var sProdId = GetFieldValue("Product Id");
TheApplication().Utility.logStep(GetFieldValue("Product Name")+" ("+sProdId+") - Return: "+sReturnQty);
with(bcOrderItem) {
ClearToQuery();
ActivateField("Destination Inventory Loc Id");
ActivateField("Source Inventory Loc Id");
ActivateField("Quantity Requested");
ActivateField("CMI Serial Number");
//LC657 Added for Tkt#Tkt#INC000004816819
ActivateField("Covered Quote Item Id");
//Nag; 9/9/2013; Added for 1.2 release, Req# 77
ActivateField("CMI Parts Movement Picked Qty");
SetViewMode(AllView);
SetSearchExpr("[Product Id] = '" + sProdId + "' AND [Quantity Requested] = '" + sZero + "'");
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Line for Product Found?", found);
//If matching line item is found, update it, otherwise create a new record
if(FirstRecord()) {
sOILId = GetFieldValue("Id");
//LC657 Added for updating Picked qty for Rebuild items
var sCoveredQuoteItemId = GetFieldValue("Covered Quote Item Id");
TheApplication().Utility.logVars("MainAssemblyId / ParentOrderItemId / sQtyAllocated",sMainAssblyId+" / "+sCoveredQuoteItemId+" / "+sQtyAllocated);
if (sMainAssblyId != null && sMainAssblyId != "")
if (sMainAssblyId == sCoveredQuoteItemId) //Added this if condition to retain main Assembly LC657 Tkt#INC000004816819
{
Ret_UpdateMainAssembly(boOrder,bcOrder,sOrderId,sMainAssblyId, sOILId,sQtyAllocated,divisionId,mainFound);
}
//For Cores, find the linked dirty core line and update the qty or delete
if (sReturn != "") { //will either be 'No Return' or 'Core'
Ret_UpdateDirtyCore(sOrderId, sOILId, sReturnQty, sTrunkInvlocId, sReturn, divisionId,sQtyAllocated);
}
//If the order item is all used, there is no need show in the return order.
if(sQtyReturn == 0) {
DeleteRecord();
} else {
SetFieldValue("Source Inventory Loc Id", sTrunkInvlocId);
SetFieldValue("Destination Inventory Loc Id", defaultInv);
SetFieldValue("Quantity Requested", sQtyReturn);
//Nag; 9/9/2013; Added for 1.2 release, Req# 77
SetFieldValue("CMI Parts Movement Picked Qty", sQtyAllocated);
WriteRecord();
}
//} //end if sMainAssblyId
//Part Tracker item exists without corresponding Order Line. If Part Tracker line has a
//return quantity create the Return Order line item
} else if (sQtyReturn > 0) {
NewRecord(NewAfter);
SetFieldValue("CMI Actual Quantity",sQtyReturn);
SetFieldValue("Product Id",sProdId);
SetFieldValue("Quantity Requested",sQtyReturn);
SetFieldValue("Extended Quantity Requested",sQtyReturn);
SetFieldValue("Action Code", TheApplication().InvokeMethod("LookupValue", "DELTA_ACTION_CODE", "New"));
SetFieldValue("CMI Action Code", TheApplication().InvokeMethod("LookupValue", "DELTA_ACTION_CODE", "New"));
SetFieldValue("CMI Quantity Quoted", 0);
SetFieldValue("CMI Unit of Measure", bcPartTracker.GetFieldValue("CMI Unit of Measure"));
SetFieldValue("CMI Line Type","Service Internal Return Line");
SetFieldValue("Source Inventory Loc Id", sTrunkInvlocId);
SetFieldValue("Destination Inventory Loc Id", defaultInv);
//Nag; 9/9/2013; Added for 1.2 release, Req# 77
SetFieldValue("CMI Parts Movement Picked Qty", sQtyAllocated);
WriteRecord();
}
}
bHasRecord = NextRecord();
}
}
}
}
//Jn705: Added to delete the return order if no line item exists
with(bcOrderItem) {
ClearToQuery();
SetSearchSpec("Order Header Id", sOrderId);
ExecuteQuery(ForwardOnly);
bDeleteOrder = FirstRecord();
}
TheApplication().Utility.logVars("Order Items Found?", bDeleteOrder);
//Only query for the order if it is necessary to delete it
if(!bDeleteOrder) {
with(bcOrder) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Order ("+sOrderId+") found?", found);
if(found) {
DeleteRecord();
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPartTracker = null;
bcAction = null;
bcOrderItem = null;
bcOrder = null;
boOrder = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS_c
Ret_UpdateMainAssembly
function Ret_UpdateMainAssembly(boOrder,bcOrder,sOrderId,sMainAssblyId, sOILId,sQtyAllocated,divisionId,mainFound)
{
TheApplication().Utility.logStack("Ret_UpdateMainAssembly", this);
try {
var boOrderMainAsbly:BusObject = TheApplication().GetBusObject("Order Entry");
var bcOrderHeaderAsbly:BusComp = boOrderMainAsbly.GetBusComp("Order Entry - Orders");
var oOrderLinesMainAsbly:BusComp = boOrderMainAsbly.GetBusComp("Order Entry - Line Items (Simple)");
var sfound;
with (bcOrderHeaderAsbly)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
with (oOrderLinesMainAsbly)
{
ClearToQuery();
ActivateField("CMI Parts Movement Picked Qty");
SetViewMode(AllView);
//SetSearchSpec("CMI Main Assembly Flag", "Y");
SetSearchSpec("Id", sMainAssblyId);
ExecuteQuery(ForwardOnly);
sfound = FirstRecord();
TheApplication().Utility.logVars("Main Assembly Line on Order?", sfound);
if(sfound) {
SetFieldValue("CMI Parts Movement Picked Qty", sQtyAllocated);
WriteRecord();
}
}
}
}
} //end try
catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oOrderLinesMainAsbly = null;
bcOrderHeaderAsbly = null;
boOrderMainAsbly = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS_c
Ret_UpdateDirtyCore
//Added by KM326 for 4455 on 22/11/2011
// This function is used to update or delete the dirty core created via datamap depending upon
// the CMI Return and CMI Return Quantity field values in Parts Tracker
function Ret_UpdateDirtyCore(sOrderId, sOILId, sReturnQty, sTrunkInvlocId, sReturn, divisionId,sQtyAllocated)
{
try {
TheApplication().Utility.logStack("Ret_UpdateDirtyCore", this);
var oBOOrderDirty:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var OBCOrderItemDirty:BusComp = oBOOrderDirty.GetBusComp("Order Entry - Line Items (Simple)");
var sCore = TheApplication().InvokeMethod("LookupValue", "CMI_RETURN", "Core");
var found;
with(OBCOrderItemDirty) {
ActivateField("Quantity Requested");
ActivateField("Source Inventory Loc Id");
ActivateField("Destination Inventory Loc Id");
ActivateField("CMI Parts Movement Picked Qty");
ClearToQuery();
SetSearchSpec("Order Header Id",sOrderId);
SetSearchSpec("Covered Quote Item Id",sOILId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Dirty Core Line Found?", found);
if(found) {
TheApplication().Utility.logVars("Return - Type/Qty", sReturn+" / "+sReturnQty);
if(sReturn == sCore && sReturnQty != 0) {
SetFieldValue("Source Inventory Loc Id", sTrunkInvlocId);
SetFieldValue("Destination Inventory Loc Id", GetDirtyInventoryLocId("Dirty Core",divisionId));
SetFieldValue("Quantity Requested", sReturnQty);
//LC657 CQ#12382
SetFieldValue("CMI Parts Movement Picked Qty", sQtyAllocated);
WriteRecord();
} else {
DeleteRecord();
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
OBCOrderItemDirty = null;
oBOOrderDirty = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS_c
Ret_QuoteToReturnOrder
/***************************************************************************************************************
Created By : JF344
Created On : 28-Feb-11
C&I Number :
Requirement # :
Method Name: uoteToReturnOrder
Functionality:
Input: None
Output: None
Customization Approval #: NA
******************************************************************************************************************/
function Ret_QuoteToReturnOrder(sQuoteId)
{
try {
TheApplication().Utility.logStack("Ret_QuoteToReturnOrder", this);
//Use the global source quote object which is already instantiated
var bcQuoteItem:BusComp = boQuote.GetBusComp("Quote Item (Simple)");
var bcAction:BusComp = boQuote.GetBusComp("Action (Quote Order)");
var bcPartsTracker:BusComp = boQuote.GetBusComp("FS Activity Parts Movement");
var sPartsTracker = TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker");
var createReturnOrder = false;
var quoteFound = false;
var found = false;
var mainFound = false;
//If the Quote has a Main Assembly, a return order must be created for it regardless of Parts Tracker
//Quantities
with(bcQuoteItem) {
SetViewMode(AllView);
ActivateField("Extended Quantity Requested");
ClearToQuery();
SetSearchSpec("CMI Main Assembly Flag","Y");
ExecuteQuery(ForwardOnly);
mainFound = FirstRecord();
TheApplication().Utility.logVars("Main Assembly found?", mainFound);
}
//if no Main Assembly present, determine if Return order is needed by checking used qty on parts tracker
if (!mainFound) {
with(bcAction) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Type", sPartsTracker);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker found?", found);
if(found) {
with(bcPartsTracker) {
ActivateField("CMI Parts Allocated");
ActivateField("Used Quantity");
ActivateField("CMI Return Quantity");
SetViewMode(AllView);
ClearToQuery();
ExecuteQuery(ForwardOnly);
var sHaveParts = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker Item found?", sHaveParts);
while(sHaveParts) {
var sPickedQty = GetFieldValue("CMI Parts Allocated");
var sUsedQty = GetFieldValue("Used Quantity");
//Added by KM326 for 4455 on 22/11/2011
var sReturnQuantity = GetFieldValue("CMI Return Quantity");
TheApplication().Utility.logVars("Used/Picked/Return", sUsedQty+" / "+sPickedQty+" / "+sReturnQuantity);
if(ToNumber(sUsedQty) < ToNumber(sPickedQty) || sReturnQuantity != 0) {//|| sReturnQuantity != 0 by KM326 for 4455 on 22/11/2011
createReturnOrder = true;
sHaveParts = false;
} else sHaveParts = NextRecord();
}//while(sHaveParts)
}//with(bcPartsTracker)
}//if(FirstRecord())
}// with(bcAction)
}
TheApplication().Utility.logVars("Create Return Order", createReturnOrder);
if(createReturnOrder || mainFound) {
var sSRId = bcQuote.GetFieldValue("Service Request Id");
//lc657 CQ#12328
TheApplication().SetProfileAttr("CMIReturnOrderCreation", "Y");
//Set a profile attribute to prevent the refresh in the signal when called from script
TheApplication().SetProfileAttr("SkipRefresh", "TRUE");
bcQuote.InvokeMethod("AutoOrderReturnQuote");
Ret_UpdateQuantity(TheApplication().GetSharedGlobal("DTUSharedGlobalDestId"),sSRId, sQuoteId, mainFound);
}//end if(createReturnOrder)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcQuoteItem = null;
bcAction = null;
bcPartsTracker = null;
TheApplication().SetProfileAttr("SkipRefresh", "");
TheApplication().SetProfileAttr("CMIReturnOrderCreation", "");
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS_c
Respec_UpdateOrderLine
function Respec_UpdateOrderLine(sOrderId)
{
/*******************************************************************************************
Created By :<JQ487>
Created On : <08/02/2011>
Method Name:AddLabor
C&I Number: 4657
Requirement #: Enhancement S138
Functionality: This BS will query for Time Tracker records in Service labor activity and based on
technicians billable product will create a new labor record with product same as billable product
from technician. also it queries the quote, from which order is generated, for labor line items
and adds the sum of their Requested Quantity to "Quoted Quantity" of first labor record in Order.
Input:
Output:
****************************************************************************************** */
try{
TheApplication().Utility.logStack("Respec_UpdateOrderLine", this);
var bcQuoteItem:BusComp = boQuote.GetBusComp("Quote Item (Simple)");
var boOrder:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var bcOrder:BusComp = boOrder.GetBusComp("Order Entry - Orders");
var bcOrderItem:BusComp = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
var bcAction:BusComp = boQuote.GetBusComp("Action (Quote Order)");
var bcProduct:BusComp;
var sSRId:String = "";
var sActionId:String = "";
var sQtySum:Number = 0;
var sProdType:String = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
var sRbtResource = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Rebuild Resource");
//Adde by KM326 to fix 721/651 on 02-12-2011
var sPrevTotalDurHr = 0;
var sPrevTotalCost = 0;
var prevOwnerId = "";
var sOwnerId:String = "";
//Querying Quote Item BC to Sum the total of the Requested Quantity for all labor lines on the quote and storing in a variable
with(bcQuoteItem) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("Product");
ActivateField("Quantity Requested");
SetSearchSpec("Product Type", sProdType);
ExecuteQuery(ForwardBackward);
var isRec = FirstRecord();
TheApplication().Utility.logVars("First Labor Item found?", isRec);
while(isRec) {
var sQty = GetFieldValue("Quantity Requested");
TheApplication().Utility.logStep("Add "+GetFieldValue("Product")+" Hours: "+sQty+" + "+sQtySum);
sQtySum += ToNumber(sQty);
isRec = NextRecord();
}//end while(isRec)
}//end with(bcQuoteItem)
//Instantiate the order. When Order lines for billing products are created, certain values will predefault from the header
with(bcOrder) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
var orderFound = FirstRecord();
TheApplication().Utility.logVars("Order ("+sOrderId+") found?", orderFound);
}//end with(bcOrder)
//Find the Service Labor activity based on Quote ID
with(bcAction) {
SetViewMode(AllView);
ActivateField("Rate List Id");
ActivateField("CMI Owner FullName");
ClearToQuery();
SetSortSpec("Primary Owner Id(ASCENDING)"); //KM326 to fix bug 721/651 on 02-12-2011
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Service Labor"));
ExecuteQuery(ForwardBackward);
var isRec1 = FirstRecord();
while(isRec1) {
TheApplication().Utility.logStep("Service Labor Activity ("+GetFieldValue("Id")+") Owner: "+GetFieldValue("CMI Owner FullName"));
sOwnerId = GetFieldValue("Primary Owner Id");
if (prevOwnerId != sOwnerId && sOwnerId != "") {
prevOwnerId = sOwnerId;
Respec_CheckPosition(sOwnerId, GetFieldValue("Rate List Id"));
}
if(sProdId == null || sProdId == "") {
isRec1 = bcAction.NextRecord();
} else {
Respec_TimeTrackerCheck(GetFieldValue("Id"));
if(orderFound) {
with(bcOrderItem) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("Product");
ActivateField("CMI Price Override");
ActivateField("Quantity Requested");
ActivateField("Extended Quantity Requested");
ActivateField("Cost");
ActivateField("Net Price");
ActivateField("Product Id");
ActivateField("CMI Line Type");
ActivateField("CMI Actual Quantity");
ActivateField("Unit Price");
SetSearchSpec("Product Id", sProdId);
ExecuteQuery(ForwardOnly);
var olisRec = FirstRecord();
TheApplication().Utility.logVars("Order Line found?", olisRec);
//For subsequent Service Labor activities, the billing product line will just need to be updated
if(olisRec) {
sPrevTotalDurHr = sPrevTotalDurHr + sTotalDurHr;
sPrevTotalCost = sPrevTotalCost + sTotalCost;
//Updating the quantity field on the labor item with the sum of
//the duration field from the time tracker record
SetFieldValue("CMI Actual Quantity", ToNumber(sPrevTotalDurHr));
SetFieldValue("Quantity Requested", ToNumber(sPrevTotalDurHr));
SetFieldValue("Extended Quantity Requested", ToNumber(sPrevTotalDurHr));
//Updating the cost and Manual Price Override on the labor item
//with the cost field from the time tracker record
SetFieldValue("CMI Price Override", ToNumber(sPrevTotalCost));
SetFieldValue("Cost", ToNumber(sCostListCost));
SetFieldValue("Net Price", ToNumber(sCostListCost));
SetFieldValue("Unit Price", ToNumber(sCostListCost));
sCost = 0;
sDurHr = 0;
sTotalCost = 0;
sTotalDurHr = 0;
sProdId = "";
isRec1 = bcAction.NextRecord();
} else {
//The first time each Billing Product is found, a new order line will be created
NewRecord(NewAfter);
bcProduct = GetPicklistBusComp("Product");
with(bcProduct) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Product ID", sProdId);
ExecuteQuery(ForwardOnly);
var isPickBCRec = FirstRecord();
if(isPickBCRec) Pick();
}//end with(sProd)
//Updating the quantity field on the labor item with the sum of
//the duration field from the time tracker record
SetFieldValue("CMI Actual Quantity", ToNumber(sTotalDurHr));
SetFieldValue("Quantity Requested", ToNumber(sTotalDurHr));
SetFieldValue("Extended Quantity Requested", ToNumber(sTotalDurHr));
//Updating the cost and Manual Price Override on the labor item
//with the cost field from the time tracker record
SetFieldValue("CMI Price Override", sTotalCost);
SetFieldValue("Cost", ToNumber(sCostListCost));
SetFieldValue("Net Price",ToNumber(sCostListCost));//added by km330 for defect 651,on 30/11/2011
SetFieldValue("Unit Price", ToNumber(sCostListCost));
SetFieldValue("CMI Line Type", sRbtResource);
WriteRecord();
sPrevTotalDurHr = sTotalDurHr;
sPrevTotalCost = sTotalCost;
sCost = 0;
sDurHr = 0;
sTotalCost = 0;
sTotalDurHr = 0;
sProdId = "";
isRec1 = bcAction.NextRecord();
}//end else
}//end with(bcOrderItem)
}//end if
}
}//end While
}//end (bcAction)
//Querying Order Item BC again to Update the field Quoted
//Quantity on first labor line that was added via the previous
//step with the total of the requested quantity
with(bcOrderItem) {
SetViewMode(AllView);
ActivateField("Order Header Id");
ActivateField("CMI Quantity Quoted");
ActivateField("CMI Order Status");
ClearToQuery();
SetSearchSpec("Order Header Id", sOrderId);
SetSearchSpec("Product Type", TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor"));
ExecuteQuery(ForwardBackward);
TheApplication().Utility.logVars("Labor Line found?", FirstRecord());
if(FirstRecord()) {
SetFieldValue("CMI Quantity Quoted", sQtySum);
WriteRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcProduct = null;
bcAction = null;
bcQuoteItem = null;
bcOrder = null;
bcOrderItem = null;
boOrder = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS_c
Respec_TimeTrackerCheck
function Respec_TimeTrackerCheck(sSerLabId)
{
/*******************************************************************************************
Created By :<JQ487>
Created On : <08/02/2011>
Method Name:AddLabor
C&I Number: 4657
Requirement #: Enhancement S138
Functionality: This BS will query for Time Tracker records in Service labor activity
Input:
****************************************************************************************** */
try{
TheApplication().Utility.logStack("Respec_TimeTrackerCheck", this);
var boAction:BusObject = TheApplication().GetBusObject("Action");
var bcTimeSheetHrs:BusComp = boAction.GetBusComp("Time Sheet Daily Hours");
with(bcTimeSheetHrs) {
SetViewMode(AllView);
ActivateField("Time Cost");
ActivateField("CMI Time Cost - Calc");
ActivateField("Elasped Time in Hours");
ActivateField("Elasped Time in Time");
ClearToQuery();
SetSearchSpec("Activity Id", sSerLabId);
ExecuteQuery(ForwardBackward);
var isRec = FirstRecord();
while(isRec) {//this loop will sum the Duration and Cost on Time tracker record and will update it on Labor record on order item
sCost = GetFieldValue("Time Cost");
sDurHr = GetFieldValue("Elasped Time in Hours");
TheApplication().Utility.logVars("Elasped Hours / Time / Cost / Converted", GetFieldValue("Elasped Time in Hours")+" / "+
GetFieldValue("Elasped Time in Time")+" / "+GetFieldValue("Time Cost")+" / "+GetFieldValue("CMI Time Cost - Calc"));
sTotalCost = ToNumber(sTotalCost) + ToNumber(sCost);
sTotalDurHr = ToNumber(sTotalDurHr) + ToNumber(sDurHr);
isRec = NextRecord();
}
}//end (bcOrder)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
boAction = null;
bcTimeSheetHrs = null;
TheApplication().Utility.logUnstack(sTotalDurHr+" / "+sTotalCost);
}
}

CMI Invoice Reconciliation Process BS_c
Respec_CheckPosition
function Respec_CheckPosition(sOwnerId, sRateListId)
{
/*******************************************************************************************
Created By :<JQ487>
Created On : <08/02/2011>
Method Name:AddLabor
C&I Number: 4657
Requirement #: Enhancement S138
Functionality: This BS will query for Billable product associated with Technician.
****************************************************************************************** */
try{
TheApplication().Utility.logStack("Respec_CheckPosition", this);
var boPosition:BusObject = TheApplication().GetBusObject("Position");
var bcPosition:BusComp = boPosition.GetBusComp("Position");
var boRateList:BusObject = TheApplication().GetBusObject("PS Rate List");
var bcRateList:BusComp = boRateList.GetBusComp("PS Rate List");
var boCostList:BusObject = TheApplication().GetBusObject("Cost List");
var bcCostList:BusComp = boCostList.GetBusComp("Cost List");
var bcCostListItem:BusComp = boCostList.GetBusComp("Cost List Item");
var sCostListId = "";
var product;
// TheApplication("Test Active Position", TheApplication().PositionName()+" ("+TheApplication().PositionId()+")");
with(bcPosition) {
SetViewMode(AllView);
ActivateField("Billing Product Id");
ActivateField("Billing Product");
ClearToQuery();
SetSearchSpec("Employee Id", sOwnerId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Position for Employee("+sOwnerId+") found?", FirstRecord());
if(FirstRecord()) {
//modified by km326 for C&I 4657 on 08-12-2011
product = GetFieldValue("Billing Product");
sProdId = GetFieldValue("Billing Product Id");
//commented by km326 for C&I 4657 on 08-12-2011
}
}//end (bcPosition)
TheApplication().Utility.logVars("Product (Id)", product+" ("+sProdId+")");
if(sProdId != null && sProdId != "") {
with(bcRateList) {
SetViewMode(AllView);
ActivateField("Cost List Id");
ClearToQuery();
SetSearchSpec("Id", sRateListId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Rate List ("+sRateListId+") found?", FirstRecord());
if(FirstRecord()) {
sCostListId = GetFieldValue("Cost List Id");
with(bcCostList) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sCostListId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Cost List ("+sCostListId+") found?", FirstRecord());
if(FirstRecord()) {
with(bcCostListItem) {
SetViewMode(AllView);
ActivateField("Product Id");
ActivateField("Standard Cost");
ClearToQuery();
SetSearchSpec("Price List Id", sCostListId);
SetSearchSpec("Product Id", sProdId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("First Cost Item found?", FirstRecord());
if(FirstRecord()) {
sCostListCost = GetFieldValue("Standard Cost");
}
}
}
}
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPosition = null;
boPosition = null;
bcCostListItem = null;
bcRateList = null;
bcCostList = null;
boRateList = null;
boCostList = null;
TheApplication().Utility.logUnstack(sCostListCost);
}
}

CMI Invoice Reconciliation Process BS_c
ParseXML
function ParseXML(Inputs, Outputs)
{
/*********************************************************
AUTHOR: JU982,
C&I:4469
Enhancement: S126,146
DESCRIPTION: The below function will parse Siebel message returned from ILog and pass Quote Id to Generate Order function
DATE CREATED: 11 Sep 2011
*********************************************************/
try {
TheApplication().Utility.logStack("ParseXML", this);
var psPSR = TheApplication().NewPropertySet();
var psRSR = TheApplication().NewPropertySet();
var psQuote = TheApplication().NewPropertySet();
var sInput = TheApplication().NewPropertySet();
var sOutput = TheApplication().NewPropertySet();
var sPendingInvoice:String = TheApplication().InvokeMethod("LookupValue" ,"SR_SUB_STATUS", "Pending Invoice");
var oSRBO:BusObject = TheApplication().GetBusObject("Service Request");
var oSRBC:BusComp = oSRBO.GetBusComp("Service Request");
var sPSRId = Inputs.GetProperty("CMI Parent SR Id");
var sInvokeLevel = Inputs.GetProperty("CMI Invoke Level");
var sRSRId;
var cntRSR;
var cntQuote;
var sQuoteId;
//Initialize outputs
Outputs.SetProperty("Error Code", "");
Outputs.SetProperty("Error Message", "");
var svc = TheApplication().GetService("Workflow Process Manager");
psRSR = Inputs.GetChild(0).GetChild(0).GetChild(0).GetChild(0);
cntRSR = psRSR.GetChildCount();
for(i=0; i<cntRSR ; i++) {
sRSRId = psRSR.GetChild(i).GetProperty("Id");
psQuote = psRSR.GetChild(i).GetChild(0);
cntQuote = psQuote.GetChildCount();
for(j=0; j<cntQuote; j++) {
sQuoteId = psQuote.GetChild(j).GetProperty("Id");
// Call Generate order BS function and pass Quote id as an input;
GenerateOrderQuote (sQuoteId);
}
// Update RSR status to Pending For Invoice
// Added sInvokeLevel == "Parent SR" to fix defect 527 by ju982 on 11152011
if(sInvokeLevel == "Related SR" || sInvokeLevel == "Parent SR") {
sInput.SetProperty("ProcessName", "CMI Update SR Sub Status and IRN");
sInput.SetProperty("Object Id", sRSRId);
sInput.SetProperty("CMI SR Sub Status", sPendingInvoice);
sInput.SetProperty("CMI IRN Flag", "N");
svc.InvokeMethod("RunProcess", sInput, sOutput);
}// End of If sInvokeLevel= Related SR
}// end of for i loop
// Update PSR sub status
if(sInvokeLevel == "Parent SR") {
sInput = TheApplication().NewPropertySet();
sOutput = TheApplication().NewPropertySet();
sInput.SetProperty("ProcessName", "CMI Update SR Sub Status and IRN");
sInput.SetProperty("Object Id", sPSRId);
sInput.SetProperty("CMI SR Sub Status", sPendingInvoice);
sInput.SetProperty("CMI IRN Flag", "N");
svc.InvokeMethod("RunProcess", sInput, sOutput);
}// End of If sInvokeLevel= Parent SR
} catch(e){
// TheApplication().Utility.logStep("ParseXML");
TheApplication().Utility.RaiseError(e);
} finally {
oSRBC=null;
sInvokeLevel=null;
psPSR = null;
psRSR = null;
psQuote = null;
sInput = null;
sOutput = null;
oSRBO=null;
svc = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS_c
GetInventoryLocId
function GetInventoryLocId(inventoryType,divisionId) {
try {
TheApplication().Utility.logStack("GetInventoryLocId", this, 4);
var boInventory:BusObject = TheApplication().GetBusObject("FS Inventory Location Mgmt");
var bcInventory:BusComp = boInventory.GetBusComp("FS Inventory Location");
var sInvLocId = "";
with(bcInventory) {
SetViewMode(AllView);
ActivateField("Inventory Type");
ActivateField("Primary Organization Id");
ClearToQuery();
SetSearchSpec("Inventory Type", inventoryType);
SetSearchSpec("Primary Organization Id", divisionId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
sInvLocId = GetFieldValue("Id");
TheApplication().Utility.logVars(inventoryType+" - Inventory Location Id", sInvLocId);
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcInventory = null;
boInventory = null;
TheApplication().Utility.logUnstack(sInvLocId, 4);
}
return (sInvLocId);
}

CMI Invoice Reconciliation Process BS_c
GetDirtyInventoryLocId
function GetDirtyInventoryLocId(inventoryType,divisionId) {
try {
TheApplication().Utility.logStack("GetDirtyInventoryLocId", this, 4);
var boInventory:BusObject = TheApplication().GetBusObject("FS Inventory Location Mgmt");
var bcInventory:BusComp = boInventory.GetBusComp("FS Inventory Location");
var sInvLocId = "";
with(bcInventory) {
SetViewMode(AllView);
ActivateField("Inventory Type");
ActivateField("CMI Primary Division Id");
ClearToQuery();
SetSearchSpec("Inventory Type", inventoryType);
SetSearchSpec("CMI Primary Division Id", divisionId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
sInvLocId = GetFieldValue("Id");
TheApplication().Utility.logVars(inventoryType+" - Inventory Location Id", sInvLocId);
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcInventory = null;
boInventory = null;
TheApplication().Utility.logUnstack(sInvLocId, 4);
}
return (sInvLocId);
}

CMI Invoice Reconciliation Process BS_c
GenerateOrderQuote
function GenerateOrderQuote(sQuoteId)
{
/*********************************************************
AUTHOR: JQ487,
C&I:4469
Enhancement: S126,147
DESCRIPTION: The below function will call CMI Invoice Reconciliation Create Order WF based on
Quote Id passed as in input to this function
DATE CREATED: 09 Sep 2011
*********************************************************/
try {
TheApplication().Utility.logStack("GenerateOrderQuote", this);
/* var sWFMgr = TheApplication().GetService("Workflow Process Manager");
var sInput = TheApplication().NewPropertySet();
//MJB 6/4/12 The wrapper service was part of an old design that had the capability to reexecute
//the generate order process if an error occurred in the middle. This service will now roll back
//If an error occurs so it is unnecessary and will be faster to skip it
// sInput.SetProperty("ProcessName","CMI Invoice Reconciliation Create Order Wrapper WF");
sInput.SetProperty("ProcessName","CMI Invoice Reconciliation Create Order WF");
sInput.SetProperty("Object Id", sQuoteId);
sWFMgr.InvokeMethod("RunProcess", sInput, Outputs);
*/
var boOrder:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var bcOrder:BusComp = boOrder.GetBusComp("Order Entry - Orders");
var found = false;
//Create the Order via Data Map
var sOrderId = Gen_QuoteToOrder(sQuoteId);
//Instantiate the newly created order activating any necessary fields
found = Gen_InstantiateOrder(sOrderId, boOrder, bcOrder);
if(found) {
//Sync the Order lines with the Parts Tracker
Gen_UpdateLineType(boOrder, bcOrder, sOrderId);
}
//If there is a main assembly or Part Tracker items with a Used Qty less than the Picked Qty, create a Return Order
Ret_QuoteToReturnOrder(sQuoteId);
//Delete lines from the sales order that after syncing with the parts tracker ended up with a 0 Actual Qty
CheckOrderPartsNotUsed(sOrderId);
//For Respec SRs, the actual hours clocked against the service labor activities need to be determined
//to update the labor quantity on the order for each Technician billing product used
var srSubType = bcQuote.GetFieldValue("CMI SR Sub Type");
TheApplication().Utility.logVars("SR Sub Type", srSubType);
if (srSubType == "Respec") {
Respec_UpdateOrderLine(sOrderId);
}
//Once all changes to the order are made, refresh the stamped order total
if(found) {
bcOrder.InvokeMethod("SetRefreshRollups")
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcOrder = null;
boOrder = null;
// sInput = null;
// sWFMgr = null;
TheApplication().Utility.logUnstack(sOrderId);
}
}

CMI Invoice Reconciliation Process BS_c
Gen_UpdatePartsOnOrder
/******************************************
Created By : IX964
Created On : Dec 21, 2011
Method Name: UpdatePartsOnOrder
C&I Number:
Requirement #:
Functionality: This method is to update order part line item with parts movement data.
Input: OrderId, QuoteNumber
Output:
******************************************/
function Gen_UpdatePartsOnOrder(boAction, bcAction, boOrder, bcOrder, sOrderId) {
try {
TheApplication().Utility.logStack("Gen_UpdatePartsOnOrder", this);
var bcActionParts = boAction.GetBusComp("FS Activity Parts Movement");
var bcOrderItem = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
with(bcActionParts) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("Product Name");
ActivateField("Product Id");
ActivateField("Used Quantity");
ActivateField("Write In Serial Number");
ActivateField("CMI Return");
ActivateField("CMI Return Quantity");
ActivateField("CMI Quoted Quantity");
ActivateField("Trunk Invloc Id");
SetSearchSpec("Used Quantity", "> 0");
//Sort so that quoted items processed first so they will find matches on the order and
//unquoted items will result in an inserted order line
SetSortSpec("CMI Quoted Quantity (DESC)");
ExecuteQuery(ForwardBackward); //Change to forwardbackward to insure unique product records
var bHasPartsMove = FirstRecord();
TheApplication().Utility.logVars("1st Part line Found?", bHasPartsMove);
while(bHasPartsMove) {
var sProductId = GetFieldValue("Product Id");
TheApplication().Utility.logStep("Process Part ("+sProductId+"): "+GetFieldValue("Product Name"));
Gen_UpdateOrderItem(bcOrderItem,
sOrderId,
sProductId,
GetFieldValue("Trunk Invloc Id"), //Source Inventory Id
ToNumber(GetFieldValue("Used Quantity")),
GetFieldValue("Write In Serial Number"),
GetFieldValue("CMI Return"), //Part Tracker Return
GetFieldValue("CMI Return Quantity"),
GetFieldValue("CMI Quoted Quantity"),
bcOrder.GetFieldValue("Price List Id"),
bcOrder.GetFieldValue("CMI IsRebuild"))
bHasPartsMove = NextRecord();
}// end while(bHasPartsMove)
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcOrderItem = null;
bcActionParts=null;
TheApplication().Utility.logUnstack();
}
}//end function

CMI Invoice Reconciliation Process BS_c
Gen_UpdateOrderItem
function Gen_UpdateOrderItem(bcOrderItem, orderId, prodId, sourceId, usedQty, serialNum, partTrkReturn, returnQty, quoteQty, priceListId, rebuild)
{
/*************************************************************************************************************************
Created By : ix964
Created On : 21-Dec-10
Functionality: Update each order line with correct quantities from the part tracker line
************************************************************************************************************************/
try {
TheApplication().Utility.logStack("Gen_UpdateOrderItem", this);
var sTotalQty = 0;
var sSearch = "";
var bErrorFlag = "N";
var sZERO = 0;
var sParentId="";//Added by KM330 for defect 2687
var sRootProductDef = "";//Added by KM330 for defect 2687
var bHasOrderItem;
var sStrSearch, mainAssembly;
var core = TheApplication().InvokeMethod("LookupValue", "CMI_RETURN", "Core");
var returnType = "";
var sOLIId;
//All Order Items are created with a 0 Actual Quantity from the signal except for Main assembly which
//takes the Quantity Requested from the quote. Query matches order lines created from quote by Product.
with(bcOrderItem) {
ActivateField("Adjusted List Price");
ActivateField("Net Price");
ActivateField("Line Number");
ActivateField("Cost");
ActivateField("Asset Id");
ActivateField("Product Id");
ActivateField("Quantity Requested");
ActivateField("Extended Quantity Requested");
ActivateField("CMI Actual Quantity");
ActivateField("CMI Serial Number");
ActivateField("CMI Quantity Quoted");
ActivateField("Destination Inventory Loc Id");
ActivateField("Source Inventory Loc Id");
ActivateField("CMI Return");
ActivateField("CMI Line Type");
ActivateField("Parent Order Item Id");
ActivateField("Root Product Def Type Code");
ActivateField("Covered Quote Item Id");
ActivateField("CMI Covered Main Assembly Flag");
ActivateField("CMI Main Assembly Flag");
ActivateField("CMI Product Return");
SetViewMode(AllView);
ClearToQuery();
sSearch = "[Product Id] = '" + prodId + "' AND [CMI Actual Quantity] = '" + sZERO + "' AND [Parent Order Item Id] IS NULL";
SetSearchExpr(sSearch);
ExecuteQuery(ForwardBackward);
bHasOrderItem = FirstRecord();
TheApplication().Utility.logVars("Line Found?", bHasOrderItem);
if(bHasOrderItem) {
returnType = GetFieldValue("CMI Product Return");
sParentId = GetFieldValue("Parent Order Item Id");
sRootProductDef = GetFieldValue("Root Product Def Type Code");
var sLineType = GetFieldValue("CMI Line Type");
var reconType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type");
var reconReturnType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type");
var noReturn = TheApplication().InvokeMethod("LookupValue", "CMI_RETURN", "No Return");
sOLIId = GetFieldValue("Id");
var covItemId = GetFieldValue("Covered Quote Item Id");
var covMainAsby = GetFieldValue("CMI Covered Main Assembly Flag");
TheApplication().Utility.logStep("Line "+GetFieldValue("Line Number")+" ("+sOLIId+") - Product Def/Parent Id: "+sRootProductDef+" / "+sParentId);
if((sRootProductDef!="Customizable" && sRootProductDef!= "Bundle") || (sParentId == null || sParentId == "")) {
SetFieldValue("Quantity Requested", usedQty);
SetFieldValue("Extended Quantity Requested", usedQty);
SetFieldValue("CMI Actual Quantity", usedQty);
SetFieldValue("CMI Return", partTrkReturn);
SetFieldValue("Source Inventory Loc Id", sourceId);
SetFieldValue("Destination Inventory Loc Id", ""); //Jq487: added for fixing defect 833
SetFieldValue("CMI Quantity Quoted", quoteQty);//By JQ487: for fixing defect 4827, 4831
TheApplication().Utility.logVars("Serial #", serialNum);
if (serialNum != "") {
SetFieldValue("CMI Serial Number", serialNum);
}
WriteRecord();
//For Core Parents and dirty Cores of a Main Assembly, find the related lines.
TheApplication().Utility.logVars("Product Return Type", returnType, "Covered Item - Id/Main Assembly", covItemId+" / "+covMainAsby);
if ((returnType == core) || (covItemId != "" && covMainAsby == "Y")) {
//For Main assembly's, parent is not on the Parts Tracker, just the Dirty Core
//Update Clean Core inventory by querying by product id of the dirty core
//Also need to include the Main Assembly in the query so quantity can be updated
if (covItemId != "" && covMainAsby == "Y") {
sStrSearch = "([Parent Order Item Id] = '" + covItemId + "' AND [Product Id] = '"+prodId+"') OR [Id] = '" + covItemId + "'";
} else {
//For non main assemblys, Query for the Recon Return and Recon related lines
sStrSearch = "[Covered Quote Item Id] = '" + sOLIId + "' OR [Parent Order Item Id] = '" + sOLIId + "'";
}
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr(sStrSearch);
ExecuteQuery(ForwardBackward);
bHasOrderItem = FirstRecord();
TheApplication().Utility.logVars("Dependent Line Found?", bHasOrderItem);
while(bHasOrderItem) {
c; // By: jv351 to fix defect 521/259/530
mainAssembly = GetFieldValue("CMI Main Assembly Flag");
sLineType = GetFieldValue("CMI Line Type");
//For non main assemblies, if the Return on Parts Tracker = No Return,
//the dirty core should be removed from the Sales Order. Otherwise just update
TheApplication().Utility.logVars("PT Return/Line Type/Main Asbly", partTrkReturn+" / "+sLineType+" / "+mainAssembly);
if(covMainAsby != "Y" && covItemId != "" &&
partTrkReturn == noReturn && sLineType == reconReturnType) {
DeleteRecord();
bHasOrderItem = FirstRecord();
} else {
Gen_ProcessDependentLines(bcOrderItem, sLineType, sourceId, mainAssembly,
covMainAsby, usedQty, returnQty, quoteQty);
bHasOrderItem = NextRecord();
}
}//end while (bHasOrderItem)
} //end if search for dependent lines
}//end if parent record or non customizeable product
} else {//can't find the Order Item so create a new one
var price = null;
var cost = null;
TheApplication().Utility.logVars("Price List Id", priceListId);
if(priceListId != "" && priceListId != null) {
var sOut = TheApplication().NewPropertySet();
Gen_GetPriceList(priceListId, prodId, sOut);
cost = sOut.GetProperty("Cost");
price = sOut.GetProperty("Price");
}
NewRecord(NewAfter);//crate new line item
SetFieldValue("CMI Serial Number", serialNum);
SetFieldValue("Quantity Requested", usedQty);
SetFieldValue("Extended Quantity Requested", usedQty);
SetFieldValue("CMI Actual Quantity", usedQty);
SetFieldValue("CMI Quantity Quoted", 0);
SetFieldValue("CMI Return", partTrkReturn);
if (price != null) {
SetFieldValue("Adjusted List Price", price);
SetFieldValue("Net Price", price);
}
if (cost != null) {
SetFieldValue("Cost", cost);
}
SetFieldValue("Source Inventory Loc Id", sourceId);
var bcPickProduct:BusComp = GetPicklistBusComp("Product");
with(bcPickProduct) {
SetViewMode(AllView);
ActivateField("CMI Return");
ClearToQuery();
SetSearchSpec("Product ID", prodId);
ExecuteQuery(ForwardBackward);
var haveProduct = FirstRecord();
TheApplication().Utility.logVars("Product Found?", haveProduct);
if(haveProduct) {
returnType = GetFieldValue("CMI Return");
Pick();
}
}//end with
//THere is a WriteRecord at the conculsion of WriteRecord
Gen_ProcessLine(bcOrderItem, rebuild)
// WriteRecord();
//Check if the Part Tracker item added is a core
TheApplication().Utility.logVars("Product Return Type", returnType);
if (returnType == core) {
//If a Core, need to add clean/dirty core items to the order
sOLIId = GetFieldValue("Id");
TheApplication().SetProfileAttr("Order Line Item Id", sOLIId);
TheApplication().SetProfileAttr("Order Id", orderId);
var svc = TheApplication().GetService("CMI Add Core Product");
svc.InvokeMethod("AddCoreOrder", TheApplication().NewPropertySet(), TheApplication().NewPropertySet());
var sStrElseSearch = "[Covered Quote Item Id] = '" + sOLIId + "' OR [Parent Order Item Id] = '" + sOLIId + "'";
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr(sStrElseSearch);
ExecuteQuery(ForwardBackward);
bHasOrderItem = FirstRecord();
TheApplication().Utility.logVars("Clean/Dirty Lines Found", bHasOrderItem);
while(bHasOrderItem) {
sLineType = GetFieldValue("CMI Line Type");
//If the Return on Parts Tracker = No Return, the dirty core should be removed
//from the Sales Order. Otherwise just update
TheApplication().Utility.logVars("PT Return/Line Type", partTrkReturn+" / "+sLineType);
if(partTrkReturn == noReturn && sLineType == reconReturnType) {
DeleteRecord();
bHasOrderItem = FirstRecord();
} else {
Gen_ProcessDependentLines(bcOrderItem, sLineType, sourceId, "", "",
usedQty, returnQty, quoteQty);
bHasOrderItem = NextRecord();
}
}//end while (bHasOrderItem)
} //end if core added
}//end else (order item not found)
}//end with(bcOrderItem)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPickProduct=null;
sOut = null;
svc = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS_c
Gen_UpdateLineType
/*******************************************************************************************
Created By :< Aaron Liu>
Created On : <2/21/2011>
Method Name:UpdateLineType(Inputs,Outputs)
C&I Number:
Requirement #:
Functionality: UpdateLineType
Update -- Replaced Status with CMI Status for SetFieldValue to bypass the statemodel validation by ki795 on 3-Nov-2011 for bug # DBUNG00000314
****************************************************************************************** */
function Gen_UpdateLineType(boOrder, bcOrder, sOrderId) {
try {
TheApplication().Utility.logStack("UpdateLineType", this);
var bcOrderItem:BusComp = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
var bcOrderAction:BusComp;
var bcAssocOrder:BusComp;
var oQuoteBO:BusObject;
var oActionBC:BusComp;
var Parts = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Part");
var Misc = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Misc");
var Labor = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
var sIsRebuild = bcOrder.GetFieldValue("CMI IsRebuild");
var sSRId = bcOrder.GetFieldValue("Service Request Id");
var sQuoteId = bcOrder.GetFieldValue("Quote Id");
var sQuoteNum = bcOrder.GetFieldValue("Quote Number");//<CMI DBU><CQ Def: DBUNG00001449><By JQ486 on 29th Aug 2011>
var found;
//Translate and set Line Types
TheApplication().Utility.logVars("Rebuild", sIsRebuild);
with(bcOrderItem) {
ActivateField("CMI Main Assembly Flag");
ActivateField("Product Type");
ActivateField("Line Number");
ActivateField("Product");
ActivateField("CMI Line Type");
ActivateField("CMI Write In Identifier");//KM330 for defect592
SetViewMode(AllView);
ClearToQuery();
ExecuteQuery(ForwardBackward);
found = FirstRecord();
TheApplication().Utility.logVars("First Order Line found?", found);
while(found) {
//C&I 4657 Enhancement# S138
Gen_ProcessLine(bcOrderItem, sIsRebuild);
found = NextRecord();
}//end while(haveRecord)
}//end with(bcOrderItem)
//Query for Parts Tracker and Service Labor Activities
oQuoteBO = TheApplication().GetBusObject("Quote");
oActionBC = oQuoteBO.GetBusComp("Action (Quote Order)");
bcOrderAction = boOrder.GetBusComp("Order Activities");
var completed = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Completed");
var done = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Done");
var sDoneTravel:String = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Done Travel");
var sRepairComplete:String = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Repair Complete");
var sDiagComplete:String = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Diagnostics Complete");
var sUnScheduled:String = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Unscheduled");
var sScheduled:String = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Scheduled");
var partsTracker:String = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Parts Tracker");
var toolSchedule:String = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Tool Schedule");
var serviceLabor:String = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Service Labor");
var sActStatus:String;
var sActType;
with(oActionBC) {
ActivateField("Order Id");
ActivateField("Type");
ActivateField("Status");
ActivateField("Rate List");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Quote Number",sQuoteNum);//<CMI DBU><CQ Def: DBUNG00001449><Added Querying with Quote Number><By JQ486 on 29th Aug 2011>
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("First Activity found?", found);
while(found) {
sActType = GetFieldValue("Type");
TheApplication().Utility.logStep("Process Activity ("+GetFieldValue("Id")+"): "+sActType);
//Associate the order
SetFieldValue("Order Id", sOrderId);
bcOrderAction.NewRecord(NewBefore);
bcOrderAction.SetFieldValue("Order Id", sOrderId);
bcOrderAction.SetFieldValue("Activity Id", GetFieldValue("Id"));
bcOrderAction.WriteRecord();
//Close the Activities
if(sActType == partsTracker) {
SetFieldValue("Status", completed);
} else {
//Change the status to complete only if the previous status is Done Travel,
//Repair Complete or Diagnostic Complete as per s256
sActStatus = GetFieldValue("Status");
TheApplication().Utility.logVars("Activity Status", sActStatus);
if(sActStatus.valueOf() == sDoneTravel.valueOf() || sActStatus.valueOf() == sRepairComplete.valueOf() || sActStatus.valueOf() == sDiagComplete.valueOf()) {//added .valueOf(), jq486, 23 sep 2011.
SetFieldValue("Status", completed);
}
if(sActType == toolSchedule) {
if(sActStatus.valueOf() == sUnScheduled.valueOf() || sActStatus.valueOf() == sScheduled.valueOf()) {//added .valueOf(), jq486, 23 sep 2011.
SetFieldValue("Status", completed);
}
}
}
WriteRecord();
var sCurrentStatus = GetFieldValue("Status");
TheApplication().Utility.logVars("Before Completed Status", sCurrentStatus);
//Bypass cost calculation on activities in Cancelled /Done / non completed
// status by ki795 on 4-Nov-2011
if (sCurrentStatus == completed && sActType != partsTracker) {
TheApplication().Utility.logVars("Rate List", GetFieldValue("Rate List"));
InvokeMethod("RefreshRecord");
InvokeMethod("CompleteActivity");
}
sActStatus = GetFieldValue("Status");
TheApplication().Utility.logVars("Before Done Status", sCurrentStatus);
if(sActStatus.valueOf() == completed) {
InvokeMethod("RefreshRecord");
SetFieldValue("Status", done);
WriteRecord();
}
//For each Parts Tracker record, sync used qty with the new order
if (sActType == partsTracker) {
Gen_UpdatePartsOnOrder(oQuoteBO, oActionBC, boOrder, bcOrder, sOrderId);
}
found = NextRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcOrderAction = null;
bcAssocOrder = null;
bcOrderItem = null;
oActionBC = null;
oQuoteBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS_c
Gen_QuoteToOrder
function Gen_QuoteToOrder(sQuoteId)
{
try {
TheApplication().Utility.logStack("Gen_QuoteToOrder", this);
var sOrderId;
//Instantiate the global source quote
with (bcQuote) {
SetViewMode(AllView);
ActivateField("Status");
ActivateField("Quote Number");
ActivateField("Service Request Id");
ActivateField("CMI SR Sub Type");
ActivateField("CMI SR Business Unit");
ActivateField("CMI Primary Division Id");
ActivateField("CMI Default Inventory Location Id");
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardOnly);
//Set a profile attribute to prevent the refresh in the signal when called from script
TheApplication().SetProfileAttr("SkipRefresh", "TRUE");
bcQuote.InvokeMethod("AutoOrderSalesQuote");
//Profile Attribute set in Order Entry - Orders new record event
sOrderId = TheApplication().GetProfileAttr("OrderId")
}// end with
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().SetProfileAttr("SkipRefresh", "");
TheApplication().Utility.logUnstack(sOrderId);
}
return (sOrderId);
}

CMI Invoice Reconciliation Process BS_c
Gen_ProcessLine
function Gen_ProcessLine(bcOrderItem, sIsRebuild)
{
try {
TheApplication().Utility.logStack("Gen_ProcessLine", this);
with (bcOrderItem) {
var sProdType = GetFieldValue("Product Type");
var sMainAssembly = GetFieldValue("CMI Main Assembly Flag");
var sLIType = GetFieldValue("CMI Line Type");
var sWriteInIdentifier = GetFieldValue("CMI Write In Identifier");//KM330 for defect 592
TheApplication().Utility.logStep("Process Line "+GetFieldValue("Line Number")+" ("+GetFieldValue("Product")+") Prod Type / Main / WriteIn / Line Type : "+sProdType+" / "+sMainAssembly+" / "+sWriteInIdentifier+" / "+sLIType);
if(sIsRebuild=="Y") {//Rebuild process
if (sProdType == "Misc" || sProdType == "Labor") {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Rebuild Resource"));
} else if(sMainAssembly == "Y") {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Rebuild Assembly"));
} else {
if((sLIType == null) || (sLIType == "") || (sWriteInIdentifier == "Yes")) {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Rebuild Material"));
}
}
} else {
if ((sProdType == "Misc") || (sProdType == "Labor")) {
if(sWriteInIdentifier == "Yes") {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Order Line Component"));
} else {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Order Line Charges"));
}
} else {
if((sLIType == null) || (sLIType == "") || (sWriteInIdentifier == "Yes")) {
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Order Line Component"));
}
}
}//End C&I 4657 Enhancement# S138
WriteRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS_c
Gen_InstantiateOrder
function Gen_InstantiateOrder(sOrderId, boOrder, bcOrder)
{
try {
TheApplication().Utility.logStack("Gen_InstantiateOrder", this);
TheApplication().Utility.logVars("Order Id", sOrderId);
var found;
with(bcOrder) {
ActivateField("CMI IsRebuild");
ActivateField("Service Request Id");
ActivateField("Quote Id");
ActivateField("Quote Number");
ActivateField("Price List Id");
ActivateField("CMI IsRebuild");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(found);
}
return(found);
}

CMI Invoice Reconciliation Process BS_c
Gen_ProcessDependentLines
function Gen_ProcessDependentLines(bcOrderItem, sLineType, sInventoryId, mainAssembly, covMainAsby, sUsedQuantity, sReturnQty, sQuoteQty) {
try {
TheApplication().Utility.logStack("Gen_ProcessDependentLines", this);
var reconType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type");
var reconReturnType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type");
var sTotalQty;
with(bcOrderItem) {
TheApplication().Utility.logVars("Main Assembly", mainAssembly);
if (sLineType == reconReturnType) {
//If this is the clean core for a main assembly, the return quantity from
//the parts tracker will be 0 so use the Used Quantity instead
if (covMainAsby == "Y") {
sTotalQty = sUsedQuantity * -1;
} else {
sTotalQty = sReturnQty * -1;
}
TheApplication().Utility.logVars("Set Actual Qty To", sTotalQty,4);
SetFieldValue("CMI Actual Quantity", sTotalQty);
SetFieldValue("CMI Quantity Quoted", (sQuoteQty * -1));
SetFieldValue("Source Inventory Loc Id", "");
SetFieldValue("Destination Inventory Loc Id", sInventoryId);
SetFieldValue("Extended Quantity Requested", sTotalQty);
SetFieldValue("Quantity Requested", sTotalQty);
} else if (sLineType == reconType) {
SetFieldValue("CMI Actual Quantity", sUsedQuantity); // By: jq487 to fix defect 521/491/530
SetFieldValue("CMI Quantity Quoted", sQuoteQty);//By JQ487: for fixing defect 4827, 4831
SetFieldValue("Source Inventory Loc Id", sInventoryId);
SetFieldValue("Destination Inventory Loc Id", "");
SetFieldValue("Extended Quantity Requested", sUsedQuantity); // By: jq487 to fix defect 521/491/530
SetFieldValue("Quantity Requested", sUsedQuantity);
} else if (mainAssembly == "Y") {
TheApplication().Utility.logVars("Set Actual Qty To", sUsedQuantity,4);
SetFieldValue("CMI Actual Quantity", sUsedQuantity); // By: jq487 to fix defect 521/491/530
SetFieldValue("CMI Quantity Quoted", sQuoteQty);//By JQ487: for fixing defect 4827, 4831
SetFieldValue("Destination Inventory Loc Id", "");
SetFieldValue("Extended Quantity Requested", sUsedQuantity); // By: jq487 to fix defect 521/491/530
SetFieldValue("Quantity Requested", sUsedQuantity);
}
WriteRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS_c
(declarations)
/*Global Varibles*/
var boQuote:BusObject = TheApplication().GetBusObject("Quote");
var bcQuote:BusComp = boQuote.GetBusComp("Quote");
var sParentSRId:String;
var sRelatedSRId:String;
var sQuoteId:String;
var sInvokeLevel:String;
var i:Number;
var j:Number;
var cntRSR:String;
var cntQuote:String;
var sPSRId:String;
var sRSRId:String;
//Respec - Add Labor
var sCost:Number = 0;
var sDurHr:Number = 0;
var sTotalCost:Number = 0;
var sTotalDurHr:Number = 0;
var sProdId = "";
var sCostListCost = 0;

CMI Invoice Reconciliation Process BS_c
CheckOrderPartsNotUsed
function CheckOrderPartsNotUsed(sOrderId)
{
try
{
TheApplication().Utility.logStack("CheckOrderPartsNotUsed", this);
var boOrder = TheApplication().GetBusObject("Order Item");
var bcOrderItem = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
var sMisc = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Misc");
var sLabor = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
with (bcOrderItem)
{
SetViewMode(AllView);
ActivateField("Product");
ActivateField("CMI Actual Quantity");
ActivateField("Line Number");
ClearToQuery();
/* var searchst = "[Order Header Id] = '" + sOrderId + "' AND [CMI Main Assembly Flag] <> 'Y' AND " +
"[CMI Actual Quantity] = 0 AND [Product Type] <> '" + sMisc + "' AND [Product Type] <> '" + sLabor + "'";
*/
/*CRQ000000111571 03MAR14 HF lq447, removed MISC type in above line*/
var searchst = "[Order Header Id] = '" + sOrderId + "' AND [CMI Main Assembly Flag] <> 'Y' AND " + "[CMI Actual Quantity] = 0 AND ([Product Type] <> '" + sMisc + "' AND [Product] = 'Write-In Service') AND [Product Type] <> '" + sLabor + "'";
SetSearchExpr(searchst);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Empty Lines (" + sOrderId + ") found?", FirstRecord());
while (FirstRecord())
{
TheApplication().Utility.logVars("Delete #/Line/Product", GetFieldValue("Id") + "/" + GetFieldValue("Line Number") + "/" + GetFieldValue("Product"));
DeleteRecord();
}
} //end with(bcOrderItem)
}
catch (e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
bcOrderItem = null;
boOrder = null;
TheApplication().Utility.logUnstack();
}
}

CMI Invoice Reconciliation Process BS_c
Gen_GetPriceList
function Gen_GetPriceList(sPriceListId, sProductId, sOut)
{
/*************************************************************************************************************************
Created By : ix964
Created On : 7-Jan-11
Method Name:
Functionality:
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
//try catch added by shanmukh for code clean up 08/27/2011
try {
TheApplication().Utility.logStack("Gen_GetPriceList", this);
var sCost;
var price;
var boPrice = TheApplication().GetBusObject("Admin Price List");
var bcPrice = boPrice.GetBusComp("Price List");
var bcPriceItem = boPrice.GetBusComp("Price List Item");
with(bcPrice) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sPriceListId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
with(bcPriceItem) {
ActivateField("Cost");
ActivateField("Original List Price");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Product Id", sProductId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
sCost = GetFieldValue("Cost");
price = GetFieldValue("Original List Price");
}
sOut.SetProperty("Cost", sCost);
sOut.SetProperty("Price", price);
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPriceItem = null;
bcPrice = null;
boPrice = null;
TheApplication().Utility.logUnstack(price);
}
}

CMI Mass Updates
InsertProdInvLocs
function InsertProdInvLocs(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("InsertProdInvLocs", this);
var boProduct:BusObject = TheApplication().GetBusObject("Admin ISS Product Definition");
var bcProduct:BusComp = boProduct.GetBusComp("Internal Product - ISS Admin");
var bcMVGOrg:BusComp;
var bcInvLoc:BusComp;
var bcAssocInvLoc:BusComp;
var max = Inputs.GetProperty("Max");
var reload = Inputs.GetProperty("Reload");
var constraint = Inputs.GetProperty("Search");
var searchExpr = "";
var prodCount = 0;
var orgCount = 0;
var errCount = 0;
var firstPartChar = 0;
var range = "";
var charBank2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var charBank = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789%)./";
var charIndex2 = 0;
var charIndex = 0;
var currentChar;
var currentChar2;
var range2 = "";
var process;
var process2 = true;
var orgFound = false;
var locFound = false;
var currentInvLocId = "";
var logText = "";
var found;
//Outer loop reduces the number of records per cursor to < 10000
while (process2 && (ToNumber(prodCount) < ToNumber(max) || max == "")) {
process = true;
currentChar2 = charBank2.charAt(charIndex2);
if (currentChar2 != "") charIndex2++;
else process2 = false;
while (process && process2 && (ToNumber(prodCount) < ToNumber(max) || max == "")) {
currentChar = charBank.charAt(charIndex);
if (currentChar != "") charIndex++;
else {
charIndex = 0;
process = false;
currentChar = '"';
}
TheApplication().Utility.logStep("Process Row Id Character: "+currentChar2+"; Name Character: "+currentChar);
with(bcProduct) {
SetViewMode(AllView);
InvokeMethod("SetAdminMode", "TRUE");
ActivateField("IMS Identifier");
ClearToQuery();
SetSearchSpec("Name", "~LIKE '*"+currentChar);
SetSearchSpec("Id", "LIKE '*"+currentChar2);
if (reload.toUpperCase() == "FALSE" || reload.toUpperCase() == "N" || reload == "") SetSearchSpec("IMS Identifier","IS NULL");
if (constraint != "") {
searchExpr = GetSearchExpr();
searchExpr += " AND "+constraint;
SetSearchExpr(searchExpr);
}
ExecuteQuery(ForwardBackward);
found = FirstRecord();
// TheApplication().Utility.logVars("1st Product Found", found);
while (found && (ToNumber(prodCount) < ToNumber(max) || max == "")) {
// TheApplication().Utility.logStep("Process "+GetFieldValue("Id")+ " "+GetFieldValue("Name"));
logText = GetFieldValue("Name");
try {
bcMVGOrg = GetMVGBusComp("Organization");
bcInvLoc = GetMVGBusComp("CMI MV Product Orderable");
bcAssocInvLoc = bcInvLoc.GetAssocBusComp();
with (bcMVGOrg) {
ClearToQuery();
ActivateField("Orderable");
ActivateField("CMI Serialized Flag");
ActivateField("Status");
ActivateField("CMI Default Inventory Location Id");
ActivateField("CMI Default Inventory Location");
ExecuteQuery(ForwardBackward);
orgFound = FirstRecord();
while (orgFound) {
// TheApplication().Utility.logStep("Process "+GetFieldValue("Name")+" - Default:"+GetFieldValue("CMI Default Inventory Location"));
currentInvLocId = GetFieldValue("CMI Default Inventory Location Id");
if (currentInvLocId != "") {
bcInvLoc.ClearToQuery();
bcInvLoc.ActivateField("Inventory Name");
bcInvLoc.ActivateField("CMI Product Orderable");
bcInvLoc.ActivateField("CMI Product Serialized");
bcInvLoc.ActivateField("CMI Product Status");
bcInvLoc.SetSearchSpec("Id", currentInvLocId);
bcInvLoc.ExecuteQuery(ForwardBackward);
locFound = bcInvLoc.FirstRecord();
// TheApplication().Utility.logVars("Location ("+currentInvLocId+") found", found);
if (locFound) {
bcInvLoc.SetFieldValue("CMI Product Orderable", bcMVGOrg.GetFieldValue("Orderable"));
bcInvLoc.SetFieldValue("CMI Product Serialized", bcMVGOrg.GetFieldValue("CMI Serialized Flag"));
bcInvLoc.SetFieldValue("CMI Product Status", bcMVGOrg.GetFieldValue("Status"));
bcInvLoc.WriteRecord()
logText += " "+bcMVGOrg.GetFieldValue("CMI Default Inventory Location") + " Exists.";
} else {
bcAssocInvLoc.ClearToQuery();
bcAssocInvLoc.ActivateField("Inventory Name");
bcAssocInvLoc.SetSearchSpec("Id", currentInvLocId);
bcAssocInvLoc.ExecuteQuery(ForwardBackward);
// TheApplication().Utility.logVars("Associate Location ("+currentInvLocId+") found", bcAssocInvLoc.FirstRecord());
if (bcAssocInvLoc.FirstRecord()) {
bcAssocInvLoc.Associate(NewBefore);
orgCount++;
bcInvLoc.SetFieldValue("CMI Product Orderable", bcMVGOrg.GetFieldValue("Orderable"));
bcInvLoc.SetFieldValue("CMI Product Serialized", bcMVGOrg.GetFieldValue("CMI Serialized Flag"));
bcInvLoc.SetFieldValue("CMI Product Status", bcMVGOrg.GetFieldValue("Status"));
bcInvLoc.WriteRecord()
logText += " "+bcInvLoc.GetFieldValue("Inventory Name") + " Added.";
}
}//end else (location not found in MVG)
}//end if default location populated
orgFound = NextRecord();
}//end org while
}//end with
SetFieldValue("IMS Identifier","Y");
WriteRecord();
prodCount++;
} catch(e) {
// UndoRecord();
errCount++;
TheApplication().Utility.logError(e);
}
TheApplication().Utility.logStep(logText);
found = NextRecord();
} //end product while
} //end with
}//end inner counter while
}//end outer counter while
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcAssocInvLoc = null;
bcInvLoc = null;
bcMVGOrg = null;
bcProduct = null;
boProduct = null;
TheApplication().Utility.logUnstack("Products: "+prodCount+" Orgs: "+orgCount+" Errors: "+errCount);
}
}

CMI Mass Updates
UpdateQIWarrantyRollups
function UpdateQIWarrantyRollups(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("UpdateQIWarrantyRollups", this);
var boQuote = TheApplication().GetBusObject("CMI Quote Item");
var bcQuoteItem = boQuote.GetBusComp("Quote Item (Simple)");
var max = Inputs.GetProperty("Max");
var count = 0;
var sumDiscount = 0;
var sumExtPrice = 0;
var sumVendorDiscount = 0;
var process = true;
var lineNumber = 0;
var range = "";
//Outer loop reduces the number of records per cursor to < 10000
while (process) {
lineNumber += 1;
if (lineNumber < 10) range = lineNumber;
else {
range = ">= 10";
process = false;
}
TheApplication().Utility.logStep("Process Line Number "+range);
with(bcQuoteItem) {
SetViewMode(AllView);
InvokeMethod("SetAdminMode", "TRUE");
ActivateField("CMI Warranty Discount - Calc");
ActivateField("CMI Total Extended Price - Calc");
ActivateField("CMI Non Internal Warranty Percentage - Calc");
ActivateField("CMI Warranty Discount");
ActivateField("CMI Total Extended Price");
ActivateField("CMI Non Internal Warranty Percentage");
ClearToQuery();
SetSearchSpec("Line Number", range);
// SetSearchSpec("CMI Warranty Discount - Calc", "> 0");
SetSearchSpec("CMI QT - Service", "Y");
SetSearchSpec("CMI Warranty Discount", "IS NULL");
ExecuteQuery(ForwardBackward);
var found = FirstRecord();
TheApplication().Utility.logVars("1st Quote Item Found", found);
while(found && (count < ToNumber(max) || max == "")) {
sumDiscount = GetFieldValue("CMI Warranty Discount - Calc");
sumExtPrice = GetFieldValue("CMI Total Extended Price - Calc");
sumVendorDiscount = GetFieldValue("CMI Non Internal Warranty Percentage - Calc");
TheApplication().Utility.logStep("Process "+GetFieldValue("Id")+ " %/Ext/Vendor == "+sumDiscount+" / "+sumExtPrice+" / "+sumVendorDiscount);
SetFieldValue("CMI Warranty Discount", sumDiscount);
SetFieldValue("CMI Total Extended Price", sumExtPrice);
SetFieldValue("CMI Non Internal Warranty Percentage", sumVendorDiscount);
WriteRecord();
count++;
found = NextRecord();
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcQuoteItem = null;
boQuote = null;
TheApplication().Utility.logUnstack(count);
}
}

CMI Mass Updates
UpdateOLRollups
function UpdateOLRollups(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("UpdateOLRollups", this);
var boOrder = TheApplication().GetBusObject("Order Entry");
var bcOrder = boOrder.GetBusComp("Order Entry - Orders");
var max = Inputs.GetProperty("Max");
var count = 0;
var errCount = 0;
var sumPrice = 0;
var sumMargin = 0;
var sumCost = 0;
var sumTax = 0;
var charBank = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890";
var charIndex = 1;
var currentChar = "A";
var process2 = true;
//Outer loop reduces the number of records per cursor to < 10000
while (process2) {
TheApplication().Utility.logStep("Process Character: "+currentChar);
with(bcOrder) {
SetViewMode(AllView);
InvokeMethod("SetAdminMode", "TRUE");
ActivateField("CMI Total Cost Calc");
ActivateField("CMI Total Margin Calc");
ActivateField("CMI Total Billable Sell Calc");
ActivateField("CMI Total Tax Amount");
ActivateField("CMI Total Margin");
ActivateField("CMI Total");
ActivateField("CMI Total Cost");
ActivateField("Tax Amount");
ClearToQuery();
SetSearchSpec("Id", "LIKE '*"+currentChar);
// SetSearchSpec("CMI Order Type", "not like '*Parts*'");
ExecuteQuery(ForwardBackward);
var found = FirstRecord();
TheApplication().Utility.logVars("1st Order Found (max)", found+" ("+max+")");
while(found && (count < ToNumber(max) || max == "")) {
sumPrice = GetFieldValue("CMI Total Billable Sell Calc");
sumMargin = GetFieldValue("CMI Total Margin Calc");
sumCost = GetFieldValue("CMI Total Cost Calc");
sumTax = GetFieldValue("CMI Total Tax Amount");
TheApplication().Utility.logStep("Process "+GetFieldValue("Id")+ " Price/Margin/Cost/Tax == "+sumPrice+" / "+sumMargin+" / "+sumCost+" / "+sumTax);
try {
SetFieldValue("CMI Total", sumPrice);
SetFieldValue("CMI Total Margin", sumMargin);
SetFieldValue("CMI Total Cost", sumCost);
SetFieldValue("Tax Amount", sumTax);
WriteRecord();
count++;
} catch(e) {
UndoRecord();
errCount++;
TheApplication().Utility.logError(e);
}
found = NextRecord();
}
currentChar = charBank.charAt(charIndex);
if (currentChar != "") charIndex++;
else process2 = false;
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcOrder = null;
boOrder = null;
TheApplication().Utility.logUnstack(count+" Errors: "+errCount);
}
}

CMI Mass Updates
UpdateOIWarrantyRollups
function UpdateOIWarrantyRollups(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("UpdateOIWarrantyRollups", this);
var boOrder = TheApplication().GetBusObject("Order Entry");
var bcOrderItem = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
var max = Inputs.GetProperty("Max");
var count = 0;
var errCount = 0;
var sumDiscount = 0;
var sumExtPrice = 0;
var sumVendorDiscount = 0;
var lineNumber = 0;
var range = "";
var charBank = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890";
var charIndex = 0;
var currentChar;
var range2 = "";
var process = true;
var process2 = true;
//Outer loop reduces the number of records per cursor to < 10000
while (process2 && (count < ToNumber(max) || max == "")) {
process = true;
currentChar = charBank.charAt(charIndex);
if (currentChar != "") charIndex++;
else process2 = false;
while (process && (count < ToNumber(max) || max == "")) {
lineNumber += 1;
if (lineNumber < 10) range = lineNumber;
else {
lineNumber = 0;
range = ">= 10";
process = false;
}
TheApplication().Utility.logStep("Process Character: "+currentChar+"; Line Number: "+range);
with(bcOrderItem) {
SetViewMode(AllView);
InvokeMethod("SetAdminMode", "TRUE");
ActivateField("CMI Warranty Discount - Calc");
ActivateField("CMI Total Extended Price - Calc");
ActivateField("CMI Non Internal Warranty Percentage - Calc");
ActivateField("CMI Warranty Discount");
ActivateField("CMI Total Extended Price");
ActivateField("CMI Non Internal Warranty Percentage");
ClearToQuery();
SetSearchSpec("Line Number", range);
SetSearchSpec("Id", "LIKE '*"+currentChar);
// SetSearchSpec("CMI Warranty Discount - Calc", "> 0");
SetSearchSpec("CMI Warranty Discount", "IS NULL");
SetSearchSpec("CMI Order Type", "not like '*Parts*'");
ExecuteQuery(ForwardBackward);
var found = FirstRecord();
TheApplication().Utility.logVars("1st Order Item Found", found);
while(found && (count < ToNumber(max) || max == "")) {
sumDiscount = GetFieldValue("CMI Warranty Discount - Calc");
sumExtPrice = GetFieldValue("CMI Total Extended Price - Calc");
sumVendorDiscount = GetFieldValue("CMI Non Internal Warranty Percentage - Calc");
TheApplication().Utility.logStep("Process "+GetFieldValue("Id")+ " %/Ext/Vendor == "+sumDiscount+" / "+sumExtPrice+" / "+sumVendorDiscount);
try {
SetFieldValue("CMI Warranty Discount", sumDiscount);
SetFieldValue("CMI Total Extended Price", sumExtPrice);
SetFieldValue("CMI Non Internal Warranty Percentage", sumVendorDiscount);
WriteRecord();
count++;
} catch(e) {
UndoRecord();
errCount++;
TheApplication().Utility.logError(e);
}
found = NextRecord();
}
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcOrderItem = null;
boOrder = null;
TheApplication().Utility.logUnstack(count+" Errors: "+errCount);
}
}

CMI Mass Updates
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retValue = CancelOperation;
switch (MethodName) {
case "UpdateQIWarrantyRollups":
UpdateQIWarrantyRollups(Inputs, Outputs);
break;
case "UpdateOIWarrantyRollups":
UpdateOIWarrantyRollups(Inputs, Outputs);
break;
case "UpdateOLRollups":
UpdateOLRollups(Inputs, Outputs);
break;
case "UpdateQLRollups":
UpdateQLRollups(Inputs, Outputs);
break;
case "InsertProdInvLocs":
InsertProdInvLocs(Inputs, Outputs);
break;
default:
break;
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retValue);
}
return (retValue);
}

CMI Mass Updates
UpdateQLRollups
function UpdateQLRollups(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("UpdateQLRollups", this);
var boQuote = TheApplication().GetBusObject("CMI Quote");
var bcQuote = boQuote.GetBusComp("CMI Quote Simple");
var max = Inputs.GetProperty("Max");
var count = 0;
var errCount = 0;
var sumPrice = 0;
var sumMargin = 0;
var sumCost = 0;
var sumTax = 0;
var charBank = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890";
var charIndex = 1;
var currentChar = "A";
var process2 = true;
//Outer loop reduces the number of records per cursor to < 10000
while (process2) {
TheApplication().Utility.logStep("Process Character: "+currentChar);
with(bcQuote) {
SetViewMode(AllView);
InvokeMethod("SetAdminMode", "TRUE");
ActivateField("CMI Total Cost Calc");
ActivateField("CMI Quote Margin Calc");
ActivateField("CMI Quote Total Calc");
ActivateField("Current Quote Total Item Tax");
ActivateField("CMI Total Margin");
ActivateField("CMI Quote Total");
ActivateField("CMI Total Cost");
ActivateField("Tax Amount");
ClearToQuery();
SetSearchSpec("Id", "LIKE '*"+currentChar);
// SetSearchSpec("CMI Order Type", "not like '*Parts*'");
ExecuteQuery(ForwardBackward);
var found = FirstRecord();
TheApplication().Utility.logVars("1st Order Found (max)", found+" ("+max+")");
while(found && (count < ToNumber(max) || max == "")) {
sumPrice = GetFieldValue("CMI Quote Total Calc");
sumMargin = GetFieldValue("CMI Quote Margin Calc");
sumCost = GetFieldValue("CMI Total Cost Calc");
sumTax = GetFieldValue("Current Quote Total Item Tax");
TheApplication().Utility.logStep("Process "+GetFieldValue("Id")+ " Price/Margin/Cost/Tax == "+sumPrice+" / "+sumMargin+" / "+sumCost+" / "+sumTax);
try{
SetFieldValue("CMI Quote Total", sumPrice);
SetFieldValue("CMI Total Margin", sumMargin);
SetFieldValue("CMI Total Cost", sumCost);
SetFieldValue("Tax Amount", sumTax);
WriteRecord();
count++;
} catch(e) {
UndoRecord();
errCount++;
TheApplication().Utility.logError(e);
}
found = NextRecord();
}
currentChar = charBank.charAt(charIndex);
if (currentChar != "") charIndex++;
else process2 = false;
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcQuote = null;
boQuote = null;
TheApplication().Utility.logUnstack(count+" Errors: "+errCount);
}
}

CMI One Off Test BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if (MethodName == "Handle Property")
{
HandleProperty(Inputs, Outputs);
return (CancelOperation);
}
return (ContinueOperation);
}
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
}

CMI One Off Test BS
HandleProperty
function HandleProperty(Inputs, Outputs)
{
try
{
var tempMassage = Inputs.Copy();
tempMassage.GetChild(0).GetChild(0).GetChild(0).GetChild(0).RemoveChild(1);
Outputs.SetProperty("HandleMessage",tempMassage);
}catch(e)
{
throw e;
}finally
{
}
}

CMI Opportunity Price Service
GetPriceAll
/*************************************************************************************************************************
Created By : James Jin
Created On : 27th December 2010
Method Name: function GetPrice()
C&I Number : NA
Requirement # : NA
Functionality: This function refresh Opportunity Product price
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function GetPriceAll()
{
try{
var boOpportunity = TheApplication().ActiveBusObject();
var bcOpportunityProduct = boOpportunity.GetBusComp("Opportunity Product");
with(bcOpportunityProduct)
{
ClearToQuery();
ExecuteQuery(ForwardBackward);
var bHasRecord = FirstRecord();
while(bHasRecord)
{
GetItemPrice();
bHasRecord = NextRecord();
}
}
}
catch(e)//Added by jr429(try catch block)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally
{
boOpportunity=null;
bcOpportunityProduct=null;
}
}

CMI Opportunity Price Service
GetItemPrice
/*************************************************************************************************************************
Created By : James Jin
Created On : 27th December 2010
Method Name: function GetPrice()
C&I Number : NA
Requirement # : NA
Functionality: This function refresh Opportunity Product price
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function GetItemPrice()
{
try//Added by jr429(try catch block)
{
var bothis = TheApplication().ActiveBusObject();
var bcthis = bothis.GetBusComp("Opportunity Product");
var sProdId = bcthis.GetFieldValue("Product Id");
var sPriceListId = bothis.GetBusComp("Opportunity").GetFieldValue("Account Price List Id");
if(sProdId != "" && sPriceListId != "")
{
var bsPriceManager = TheApplication().GetService("Pricing Manager");
var psInputs = TheApplication().NewPropertySet();
var psOutputs = TheApplication().NewPropertySet();
psInputs.SetProperty("Product Id",sProdId);
psInputs.SetProperty("Price List Id",sPriceListId);
bsPriceManager.InvokeMethod("GetProductListPrice",psInputs,psOutputs);
bcthis.SetFieldValue("Product Price",ToNumber(psOutputs.GetProperty("List Price")));
psInputs = null;
psOutputs = null;
bsPriceManager = null;
}
else
{
bcthis.SetFieldValue("Product Price",0);
}
}
catch(e) //Added by jr429(try catch block)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}
finally//Added by jr429(try catch block)
{
bothis=null;
bcthis=null;
//added by shanmukh for code clean up 08/27/2011
sPriceListId = null;
}
}

CMI Opportunity Price Service
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//try catch added by shanmukh for code clean up 08/27/2011
try
{
if(MethodName == "GetItemPrice")
{
if(TheApplication().ActiveBusObject().Name() == "Opportunity")
{
GetItemPrice();
}
else
{
Outputs.SetProperty("Error Code","2");
Outputs.SetProperty("Error Message","This service can only invoke in 'Opportunity' BO!");
}
return (CancelOperation);
}
if(MethodName == "GetPriceAll")
{
if(TheApplication().ActiveBusObject().Name() == "Opportunity")
{
GetPriceAll();
}
else
{
Outputs.SetProperty("Error Code","2");
Outputs.SetProperty("Error Message","This service can only invoke in 'Opportunity' BO!");
}
return (CancelOperation);
}
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}//end of catch
return (ContinueOperation);
}

CMI Order Default BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : Pankaj Sinha
Created On : 26th January 2010
Method Name: Service_PreInvokeMethod (MethodName) == "Query"
Functionality: This business service will be invoked when user try to open the Bill To Account # Pick Applet for Order Default Interface.
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try{
switch (MethodName)
{
case "Init" :
Outputs.SetProperty ("CMI Account Class", "");
Outputs.SetProperty ("CMI BackOffice Bill To Account Num", "");
Outputs.SetProperty ("CMI BackOffice Ship To Account Num", "");
Outputs.SetProperty ("CMI BackOffice Bill To Account Name", "");
Outputs.SetProperty ("CMI BackOffice Ship To Account Name", "");
Outputs.SetProperty ("CMI Siebel Bill To Account Name", "");
Outputs.SetProperty ("CMI Carrier", "");
Outputs.SetProperty ("CMI Due Date Code", "");
Outputs.SetProperty ("CMI Inventory Location", "");
Outputs.SetProperty ("CMI Must ship Complete Flag", "");
Outputs.SetProperty ("CMI Premium Code", "");
Outputs.SetProperty ("CMI Prepaid by Amount", "");
Outputs.SetProperty ("CMI Prepaid by Weight", "");
Outputs.SetProperty ("CMI Pro Forma Flag", "");
Outputs.SetProperty ("CMI Prohibit Carrier Override", "");
//Outputs.SetProperty ("CMI Shipment Method", "");
Outputs.SetProperty ("CMI Shipping Terms", "");
Outputs.SetProperty ("CMI Siebel Bill To Account Id", "");
Outputs.SetProperty ("CMI Siebel Order Id", "");
Outputs.SetProperty ("CMI Source System", "");
Outputs.SetProperty ("CMI Special Care Flag", "");
Outputs.SetProperty ("CMI UCM Billing Account Number", "");
Outputs.SetProperty ("CMI Currency Code", "");
return (CancelOperation);
break;
case "Query" :
var OrderBU = TheApplication().GetProfileAttr("OrderBU");
var OrderAcct = TheApplication().GetProfileAttr("OrderAcct");
var OrderBillAcct = TheApplication().GetProfileAttr("OrderBillAcct");
var OrderId = TheApplication().GetProfileAttr("OrderId");
if (OrderBU == "")
{
TheApplication().RaiseErrorText("Please add Business Unit before proceeding.");
return(CancelOperation);
}
if (OrderAcct == "")
{
TheApplication().RaiseErrorText("Please add Ship To Account before proceeding.");
return(CancelOperation);
}
var inpPS = TheApplication().NewPropertySet();
var outPS = TheApplication().NewPropertySet();
var oBS = TheApplication().GetService("Workflow Process Manager");
inpPS.SetProperty("ShipToAccountId", OrderAcct);
inpPS.SetProperty("BusinessUnit", OrderBU);
inpPS.SetProperty("BillToAccountId", OrderBillAcct);
inpPS.SetProperty("OrderId", OrderId);
inpPS.SetProperty("ProcessName", "CMI Order Defaults Update Integration Workflow");
oBS.InvokeMethod("RunProcess", inpPS, outPS);
var strErrCode = outPS.GetProperty("Error Code");
var strErrMsg = outPS.GetProperty("Error Message");
var sOrder = TheApplication().NewPropertySet();
if (strErrMsg == "")
{
if (outPS.GetChild(0).GetChild(0).GetChild(0).GetChildCount() > 1) //Checks the presence of ListOfbody
{
if (outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChildCount() > 0) //Checks the presence of body
{
if(outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChildCount() > 0) //Checks the presence of ListOfOrder
{
if(outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChild(0).GetChildCount() > 0) //Checks the presence of ListOfOrder
{
if(outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChildCount() > 0) //Checks the presence of Order
{
sOrder = outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChild(0).GetChild(0);
var invcount=sOrder.GetChildCount();
if (invcount > 0)
{
var SiebelOrderId = new Array;
var BackOfficeShipToAccountNumber = new Array;
var BackOfficeBillToAccountNumber = new Array;
var SiebelBillToAccountId = new Array;
var ShippingTerms = new Array;
//var ShipmentMethod = new Array;
var PrepaidByWeight = new Array;
var PrepaidByAmount = new Array;
var InventoryLocation = new Array;
var Carrier = new Array;
var DueDateCode = new Array;
var MustShipCompleteFlag = new Array;
var SpecialCareFlag = new Array;
var ProFormaFlag = new Array;
var PremiumCode = new Array;
var ProhibitCarrierOverride = new Array;
var SourceSystem = new Array;
var AccountClass = new Array;
var BackOfficeBillToAccountName = new Array;
var BackOfficeShipToAccountName = new Array;
var SiebelBillToAccountName = new Array;
var CurrencyCode = new Array;
TheApplication().SetProfileAttr("OrderDefaultsFlag","Y");
for (var i=0;i<invcount;i++)
{
SiebelOrderId[i] = sOrder.GetChild(i).GetProperty("SiebelOrderId");
BackOfficeShipToAccountNumber[i] = sOrder.GetChild(i).GetProperty("BackOfficeShipToAccountNumber");
BackOfficeBillToAccountNumber[i] = sOrder.GetChild(i).GetProperty("BackOfficeBillToAccountNumber");
SiebelBillToAccountId[i] = sOrder.GetChild(i).GetProperty("SiebelBillToAccountId");
ShippingTerms[i] = sOrder.GetChild(i).GetProperty("ShippingTerms");
//ShipmentMethod[i] = sOrder.GetChild(i).GetProperty("ShipmentMethod");
PrepaidByWeight[i] = sOrder.GetChild(i).GetProperty("PrepaidByWeight");
PrepaidByAmount[i] = sOrder.GetChild(i).GetProperty("PrepaidByAmount");
InventoryLocation[i] = sOrder.GetChild(i).GetProperty("InventoryLocation");
Carrier[i] = sOrder.GetChild(i).GetProperty("Carrier");
DueDateCode[i] = sOrder.GetChild(i).GetProperty("DueDateCode");
MustShipCompleteFlag[i] = sOrder.GetChild(i).GetProperty("MustShipCompleteFlag");
SpecialCareFlag[i] = sOrder.GetChild(i).GetProperty("SpecialCareFlag");
ProFormaFlag[i] = sOrder.GetChild(i).GetProperty("ProFormaFlag");
PremiumCode[i] = sOrder.GetChild(i).GetProperty("PremiumCode");
ProhibitCarrierOverride[i] = sOrder.GetChild(i).GetProperty("ProhibitCarrierOverride");
SourceSystem[i] = sOrder.GetChild(i).GetProperty("SourceSystem");
AccountClass[i] = sOrder.GetChild(i).GetProperty("AccountType");
BackOfficeBillToAccountName[i] = sOrder.GetChild(i).GetProperty("BackOfficeBillToAccountName");
BackOfficeShipToAccountName[i] = sOrder.GetChild(i).GetProperty("BackOfficeShipToAccountName");
SiebelBillToAccountName[i] = sOrder.GetChild(i).GetProperty("SiebelBillToAccountName");
CurrencyCode[i] = sOrder.GetChild(i).GetProperty("CurrencyCode");
var sOrderData = TheApplication().NewPropertySet();
sOrderData.SetProperty ("CMI Siebel Order Id",SiebelOrderId[i]);
sOrderData.SetProperty ("CMI BackOffice Ship To Account Num",BackOfficeShipToAccountNumber[i]);
sOrderData.SetProperty ("CMI BackOffice Bill To Account Num",BackOfficeBillToAccountNumber[i]);
sOrderData.SetProperty ("CMI Siebel Bill To Account Id",SiebelBillToAccountId[i]);
sOrderData.SetProperty ("CMI Shipping Terms",ShippingTerms[i]);
//sOrderData.SetProperty ("CMI Shipment Method",ShipmentMethod[i]);
sOrderData.SetProperty ("CMI Prepaid by Weight", PrepaidByWeight[i]);
sOrderData.SetProperty ("CMI Prepaid by Amount", PrepaidByAmount[i]);
sOrderData.SetProperty ("CMI Inventory Location", InventoryLocation[i]);
//Commented by Pankaj Sinha on 30-March-2010 and set the profile attribute at BC PreSetFieldValue.
//TheApplication().SetProfileAttr("InventoryName",InventoryLocation[i]);
sOrderData.SetProperty ("CMI Carrier", Carrier[i]);
sOrderData.SetProperty ("CMI Due Date Code", DueDateCode[i]);
sOrderData.SetProperty ("CMI Must ship Complete Flag", MustShipCompleteFlag[i]);
sOrderData.SetProperty ("CMI Special Care Flag", SpecialCareFlag[i]);
sOrderData.SetProperty ("CMI Pro Forma Flag", ProFormaFlag[i]);
sOrderData.SetProperty ("CMI Premium Code", PremiumCode[i]);
sOrderData.SetProperty ("CMI Prohibit Carrier Override", ProhibitCarrierOverride[i]);
sOrderData.SetProperty ("CMI Source System", SourceSystem[i]);
sOrderData.SetProperty ("CMI Account Class", AccountClass[i]);
sOrderData.SetProperty ("CMI Siebel Bill To Account Name", SiebelBillToAccountName[i]);
sOrderData.SetProperty ("CMI BackOffice Bill To Account Name", BackOfficeBillToAccountName[i]);
sOrderData.SetProperty ("CMI BackOffice Ship To Account Name", BackOfficeShipToAccountName[i]);
sOrderData.SetProperty ("CMI Currency Code", CurrencyCode[i]);
Outputs.AddChild(sOrderData);
}
}
}
}
}
}
}
}
else
{
TheApplication().SetProfileAttr("InterfaceErrMsg",strErrMsg);
}
return (CancelOperation);
break;
}
}// end of try
catch(e)
{
throw(e);
}// end of catch
finally
{
sOrderData = null;
sOrder = null;
outPS = null;
inpPS = null;
oBS = null;
OrderBillAcct = null;
OrderBU = null;
OrderAcct = null;
}
return (ContinueOperation);
}

CMI Parts Movement Update BS
(declarations)
//global declaration
var PrevProd;
var SRId;
var QuoteId;
var OLIId;
var sSubInvent;
//Global Variables
var sReturn:String;

CMI Parts Movement Update BS
NonSerialCheck
function NonSerialCheck(SRId,sProductId,sProduct,PrevProdCount,sQty,sPartAlloc,sSubInvent)
/*CMI DBU:JQ486:26/Nov/2010: The Below function is used to update the Non Serialized parts in
part tracke BC on sync with the order line items updated from Oracle*/
{
try
{
var IsActivityRec;
var IsPartTrackRec;
var oBO = TheApplication().GetBusObject("Action");
var oBCAction = oBO.GetBusComp("Action");
var oBCPartTracker = oBO.GetBusComp("CMI Activity Parts Movement");
var sPartCount;
var RemainRecords = 1;
var NeedNewRecord;
with(oBCAction)
{
ActivateField("Activity SR Id");
ActivateField("CMI Quote Number");//JQ486:Changed CMI Quote Number From Quote Id.
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Activity SR Id", SRId);
SetSearchSpec("CMI Quote Number", QuoteId);//JQ486:Changed CMI Quote Number From Quote Id.
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker"));
ExecuteQuery(ForwardBackward);
IsActivityRec = FirstRecord()
while(IsActivityRec)
{
var ActivityId = GetFieldValue("Id");
with(oBCPartTracker)
{
ActivateField("CMI Parts Allocated");
ActivateField("Order Item Id");
//ActivateField("CMI OLI Sub Inventory");//Added as per def 473:JQ486
//ActivateField("Trunk Invloc Name");//Added by JQ487 as per def 672
ActivateField("Trunk Invloc Id");//Added by JQ487 as per def 672
//CMI <Release# 1DBU>,C&I# 4455Enhancement# S154<Configuration>: <activating field for CMI return > By km558 On 05/10/11
ActivateField("CMI Return");
SetViewMode(AllView)
ClearToQuery();
SetSearchSpec("Product Id", sProductId);
ExecuteQuery(ForwardBackward);
var sPCNextRecord = FirstRecord();
//If Record is not found in Part Tracker.
if(sPCNextRecord == false)
{
NeedNewRecord=1;
RemainRecords = PrevProdCount;
}
//If Record is found in Part Tracker.
if(sPCNextRecord)
{ sPartAlloc = sPartAlloc;
var sPartUpdated = GetFieldValue("CMI Parts Allocated");
SetFieldValue("CMI Parts Allocated",ToNumber(sPartAlloc)+ToNumber(sPartUpdated));
SetFieldValue("Order Item Id",OLIId);//Added as per def 473:JQ486
//SetFieldValue("CMI OLI Sub Inventory",sSubInvent);//Commented by JQ487 on 28/03/2011 as per def 672
//SetFieldValue("Trunk Invloc Name", sSubInvent);//Added by JQ487 as per def 672
SetFieldValue("Trunk Invloc Id", sSubInvent);//Added by JQ487 as per def 672
//CMI <Release# 1DBU>,C&I# 4455Enhancement# S154<Configuration>: <setting field for CMI return> By km558 On 05/10/11
SetFieldValue("CMI Return", sReturn);
WriteRecord();
}//end of if(sPCNextRecord)
//Creation of new part tracker records if no records are found.
if(NeedNewRecord==1)
{
for(var k=1;k <= RemainRecords;k++)
{
NewRecord(NewAfter);
SetFieldValue("Product Name", sProduct);
SetFieldValue("Used Quantity",0);
SetFieldValue("CMI Quoted Quantity",0);
SetFieldValue("CMI Parts Allocated", sPartAlloc);
SetFieldValue("Order Item Id",OLIId);//Added as per def 473:JQ486
//SetFieldValue("CMI OLI Sub Inventory",sSubInvent);//Commented by JQ487 on 28/03/2011 as per def 672
//SetFieldValue("Trunk Invloc Name", sSubInvent);//Added by JQ487 as per def 672
SetFieldValue("Trunk Invloc Id", sSubInvent);//Added by JQ487 as per def 672
//CMI <Release# 1DBU>,C&I# 4455Enhancement# S154<Configuration>: <setting field for CMI return> By km558 On 05/10/11
SetFieldValue("CMI Return", sReturn);
WriteRecord();
}
}// End of if(NeedNewRecord==1)
}//End of with(oBCPartTracker)
IsActivityRec = NextRecord();
}//End of while(IsActivityRec)
}//End of with(oBCAction)
}//End of try
catch(e)
{
throw(e);
}
finally
{
oBCPartTracker = null;
oBCAction = null;
//added by shanmukh for code clean up 08/27/2011
oBO = null;
}
}//End of function

CMI Parts Movement Update BS
PartsUpdate
function PartsUpdate(OrderId)
/*CMI DBU:JQ486:26/Nov/2010: The Below function is used to scheck the number of part line items updated
in the Update OLI from Oracle and identifying if the parts are serialized or non serialized. Based on
the serialize check, this will call the SerialCheck or NonSerialCheck function*/
{
try
{
//var oBO = TheApplication().ActiveBusObject();
var oBO = TheApplication().GetBusObject("Order Entry (Sales)");//Coomented active bhusobject and using Get bus object instead by JQ487 on 09/20/2011
//var oBO = TheApplication().ActiveBusObject();
//var oBO = TheApplication().GetBusObject("Order Entry");
var oBCOrders = oBO.GetBusComp("Order Entry - Orders");
var OBCOrderLItem = oBO.GetBusComp("Order Entry - Line Items");
OBCOrderLItem.ActivateField("Order Quote Id");//Added as per def 473:JQ486
OBCOrderLItem.ActivateField("CMI Serial Number");
OBCOrderLItem.ActivateField("CMI Qty Consumed");
//OBCOrderLItem.ActivateField("CMI Sub Inventory");
OBCOrderLItem.ActivateField("Destination Inventory Loc Id");
//CMI <Release# 1DBU>,C&I# 4455Enhancement# S154<Configuration>: <activating field for CMI Return> By km558 On 05/10/11
OBCOrderLItem.ActivateField("CMI Return");
var sCount;
var PrevProdCount = 1;
var IsOLIRec;
with(oBCOrders)
{
ActivateField("Service Request Id");
ActivateField("Quote Number");//JQ486:Changed Quote Number From Quote Id.
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",OrderId);
ExecuteQuery(ForwardBackward);
QuoteId = GetFieldValue("Quote Number");//JQ486:Changed Quote Number From Quote Id.
var IsOrderRec = FirstRecord();
while(IsOrderRec)
{
SRId = GetFieldValue("Service Request Id");
IsOrderRec = NextRecord();
}
}
with(OBCOrderLItem)
{
OLIId = OBCOrderLItem.GetFieldValue("Id");
var sProductId = OBCOrderLItem.GetFieldValue("Product Id");
var sProduct = OBCOrderLItem.GetFieldValue("Product");
var sQty = OBCOrderLItem.GetFieldValue("Quantity Requested");
var SerialNum = OBCOrderLItem.GetFieldValue("CMI Serial Number");
var sPartAlloc = ToNumber(OBCOrderLItem.GetFieldValue("CMI Qty Consumed"));
//sSubInvent = OBCOrderLItem.GetFieldValue("CMI Sub Inventory");//Added as per def 473:JQ486
sSubInvent = OBCOrderLItem.GetFieldValue("Destination Inventory Loc Id");
//CMI <Release# 1DBU>,C&I# 4455Enhancement# S154<Configuration>: <getting value of field for CMI Return> By km558 On 05/10/11
sReturn = OBCOrderLItem.GetFieldValue("CMI Return");
if((SerialNum == "") || (SerialNum == null))
{
/*Calling the fn to create/update records in the part tracker for the nonserialized part in the
Order Line Item*/
NonSerialCheck(SRId,sProductId,sProduct,1,sQty,sPartAlloc,sSubInvent);
}
else
{
/*Calling the fn to create/update records in the part tracker for the serialized part in the
Order Line Item.*/
PrevProd = sProduct;
SerialCheck (SRId,sProductId,PrevProd,PrevProdCount,sQty,sPartAlloc,SerialNum,sSubInvent);//din
}
}//End of with(OBCOrderLItem)
}//End of Try
catch(e)
{
throw e;
}
finally
{
sPartAlloc = null;
sQty = null;
sProductId = null;
sProduct = null;
OBCOrderLItem = null;
oBCOrders = null;
oBO = null;
}
}//end of function

CMI Parts Movement Update BS
SerialCheck
function SerialCheck(SRId,sProductId,PrevProd,PrevProdCount,sQty,sPartAlloc,SerialNum,sSubInvent)
/*CMI DBU:JQ486:26/Nov/2010: The Below function is used to update the Serialized parts in
part tracke BC on sync with the order line items updated from Oracle*/
{
try
{
var IsActivityRec;
var IsPartTrackRec;
var oBO = TheApplication().GetBusObject("Action");
var oBCAction = oBO.GetBusComp("Action");
var oBCPartTracker = oBO.GetBusComp("CMI Activity Parts Movement");
var sPartCount;
var RemainRecords = 1;
var NeedNewRecord;
with(oBCAction)
{
ActivateField("Activity SR Id");
ActivateField("CMI Quote Number");//JQ486:Changed CMI Quote Number From Quote Id.
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Activity SR Id",SRId);
SetSearchSpec("CMI Quote Number", QuoteId);//JQ486:Changed CMI Quote Number From Quote Id.
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker"));
ExecuteQuery(ForwardBackward);
IsActivityRec = FirstRecord();
while(IsActivityRec)
{
var ActivityId = GetFieldValue("Id");
with(oBCPartTracker)
{
SetViewMode(AllView)
ActivateField("Used Quantity");
ActivateField("Write In Serial Number");
ActivateField("CMI Parts Allocated");
ActivateField("Order Item Id");
//ActivateField("CMI OLI Sub Inventory");
//ActivateField("Trunk Invloc Name");//Added by JQ487 as per def 672
ActivateField("Trunk Invloc Id");//Added by JQ487 as per def 672
//CMI <Release# 1DBU>,C&I# 4455Enhancement# S154<Configuration>: <activating field for CMI return > By km558 On 05/10/11
ActivateField("CMI Return");
ClearToQuery();
SetSearchSpec("Product Id", sProductId);
SetSearchSpec("Write In Serial Number",SerialNum);
ExecuteQuery(ForwardBackward);
var sPCNextRecord = FirstRecord();
//If Record is not found in Part Tracker.
if(sPCNextRecord == false)
{
SetViewMode(AllView)
ClearToQuery();
SetSearchSpec("Product Id", sProductId);
SetSearchSpec("Write In Serial Number","is NULL");
ExecuteQuery(ForwardBackward);
var sPCNextRecord1 = FirstRecord();
//If Record is not found in Part Tracker.
if(sPCNextRecord1 == false)
{
RemainRecords = PrevProdCount;
for(var k=1;k <= RemainRecords;k++)
{
NewRecord(NewAfter);
SetFieldValue("Product Name",PrevProd);
SetFieldValue("Used Quantity",0);
SetFieldValue("CMI Quoted Quantity",0);
SetFieldValue("CMI Parts Allocated",sPartAlloc);
SetFieldValue("Write In Serial Number",SerialNum);
SetFieldValue("Order Item Id",OLIId);
//SetFieldValue("CMI OLI Sub Inventory",sSubInvent);//Commented by JQ487 on 28/03/2011 as per def 672
//SetFieldValue("Trunk Invloc Name", sSubInvent);//Added by JQ487 as per def 672
SetFieldValue("Trunk Invloc Id", sSubInvent);//Added by JQ487 as per def 672
//CMI <Release# 1DBU>,C&I# 4455Enhancement# S154<Configuration>: <setting field for CMI return> By km558 On 05/10/11
SetFieldValue("CMI Return", sReturn);
WriteRecord();
}
}
else
{
SetFieldValue("Write In Serial Number",SerialNum);
SetFieldValue("CMI Parts Allocated",1);
SetFieldValue("Order Item Id",OLIId);
//SetFieldValue("CMI OLI Sub Inventory",sSubInvent);//Commented by JQ487 on 28/03/2011 as per def 672
//SetFieldValue("Trunk Invloc Name", sSubInvent);//Added by JQ487 as per def 672
SetFieldValue("Trunk Invloc Id", sSubInvent);//Added by JQ487 as per def 672
//CMI <Release# 1DBU>,C&I# 4455Enhancement# S154<Configuration>: <setting field for CMI return> By km558 On 05/10/11
SetFieldValue("CMI Return", sReturn);
WriteRecord();
}
}
else
{
SetFieldValue("CMI Parts Allocated",1);
SetFieldValue("Order Item Id",OLIId);
//SetFieldValue("CMI OLI Sub Inventory",sSubInvent);
SetFieldValue("Trunk Invloc Id", sSubInvent);//Added by JQ487 as per def 672
//CMI <Release# 1DBU>,C&I# 4455Enhancement# S154<Configuration>: <setting field for CMI return> By km558 On 05/10/11
SetFieldValue("CMI Return", sReturn);
WriteRecord();
}
}//End of with(oBCPartTracker)
IsActivityRec = NextRecord();
}//End of while(IsActivityRec)
}//End of with(oBCAction)
}//End of try
catch(e)
{
throw(e);
}
finally
{
oBCPartTracker = null;
oBCAction = null;
//added by shanmukh for code clean up 08/27/2011
oBO = null;
}
}//End of function

CMI Parts Movement Update BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: JQ486,CMI DBU, Build Quote Repair Functionality(Part Tracker Section)
DESCRIPTION: This Script will be triggered to update records in the
part tracker BC based on the update on Order Line Items from Oracle.
DATE CREATED: 26 Nov 2010
UPDATES:
*********************************************************/
try
{
if (MethodName == "PartsUpdate")
{
var OrderId = TheApplication().GetProfileAttr("PartUpdateOrderId");
PartsUpdate(OrderId);
return(CancelOperation);
}
}//try
catch(e)
{
throw e;
}
//Commented by shanmukh for code clean up 08/18/2011
/*finally
{
}*/
}

CMI Parts Tracker BS
(declarations)
var sReturnQtyTotal = 0;
var sInvIdRet = "";
var boQuote:BusObject = TheApplication().GetBusObject("CMI Quote");
var bcQuote:BusComp = boQuote.GetBusComp("CMI Quote Simple");
var boPartTracker = TheApplication().GetBusObject("Action");
var bcPartTracker = boPartTracker.GetBusComp("Action");
var bcPTLines = boPartTracker.GetBusComp("FS Activity Parts Movement");
//created arrays, performance tuning, By jq486.
var aProdArr = new Array;
var aQuotedQtyArr = new Array;
var aAllocQtyArr = new Array;
var currentPTStatus = "";
var currentQuoteId = "";
//CMI DBU Release#1, Defect# 463, variable created to hold value of Return field of Line Item by JW919 on 11/08/2011
var sReturn = "";

CMI Parts Tracker BS
CheckPartRequestRequired
function CheckPartRequestRequired(sQuoteId)
{
/*CMI DBU:JQ487:19/Nov/2010: The Below function is used to Query on Quote BC to valdate that product of
type Part or Product are also present in QLI before creation of parts request. IF not product of type part/Product
is present, then this script sets a variable, which controls creation pf parts request order. This script is also
used for calculating the delta changes. */
try {
TheApplication().Utility.logStack("CheckPartRequestRequired", this);
var bcQuoteItem:BusComp = boQuote.GetBusComp("Quote Item (Simple)");
var prodTypeLabor = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
var prodTypeMisc = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Misc");
var writeInYes = TheApplication().InvokeMethod("LookupValue", "CMI_WRITE_IN_IDENTIFIER", "Yes");
var lineTypeRecon = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type");
var lineTypeReturn = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type");
var createRequest = false;
var sUpdQty = 0;
var sQtyDiff = 0;
var iQtyIdx;//Declaring Variable to capture the Qty Index
var sRev, sRevFlg, sMainFlg, sLineType, sWriteIn, sProdType, sProdName, EBSProdId, genProdId;
var sQty = 0;
var sQtyCal = 0;
var sMainFlgCount=0;
var found = false;
var sProdId;//<jq487> added to accomodate defect 657
var sPickQuan;//<jq487> added to accomodate defect 657
var sQuantQuoted;//<jq487> added to accomodate defect 657
var sSerialized;//<jq487> added to accomodate defect 657
sRev = bcQuote.GetFieldValue("Revision");
TheApplication().Utility.logVars("Revisions", sRev);
with (bcQuoteItem) {
SetViewMode(AllView);
ActivateField("Product Type");
ActivateField("CMI Revise Flag");
ActivateField("Quantity Requested");
ActivateField("CMI Quantity Requested");
ActivateField("Product Id");
ActivateField("Product");
ActivateField("CMI Serialized Flag");
ActivateField("CMI Parts Check");
ActivateField("CMI Main Assembly Flag");
ActivateField("CMI Line Type");
ActivateField("CMI External Prod Id");
ClearToQuery();
ExecuteQuery(ForwardBackward);
found = FirstRecord();
//Loop through each quote item
TheApplication().Utility.logVars("Quote Items Found?", found);
while(found) {
sProdType = GetFieldValue("Product Type");
sProdId = GetFieldValue("Product Id");
sRevFlg = GetFieldValue("CMI Revise Flag");
sQty = GetFieldValue("Quantity Requested");
sQtyCal = GetFieldValue("CMI Quantity Requested");
sProdName = GetFieldValue("Product");
sSerialized = GetFieldValue("CMI Serialized Flag");
sMainFlg = GetFieldValue("CMI Main Assembly Flag");
sLineType = GetFieldValue("CMI Line Type");
sWriteIn = GetFieldValue("CMI Write In Identifier");
EBSProdId = GetFieldValue("CMI External Prod Id");
genProdId = (EBSProdId != "" ? EBSProdId : sProdId);
TheApplication().Utility.logStep(sProdName+" ("+genProdId+") - Type / Line Type / Write In / Main: "+sProdType+" / "+sLineType+" / "+sWriteIn+" / "+sMainFlg);
//Exclude Clean/Dirty Core Lines; all Labor lines; Misc Part types except for
//Write In Service; and Main Assembly lines
if ((sProdType != prodTypeLabor) &&
(sProdType != prodTypeMisc || sWriteIn == writeInYes) &&
sLineType != lineTypeRecon && sLineType != lineTypeReturn && sMainFlg != "Y") {
TheApplication().Utility.logVars("Line Revised",sRevFlg);
if (sRevFlg == "Y") {
TheApplication().Utility.logVars("New/Prev Quantity", sQty+" / "+sQtyCal);
if (sQty != sQtyCal) {
sUpdQty = GetFieldValue("CMI ATP Requested Quantity");
TheApplication().Utility.logVars("ATP Requested Quantity", sUpdQty);
if (sUpdQty > 0) {
createRequest = true;
}
}
} else {
if(sRev > 1) {
TheApplication().Utility.logVars("Serialized", sSerialized);
if (sSerialized != "Y") {//this condition invokes Serial check func
//Since all write in products have the same siebel product row id, we indicate uniqueness by specifying the EBS Id
iQtyIdx = GetItemQty(genProdId);
sQuantQuoted = aQuotedQtyArr[iQtyIdx];
sQuantQuoted = (defined(sQuantQuoted) ? sQuantQuoted : 0);
sPickQuan = aAllocQtyArr[iQtyIdx];
sPickQuan = (defined(sPickQuan) ? sPickQuan : 0)
sQtyDiff = ToNumber(sQuantQuoted) + ToNumber(sQty);//<jq487> added to accomodate defect 657
//Account for pre staged products. If amount already picked is greater
//than what is requested, no need to create a Parts Request
TheApplication().Utility.logVars("Quoted Difference / Picked", sQtyDiff+" / "+sPickQuan);
if (sQtyDiff <= ToNumber(sPickQuan)) {//<jq487> added to accomodate defect 657
SetFieldValue("CMI Parts Check", "Y");//<jq487> added to accomodate defect 657
} else {
createRequest = true;
SetFieldValue("CMI Parts Check", "N");//<jq487> added to accomodate defect 657
SetFieldValue("CMI Quantity Requested", sPickQuan);//<jq487> added to accomodate defect 657
}
WriteRecord();
} else {
createRequest = true;
}
} else {
createRequest = true;
}
}
}
found = NextRecord();
}//end while
}//end with
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcQuoteItem = null;
TheApplication().Utility.logVars("Create Request?", createRequest);
TheApplication().Utility.logUnstack(createRequest);
}
return(createRequest);
}

CMI Parts Tracker BS
CallIPRUpdate
function CallIPRUpdate(Inputs, Outputs)
{
try
{
TheApplication().Utility.logStack("CallIPRUpdate", this);
var boOrder = TheApplication().GetBusObject("PDS Simplified Order");
var bcOrderEntry = boOrder.GetBusComp("PDS Simplified Order Entry - Orders");
var bcOrderLine = boOrder.GetBusComp("PDS Simplified Order Entry - Line Items");
var boQuote = TheApplication().GetBusObject("Quote");
var bcQuote = boQuote.GetBusComp("Quote");
var typeIntRet = TheApplication().InvokeMethod("LookupValue", "FS_ORDER_TYPE", "Internal Parts Return");
var partsFound = false;
var PName; var ReqQty;
var sOrderId = Inputs.GetProperty("Order Id");
TheApplication().Utility.logVars("sOrderId", sOrderId);
//var orderId ='1-AA2HU';
with(bcOrderEntry)
{
ClearToQuery();
SetViewMode(AllView);
//ActivateField("Root Order Id");
ActivateField("Quote Number");
ActivateField("CMI Order Type");
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
var isrec = FirstRecord();
TheApplication().Utility.logVars("Order Found?", isrec);
if(isrec)
{
//var soLov = GetFieldValue("CMI Order Type");
var qNum = GetFieldValue("Quote Number");
TheApplication().Utility.logVars("qNum", qNum);
with(bcOrderLine)
{
ActivateField("Quantity Requested");
ActivateField("Product");
ActivateField("CMI Parent Order Type");
SetViewMode(AllView);
ClearToQuery();
//SetSearchSpec("CMI Parent Order Type", typeIntRet);
ExecuteQuery(ForwardOnly);
partsFound = FirstRecord();
TheApplication().Utility.logVars("Line Found?", partsFound);
while (partsFound)
{
PName = GetFieldValue("Product");
ReqQty = GetFieldValue("Quantity Requested");
updateReturnQty(ReqQty,PName,qNum);
partsFound = NextRecord();
}
var sUpdated = "Yes";
TheApplication().Utility.logVars("Parts Tracker Updated?", sUpdated);
}//bcorderLine
}//if
}//End of bcOrderEntry
}//try
catch(e){
TheApplication().Utility.RaiseError(e);
}
finally {
if(defined(bcOrderEntry)) bcOrderEntry = null;
if(defined(bcOrderLine)) bcOrderLine = null;
if(defined(bcQuote)) bcQuote = null;
if(defined(boOrder)) boOrder = null;
if(defined(boQuote)) boQuote = null;
TheApplication().Utility.logUnstack();
}
}

CMI Parts Tracker BS
updateReturnQty
function updateReturnQty(ReqQty,PName,qNum)
{
try
{
TheApplication().Utility.logStack("updateReturnQty", this);
var boAction = TheApplication().GetBusObject("Quote");
var bcAction = boAction.GetBusComp("Action (Quote Order)");
var bcPartsTracker = boAction.GetBusComp("FS Activity Parts Movement");//CMI Activity Parts Movement");
var typePartReq = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Parts Tracker");
var qQty=0,uQty=0,rQty=0;
var ptId;
with(bcAction)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Quote Number");
SetSearchSpec("CMI Quote Number", qNum);
SetSearchSpec("Type",typePartReq)
ExecuteQuery(ForwardOnly);
var isRec = FirstRecord();
TheApplication().Utility.logVars("PT Activity Found?", isRec);
if(isRec)
{
with(bcPartsTracker)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Product Name");
ActivateField("CMI Parts Allocated");
ActivateField("CMI Return Quantity");
ActivateField("Used Quantity");
SetSearchSpec("Product Name",PName);
ExecuteQuery(ForwardOnly);
var fRecord = FirstRecord();
TheApplication().Utility.logVars("Parts Movement Found?", fRecord);
if(fRecord)
{
var len = PName.length;
var ReconProd = PName.substring(len-1);
if(ReconProd == "X" || ReconProd == "x")
{
SetFieldValue("CMI Return Quantity",ReqQty);
}
qQty = GetFieldValue("CMI Parts Allocated");
uQty = GetFieldValue("Used Quantity");
//ptId = GetFieldValue("Product Id");
//var oId= GetFieldValue("Order Id");
qQty = qQty-ReqQty;
uQty = uQty-ReqQty;
SetFieldValue("CMI Parts Allocated",qQty);
SetFieldValue("Used Quantity",uQty);
}//End of if
WriteRecord();
}//End of with(bcPartsTracker)
}//end of if
}//end of with(bcaction)
}//end of try
catch(e)
{
TheApplication().Utility.RaiseError(e);
}//end of catch(e)
finally
{
if(defined(bcPartsTracker)) bcPartsTracker = null;
if(defined(bcAction)) bcAction = null;
if(defined(boAction)) boAction = null;
TheApplication().Utility.logUnstack();
}//end of catch
}//end of fucntion

CMI Parts Tracker BS
UpdatePickedQty
function UpdatePickedQty()
{
//MJB 2/7/13: The Below function is used to update the Picked Qty of Parts Tracker line items when the order qty is updated
try {
TheApplication().Utility.logStack("UpdatePickedQty", this);
var activityFound;
var partFound = false;
var boAction = TheApplication().GetBusObject("Action");
var bcPartTracker = boAction.GetBusComp("CMI Activity Parts Movement");
var bcProduct;
var sPartCount;
var RemainRecords = 1;
var NeedNewRecord;
var totalPicked:Number = 0;
var boOrder:BusObject = TheApplication().GetBusObject("PDS Simplified Order");
var bcOrderLine:BusComp = boOrder.GetBusComp("PDS Simplified Order Entry - Line Items");
var lineId = TheApplication().GetProfileAttr("QtyPickedUpdLineId");
with (bcOrderLine) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Quote Number");
ActivateField("CMI Serial Number");
ActivateField("CMI Write In Identifier");
ActivateField("CMI Qty Consumed");
ActivateField("CMI External Product Id");
ActivateField("Destination Inventory Loc Id");
ActivateField("Product Id");
SetSearchSpec("Id", lineId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Line ("+lineId+") found?", FirstRecord());
if (FirstRecord()) {
var productId = GetFieldValue("Product Id");
var currentPicked = GetFieldValue("CMI Qty Consumed");
var subInventory = GetFieldValue("Destination Inventory Loc Id");
var quoteNum = GetFieldValue("CMI Quote Number");
var exteralProdId = GetFieldValue("CMI External Product Id");
var writeIn = GetFieldValue("CMI Write In Identifier");
var serialNum = GetFieldValue("CMI Serial Number");
}
}
TheApplication().Utility.logVars("Quote #", quoteNum);
if (quoteNum != "" && productId != "") {
with(bcPartTracker) {
ActivateField("Activity Id");
ActivateField("Write In Serial Number");
ActivateField("Product Name");
ActivateField("CMI Parts Allocated");
ActivateField("Order Item Id");
ActivateField("Trunk Invloc Id");//Added by JQ487 as per def 672
SetViewMode(AllView)
ClearToQuery();
SetSearchSpec("CMI Activity Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker"));
SetSearchSpec("Product Id", productId);
SetSearchSpec("CMI Quote Number", quoteNum);
if(writeIn=="Yes") {//added if block for defect 4075,KM330,11/01/12
//Multiple write in parts may exist on the same tracker. Only way to distingush is by the EBS Unique Id assigned
SetSearchSpec("CMI EBS Product Id", exteralProdId);
} else if (serialNum != "") {
//If multiple lines exist for the same serialized part, some may have a serial number assigned already
//and others may not. If the serial number exists on the part tracker, need to just update the qty. If not
//need to take one of the lines with no serial and assign it one
SetSearchSpec("Write In Serial Number", serialNum+" OR IS NULL");
SetSortSpec("Write In Serial Number (ASC)"); //Sort ascending so line with matching serial will come first
}
ExecuteQuery(ForwardBackward);
partFound = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker Line found?", partFound);
//If Record is found in Part Tracker, update the Picked qty. If Serialized assign the SN
if(partFound) {
TheApplication().Utility.logVars("Serial", serialNum);
if (serialNum != "") {
SetFieldValue("CMI Parts Allocated",1);
SetFieldValue("Write In Serial Number",serialNum);
} else {
//oldPicked = GetFieldValue("CMI Parts Allocated");
totalPicked = GetTotalPickedQty(bcOrderLine, productId, quoteNum);
TheApplication().Utility.logVars("Picked Current/Total", currentPicked+" / "+totalPicked);
SetFieldValue("CMI Parts Allocated", ToNumber(totalPicked));
}
SetFieldValue("Order Item Id",lineId);//Added as per def 473:JQ486
SetFieldValue("Trunk Invloc Id", subInventory);//Added by JQ487 as per def 672
WriteRecord();
} else {
//If no record is found create new
bcPartTracker.NewRecord(NewAfter);
bcProduct = bcPartTracker.GetPicklistBusComp("Product Name");
with (bcProduct) {
SetViewMode(AllView);
ClearToQuery()
SetSearchSpec("Product ID", productId);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) Pick();
}
SetFieldValue("Write In Serial Number",serialNum);
SetFieldValue("Used Quantity",0);
SetFieldValue("CMI Quoted Quantity",0);
SetFieldValue("CMI Parts Allocated", currentPicked);
SetFieldValue("Order Item Id",lineId);//Added as per def 473:JQ486
SetFieldValue("Trunk Invloc Id", subInventory);//Added by JQ487 as per def 672
WriteRecord();
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcProduct = null;
bcPartTracker = null;
boAction = null;
bcOrderLine = null;
boOrder = null;
TheApplication().Utility.logUnstack();
}
}

CMI Parts Tracker BS
UpdatePaymentLines
function UpdatePaymentLines(sQuoteId)
{
try {
TheApplication().Utility.logStack("UpdatePaymentLines", this);
var bcPayment = boQuote.GetBusComp("Payments (Simple)");
with (bcPayment) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("CMI Payments Accept Flag");
ExecuteQuery(ForwardBackward);
var isRec = FirstRecord();
while (isRec) {
SetFieldValue("CMI Payments Accept Flag","Y");
WriteRecord();
isRec = NextRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPayment = null;
TheApplication().Utility.logUnstack();
}
}

CMI Parts Tracker BS
UpdatePartTracker
function UpdatePartTracker(sQuoteNum)
{
// If the Quote was revised, the existing Parts Tracker may already be in Ship Complete. If that is
// the case, and a new Parts Request is going to be created, then update the status to Partial Ship
// MJB CQ 4873
try {
TheApplication().Utility.logStack("UpdatePartTracker", this);
var IsActivityRec;
var oBO = TheApplication().GetBusObject("Action");
var oBCAction = oBO.GetBusComp("Action (Quote Order)");
with(oBCAction) {
ActivateField("CMI Status");
ActivateField("Type");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Quote Number",sQuoteNum);
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker"));
ExecuteQuery(ForwardOnly);
IsActivityRec = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker Found?", IsActivityRec);
if(IsActivityRec) {
SetFieldValue("Status", TheApplication().InvokeMethod("LookupValue","EVENT_STATUS","Partial Ship"));
WriteRecord();
}//End of if(IsActivityRec)
}//End of with(oBCAction)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCAction = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Parts Tracker BS
UpdatePTStatusOnShipment
function UpdatePTStatusOnShipment(Inputs, Outputs)
{
//If the order is set to ship complete, query parts requests for the Quote # to see if there are any open
//and if NOT, set the Part Tracker to Ship Complete as well. Otherwise set to Partial Ship
try {
TheApplication().Utility.logStack("UpdatePTStatusOnShipment", this);
var boAction:BusObject;
var bcAction:BusComp;
var boOrder:BusObject;
var bcOrder:BusComp;
var partsRequestFound = false;
var partsTrackerFound = false;
var quoteNum = Inputs.GetProperty("QuoteNumber");
var orderId = Inputs.GetProperty("OrderId");
var shipCompleteFlag = Inputs.GetProperty("ShipComplete");
boOrder = TheApplication().GetBusObject("PDS Simplified Order");
bcOrder = boOrder.GetBusComp("PDS Simplified Order Entry - Orders");
TheApplication().Utility.logVars("Quote #/Order Id/Ship Complete",quoteNum+" / "+orderId+" / "+shipCompleteFlag);
//If the triggering order line is not ship complete then there is no need to query orders. If the triggering order line
//was set to ship complete, then since it is on a field trigger, the record is not committed so query for
//orders excluding the triggering one
if (shipCompleteFlag == "N") {
partsRequestFound = true;
} else {
with (bcOrder) {
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("CMI Ship Complete Flag", "N");
SetSearchSpec("Quote Number", quoteNum);
ExecuteQuery(ForwardOnly);
partsRequestFound = FirstRecord();
TheApplication().Utility.logVars("Open Parts Request found?", partsRequestFound);
}
}
boAction = TheApplication().GetBusObject("Action");
bcAction = boAction.GetBusComp("Action (Quote Order)");
with (bcAction) {
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker"));
SetSearchSpec("CMI Quote Number", quoteNum);
ExecuteQuery(ForwardOnly);
partsTrackerFound = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker found?", partsTrackerFound);
if (partsTrackerFound) {
var activityStatus = GetFieldValue("Status");
var statShipComplete = TheApplication().InvokeMethod("LookupValue","EVENT_STATUS","Ship Complete");
var statPartialShip = TheApplication().InvokeMethod("LookupValue","EVENT_STATUS","Partial Ship");
var statDone = TheApplication().InvokeMethod("LookupValue","EVENT_STATUS","Done");
TheApplication().Utility.logVars("Activity Id/Status", GetFieldValue("Id")+" / "+activityStatus);
if (partsRequestFound) {
if (activityStatus != statPartialShip) {
SetFieldValue("Status", statPartialShip);
WriteRecord();
}
} else {
if (activityStatus != statShipComplete && activityStatus != statDone) {
SetFieldValue("Status", statShipComplete);
WriteRecord();
}
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcOrder = null;
boOrder = null;
bcAction = null;
boAction = null;
TheApplication().Utility.logUnstack();
}
}

CMI Parts Tracker BS
UpdateLineShipComplete
function UpdateLineShipComplete(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("UpdateLineShipComplete", this);
var bcParent:BusComp = TheApplication().ActiveBusObject().GetBusComp(Inputs.GetProperty("ActiveParentBC"));
var boOrder:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var bcOrderItem:BusComp = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
//If a line is set to ship complete, query all lines for this order to see if there are any remaining open lines
//and if NOT, set the order to ship complete as well
if (bcParent != null && typeof(bcParent) != "undefined") {
var orderId = bcParent.GetFieldValue("Id");
var currentShipComplete = bcParent.GetFieldValue("CMI Ship Complete Flag");
TheApplication().Utility.logStep("Query for open lines for order "+orderId);
with (bcOrderItem) {
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Ship Complete Flag", "N");
SetSearchSpec("Order Header Id", orderId);
ExecuteQuery(ForwardOnly);
var found = FirstRecord();
}
TheApplication().Utility.logVars("Open Item found?", found);
if (found) {
if (currentShipComplete != "N") {
bcParent.SetFieldValue("CMI Ship Complete Flag", "N");
bcParent.WriteRecord();
}
} else {
if (currentShipComplete != "Y") {
bcParent.SetFieldValue("CMI Ship Complete Flag", "Y");
bcParent.WriteRecord();
}
}
}
} catch(e) {
TheApplication().Utility.logError(e);
} finally {
bcOrderItem = null;
boOrder = null;
bcParent = null;
TheApplication().Utility.logUnstack();
}
}

CMI Parts Tracker BS
SyncPartsTracker
function SyncPartsTracker(SRId,QuoteId) {
/*CMI DBU:JQ486:19/Nov/2010: The Below function is used to check the number of part line items present
in the accepted quote and identifying if the parts are serialized or non serialized. Based on
the serialize check, this will call the SerialNonSerialCheck function*/
/*Modified By KL968 for C & I 4457,Req# 271 on 09/15/2011 for allowing creation of Part Tracker Record with the Writ In Products*/
try {
TheApplication().Utility.logStack("SyncPartsTracker", this);
TheApplication().Utility.logVars("SR Id", SRId);
var bcQuoteItem:BusComp = boQuote.GetBusComp("Quote Item (Simple)");
var PrevProdCount = 1;
var writeIn = "Write-In Product";
//Search spec: All parts or Write Ins excluding Recon Clean and dirty lines
var strSearch = "([Product Type] = '"+TheApplication().InvokeMethod("LookupValue","PRODUCT_TYPE","Part")+"' OR [CMI Write In Identifier] = 'Yes') "+
"AND (([CMI Line Type]<>'"+ TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type") +
"' AND [CMI Line Type]<>'"+TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type")+"') OR [CMI Line Type] IS NULL)";
var sAllQty = 0;//update by jj954 for count used quantity
var found;
var sMainAssembFlg,Serialize, sReviseFlag;
var sProduct, sProductId, sWriteInIdentifier, sWriteInDesc, sEBSProd, sPrevProd;
var sQty, sQtyReq;
var sReturnQuantity = "";
sInvIdRet = bcQuote.GetFieldValue("CMI Default ServiceWIP Id");
with(bcQuoteItem) {
SetViewMode(AllView);
ActivateField("CMI Serialized Flag");
ActivateField("CMI Revise Flag");
ActivateField("CMI Quantity Requested");
ActivateField("CMI Write In Description");
ActivateField("CMI Write In Identifier");
ActivateField("CMI External Prod Id");
ActivateField("CMI Main Assembly Flag");
ActivateField("CMI Return");
ActivateField("Write-In Product");
ActivateField("Line Number");
ClearToQuery();
SetSearchExpr(strSearch);
SetSortSpec("Product Id(Ascending)");//Sort by product to group multiple lines with same product together
ExecuteQuery(ForwardBackward);//ku060: Needs to be Forwardbackward to eliminate duplicates caused by multiple product/orgs
found = FirstRecord();
TheApplication().Utility.logVars("First Quote Item Found?", found);
while(found) {
var QLIId = GetFieldValue("Id");
sProductId = GetFieldValue("Product Id");
sProduct = GetFieldValue("Product");
sQty = GetFieldValue("Quantity Requested");
sEBSProd = GetFieldValue("CMI External Prod Id");
//fetching the field to set it on Recon Product by JW919 on 11/08/2011
sReturn = GetFieldValue("CMI Return");
TheApplication().Utility.logStep("Line "+GetFieldValue("Line Number")+" ("+QLIId+") Part: "+sProduct+" ("+sProductId+") "+(sEBSProd != "" ? "External: " : "")+sEBSProd +" "+sReturn);
if(sReturn == TheApplication().InvokeMethod("LookupValue", "CMI_RETURN", "Core")) {
//call the function to fetch Dirty Core Quantity
sReturnQuantity = GetDirtyReturnQty(QuoteId, QLIId);
}
Serialize = GetFieldValue("CMI Serialized Flag");//Serialized Part or Non Serialized Part
sMainAssembFlg = GetFieldValue("CMI Main Assembly Flag");//CMI <Release# 1DBU>,C&I# 4657Enhancement# S138<Configuration>: <Getting Value of main Assembly Flag> By ko981 On 04/10/11
sQtyReq = GetFieldValue("CMI Quantity Requested");//update by jj954 for count used quantity
sReviseFlag = GetFieldValue("CMI Revise Flag");//update by jj954 for count used quantity
sWriteInDesc = GetFieldValue("CMI Write In Description");
sWriteInIdentifier = GetFieldValue("CMI Write In Identifier");
if(sPrevProd != sProduct || sPrevProd == null || sPrevProd == "") {
sPrevProd = sProduct;
sAllQty = 0;
sReturnQtyTotal = 0;
PrevProdCount = 1; //If product doesnt match, only 1 record should be created.
} else {
PrevProdCount = PrevProdCount + 1;
}
sAllQty = ToNumber(sAllQty) + ToNumber(sQty); //update by jj954 for count used quantity
sReturnQtyTotal = ToNumber(sReturnQtyTotal) + ToNumber(sReturnQuantity);
//Set to a value unique to each write in so multiple write in quote lines will
//will not be grouped into a single part tracker qty
if(sProduct == writeIn) {
sProduct = GetFieldValue("Write-In Product");
}
//CMI C&I# 4657 Enhancement# S138: below loop will check, if Main Assembly flag is true then that line item will skip in getting updated in Parts Tracker> By ko981 On 04/10/11
TheApplication().Utility.logVars("Main/Serialized (Running)", sMainAssembFlg+" / "+Serialize+" ("+PrevProdCount+")");
if(sMainAssembFlg != "Y") {
if(Serialize != "Y") {
//Create records in the part tracker for the nonserialized part
SerialNonSerialCheck(boPartTracker,sProductId,sProduct, sWriteInDesc, sWriteInIdentifier, sEBSProd, 1,sQty,Serialize,sQtyReq,sReviseFlag,sAllQty);
} else {
//Create records in the part tracker for the serialized part
SerialNonSerialCheck(boPartTracker,sProductId,sProduct, sWriteInDesc, sWriteInIdentifier, sEBSProd,PrevProdCount,sQty,Serialize);
}
}//end (if(sMainAssembFlg<>'Y'))
found = NextRecord();
}//End of while(quote item found)
}//End of with(bcQuoteItem)
} catch(e){
bcQuoteItem = null;
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
}//end of function

CMI Parts Tracker BS
UpdateOldRevisions
function UpdateOldRevisions(quoteNum)
{
try {
TheApplication().Utility.logStack("UpdateOldRevisions", this);
var boOldRevs = TheApplication().GetBusObject("CMI Quote");
var bcOldRevs = boOldRevs.GetBusComp("CMI Quote Simple");
var accepted = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Accepted");
var altQuoteSelected = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Alternative Quote Selected");
var cancelled = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Cancelled");
var found = false;
var quoteId, quoteStatus, activeFlag;
with (bcOldRevs) {
SetViewMode(AllView);
ActivateField("Quote Number");
ActivateField("Active");
ActivateField("Status");
ActivateField("Revision");
ClearToQuery();
SetSearchSpec("Quote Number",quoteNum);
ExecuteQuery(ForwardBackward);
var isRec = FirstRecord();
TheApplication().Utility.logVars("Quote ("+quoteNum+") found?", isRec);
while(isRec) {
quoteStatus = GetFieldValue("Status");
quoteId = GetFieldValue("Id");
activeFlag = GetFieldValue("Active");
TheApplication().Utility.logStep("Process Revision "+GetFieldValue("Revision")+" ("+quoteId+") - Status/Active: "+quoteStatus+" / "+activeFlag);
//Skip processing quotes that are read only already
if (quoteStatus != accepted && quoteStatus != cancelled && currentQuoteId != quoteId && activeFlag == "Y") {
//Update the Quote status to indicate a different quote has been accepted.
SetFieldValue("Status", altQuoteSelected);
SetFieldValue("Active", "N");
WriteRecord();
}
isRec = NextRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcOldRevs = null;
boOldRevs = null;
TheApplication().Utility.logUnstack();
}
}

CMI Parts Tracker BS
SerialNonSerialCheck
function SerialNonSerialCheck(oBO,sProductId,sProduct, sWriteInDesc, sWriteInIdentifier, sEBSProd,PrevProdCount,sQty,Serialize,sQtyReq,sReviseFlag,sAllQty)
/*CMI DBU:JQ486:19/Nov/2010: The Below function is used to create the part tracker records for serialized and non serailized
parts based on the quote line item records*/
{
try {
TheApplication().Utility.logStack("SerialNonSerialCheck", this);
var found;
var oBCPartTracker:BusComp = oBO.GetBusComp("CMI Activity Parts Movement");
var sPartCount;
var RemainRecords = 1;
var NeedNewRecord = false;
var bcProduct:BusComp;
var sQuanSum = 0; //added by jq487 for fixing def# 705
var updateStatus = false;
with(oBCPartTracker) {
InvokeMethod("SetAdminMode","TRUE");
ActivateField("Product Name");
ActivateField("Product Id");//JQ486-Activating field.
ActivateField("Used Quantity");
ActivateField("Serial Number");
ActivateField("CMI Quoted Quantity");
ActivateField("Trunk Invloc Id");
ActivateField("CMI Return Quantity");
ActivateField("CMI Return");
ActivateField("CMI EBS Product Id");
ClearToQuery();
SetSearchSpec("Product Id", sProductId);
if (sEBSProd!="") {
SetSearchSpec("CMI EBS Product Id", sEBSProd);
}
ExecuteQuery(ForwardOnly);//JQ486:Changed to ForwardOnly
found = FirstRecord();
TheApplication().Utility.logVars("Part Tracker Found?", found);
if(found == false) {
NeedNewRecord = true;
RemainRecords = PrevProdCount;
}
if(found) {
var sQuantUsed = GetFieldValue("Used Quantity");
var sSerialNum = GetFieldValue("Serial Number");
var sPrevReturnQty = GetFieldValue("CMI Return Quantity");
//If Count of QLI is More than the Count of Part Tracker.
TheApplication().Utility.logVars("Serialized", Serialize, 5);
if(Serialize == "Y") {
sPartCount = CountRecords();
TheApplication().Utility.logVars("Previous/Current Count", PrevProdCount+" / "+sPartCount);
if(PrevProdCount > sPartCount) {
//If Part(Quantity) Used is 0 in Part Tracker,then update below fields.
TheApplication().Utility.logVars("Used Quantity", sQuantUsed);
if(sQuantUsed == 0) {
SetFieldValue("Used Quantity",1);
SetFieldValue("CMI Quoted Quantity",1);
SetFieldValue("Trunk Invloc Id", sInvIdRet); //*CMI DBU:JQ486:13/April/2011: This Change is done for Performance Tuning
WriteRecord();
}
NeedNewRecord = true;
RemainRecords = PrevProdCount-sPartCount;
} else if (PrevProdCount < sPartCount) {
//If Count of QLI is less than the Count of Part Tracker,then update below fields.
if((sSerialNum == null || sSerialNum == "") && (sQuantUsed != 0)) {
SetFieldValue("Used Quantity",0);
SetFieldValue("CMI Quoted Quantity",0);
SetFieldValue("Trunk Invloc Id", sInvIdRet); //*CMI DBU:JQ486:13/April/2011: This Change is done for Performance Tuning
WriteRecord();
}
/*If Count of QLI is equal to the Count of Part Tracker and if part is NonSerialized
then update below fields.*/
} else if (PrevProdCount == sPartCount) {
NeedNewRecord = true;
}
} else {
TheApplication().Utility.logVars("Revised / Return", sReviseFlag+" / "+sReturn);
if(sReviseFlag == 'Y') {
TheApplication().Utility.logVars("Quantity/Requested", sQty+" / "+sQtyReq);
if(sQty != sQtyReq) {
sQuanSum = ToNumber(sAllQty);
SetFieldValue("Used Quantity",sQuanSum);
SetFieldValue("CMI Quoted Quantity",sQuanSum);
SetFieldValue("Trunk Invloc Id", sInvIdRet);
WriteRecord();
}
if(sReturn == TheApplication().InvokeMethod("LookupValue", "CMI_RETURN", "Core")) {
SetFieldValue("CMI Return", sReturn);
SetFieldValue("CMI Return Quantity", ToNumber(sReturnQtyTotal));
WriteRecord();
}
} else {
sQuanSum = ToNumber(sAllQty);
SetFieldValue("Used Quantity",sQuanSum);
SetFieldValue("CMI Quoted Quantity",sQuanSum);
SetFieldValue("Trunk Invloc Id", sInvIdRet);
if(sReturn == TheApplication().InvokeMethod("LookupValue", "CMI_RETURN", "Core")) {
SetFieldValue("CMI Return", sReturn);
SetFieldValue("CMI Return Quantity", ToNumber(sReturnQtyTotal));
}
WriteRecord();
}
}
}//end of while(sPCNextRecord)
//Creation of new part tracker records if no records are found.
TheApplication().Utility.logVars("Need New Record", NeedNewRecord);
if(NeedNewRecord) {
for(var k=1;k <= RemainRecords;k++) {
NewRecord(NewAfter);
TheApplication().Utility.logVars("Serialized", Serialize);
if(Serialize == "Y") {
bcProduct = oBCPartTracker.GetPicklistBusComp("Product Name");
with(bcProduct) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Product ID", sProductId);//Setting the product Id for performance tuning:JQ486:13/April/2011
ExecuteQuery(ForwardBackward);
if(FirstRecord()) {
Pick();
} else {
TheApplication().RaiseError("CMI Product Not Transactable", sProduct, "Current Position's");
}
}
SetFieldValue("Used Quantity",1);
SetFieldValue("CMI Quoted Quantity",1);
SetFieldValue("Trunk Invloc Id", sInvIdRet); //*CMI DBU:JQ486:13/April/2011: This Change is done for Performance Tuning
TheApplication().Utility.logVars("Write In / Return", sWriteInIdentifier+" / "+sReturn);
if(sWriteInIdentifier=="Yes") {
SetFieldValue("Comments",sWriteInDesc);
}
SetFieldValue("CMI EBS Product Id", sEBSProd);
if(sReturn == TheApplication().InvokeMethod("LookupValue", "CMI_RETURN", "Core")) {
SetFieldValue("CMI Return", sReturn);
SetFieldValue("CMI Return Quantity", 1);
}
WriteRecord();
} else {
bcProduct = oBCPartTracker.GetPicklistBusComp("Product Name");
with(bcProduct) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Product ID", sProductId);//Setting the product Id for performance tuning:JQ486:13/April/2011
ExecuteQuery(ForwardBackward);
if(FirstRecord()) {
Pick();
} else {
TheApplication().RaiseError("CMI Product Not Transactable", sProduct, "Current Position's");
}
}
SetFieldValue("Used Quantity",sQty);
SetFieldValue("CMI Quoted Quantity",sQty);
//CMI DBU Defect# 463, added the fields which need to be set for Recon Products by JW919 on 11/08/2011
TheApplication().Utility.logVars("Write In / Return", sWriteInIdentifier+" / "+sReturn);
if(sReturn == TheApplication().InvokeMethod("LookupValue", "CMI_RETURN", "Core")) {
SetFieldValue("CMI Return", sReturn);
SetFieldValue("CMI Return Quantity", ToNumber(sReturnQtyTotal));
}
SetFieldValue("Trunk Invloc Id", sInvIdRet); //*CMI DBU:JQ486:13/April/2011: This Change is done for Performance Tuning
if(sWriteInIdentifier=="Yes") {
SetFieldValue("Comments",sWriteInDesc);
}
SetFieldValue("CMI EBS Product Id", sEBSProd);
}
WriteRecord();
}
}// End of if(NeedNewRecord)
}//End of if(oBCPartTracker)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcProduct = null;
oBCPartTracker = null;
TheApplication().Utility.logUnstack();
}
}//End of function

CMI Parts Tracker BS
ProcessPartsRequest
function ProcessPartsRequest(QuoteId)
{
/*********************************************************
AUTHOR: JQ487,CMI DBU, Build Quote Repair Functionality(Part Request Section)
DESCRIPTION: This Script will be triggered for creation of Parts Request Order
based on the number of Part/Product Line Items available on the Quote Line
Item for an Accepted Quote.
DATE CREATED: 19 Nov 2010
UPDATES: 29 March 2011 - JQ487, Added additional condition for one off.
*********************************************************/
try {
TheApplication().Utility.logStack("ProcessPartsRequest", this);
var statusAccepted = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Accepted");
var displayMessage = "";
with (bcQuote) {
var sStatus = GetFieldValue("Status");
var quoteNum = GetFieldValue("Quote Number");
var sRev = GetFieldValue("Revision");
var accountId = GetFieldValue("Account Id")
//If all quote lines are explicitly excluded by rule, then set a flag to prevent the
//creation of the Parts Request
var createPartsRequest = CheckPartRequestRequired(QuoteId);
if(createPartsRequest) {
//If a revision, potentially update the parts tracker
TheApplication().Utility.logVars("Revision / Part Tracker Status", sRev+" / "+currentPTStatus);
if (sRev > 1 && currentPTStatus == TheApplication().InvokeMethod("LookupValue","EVENT_STATUS","Ship Complete")) {
UpdatePartTracker(quoteNum);
}
//Execute the OM Signal on the active object, Quote
TheApplication().ActiveBusObject().GetBusComp("Quote").InvokeMethod("AutoOrderPartsRequestQuote");
displayMessage = "Parts Request created. Review & submit.";
}
SetFieldValue("Status", statusAccepted);
WriteRecord();
//Post processing steps
MoveActivitiesToAcceptedQuote(quoteNum, accountId);
UpdateOldRevisions(quoteNum);
UpdatePaymentLines(QuoteId);
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(displayMessage);
}
return (displayMessage);
}

CMI Parts Tracker BS
PartsTracking
function PartsTracking(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("PartsTracking", this);
var txnSvc = TheApplication().GetService("EAI Transaction Service");
var ins = TheApplication().NewPropertySet();
var outs = TheApplication().NewPropertySet();
var displayMessage = "";
//Create a commit point before any record updates are made to the quote or order
txnSvc.InvokeMethod("BeginTransaction", ins, outs);
var SRId = TheApplication().GetProfileAttr("PartSRId");
TheApplication().Utility.logId("Service Request", SRId);
currentQuoteId = TheApplication().GetProfileAttr("PartQuoteId");
with(bcQuote) {
ActivateField("Status");
ActivateField("Quote Number");
ActivateField("Source Inventory Location");
ActivateField("CMI Default ServiceWIP Id");
ActivateField("CMI Primary Division Id");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",currentQuoteId);
ExecuteQuery(ForwardOnly);//JQ486:Changed to ForwardOnly
var found = FirstRecord();
TheApplication().Utility.logVars("Quote for SR ("+currentQuoteId+" for "+SRId+") Found?", found);
if(found) {
var sQuoteNum = GetFieldValue("Quote Number");
//Populate an array to get quoted/picked quantities of each product from the Parts Tracker activity
found = GetPartTrackerLines(SRId, sQuoteNum);
if(found) {
//Update the insure all part tracker lines exist with correct quantity to match quote lines
SyncPartsTracker(SRId,currentQuoteId);
//Create the Parts Request and update the Quote Status. If parts request is created, notify user via popup
//because popup will cancel subsequent operations, execute all processes before the popup is displayed
displayMessage = ProcessPartsRequest(currentQuoteId);
}
} else throw("Quote Context cannot be found");
}
ins.SetProperty("Is Abort", "False");
txnSvc.InvokeMethod("EndTransaction", ins, outs);
// TheApplication().ActiveBusObject().GetBusComp("Quote").InvokeMethod("RefreshBusComp");
TheApplication().ActiveBusObject().GetBusComp("Quote").ClearToQuery();
TheApplication().ActiveBusObject().GetBusComp("Quote").ExecuteQuery(ForwardBackward);
if (displayMessage != "") throw(displayMessage);
} catch(e){
if (displayMessage == "" ) {
ins.SetProperty("Is Abort", "True");
txnSvc.InvokeMethod("EndTransaction", ins, outs);
with (TheApplication().ActiveBusObject().GetBusComp("Quote")) {
InvokeMethod("RefreshRecord");
SetFieldValue("CMI Status", TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Quote Ready"));
WriteRecord();
InvokeMethod("RefreshBusComp");
}
}
TheApplication().Utility.RaiseError(e);
} finally {
outs = null;
ins = null;
txnSvc = null;
TheApplication().Utility.logUnstack();
}
}

CMI Parts Tracker BS
MoveActivitiesToAcceptedQuote
function MoveActivitiesToAcceptedQuote(quoteNum, accountId)
{
//Reassociate all non cancelled activities for this quote (identified by having same Quote #) under this SR to the Accepted Quote
try
{
TheApplication().Utility.logStack("MoveActivitiesToAcceptedQuote", this);
var boAction : BusObject = TheApplication().GetBusObject("Action");
var bcAction : BusComp = boAction.GetBusComp("Action (Quote Order)");
var lost : String = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Lost");
var accepted : String = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Accepted");
var cancelled : String = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Cancelled");
var altQuoteAccepted : String = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Alternative Quote Selected");
var quoteId : String = "";
var quoteStatus : String = "";
var quoteActive : String = "";
var activityStatus : String = "";
var activityId : String = "";
var activityType : String = "";
//Find all tied to other revisions of the same Quote number. Process exclusions in the loop rather than the SQL to leverage indexes
with (bcAction)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Quote Status");
ActivateField("Status");
ActivateField("CMI Quote Active");
ActivateField("Quote Id");
ActivateField("Type");
SetSearchSpec("CMI Quote Number", quoteNum);
ExecuteQuery(ForwardBackward);
var activityFound = FirstRecord();
while (activityFound)
{
quoteId = GetFieldValue("Quote Id");
quoteStatus = GetFieldValue("CMI Quote Status");
quoteActive = GetFieldValue("CMI Quote Active");
activityStatus = GetFieldValue("Status");
activityId = GetFieldValue("Id");
activityType = GetFieldValue("Type");
TheApplication().Utility.logStep("Process " + activityStatus + " " + activityType + " (" + activityId + ") for Quote (" + quoteId + ")");
//Skip activities already linked to the Accepted quote and those that are cancelled
if (quoteId != currentQuoteId && activityStatus != TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Cancelled"))
{
//MJB 11/5/12 INC000003627919 Cancel all activities tied to the Alternative Quote before updating quote status
TheApplication().Utility.logVars("Quote Status / Active ", quoteStatus + " / " + quoteActive);
/*if (quoteStatus != accepted && quoteStatus != lost && quoteStatus != cancelled && quoteStatus != altQuoteAccepted && quoteActive == "Y")*/
/*CRQ000000112029 03MAR14 HF lq447- above line replaced by new condition below*/
if (quoteStatus !== accepted && quoteStatus !== lost && quoteStatus !== cancelled && quoteStatus !== altQuoteAccepted && quoteActive === "Y")
{
TheApplication().Utility.logVars("Cancel Activity", GetFieldValue("Id"));
SetFieldValue("Status", "Cancelled");
WriteRecord();
//Quotes in Lost, Alternative Quote Accepted or Cancelled status will be read only. Update all other activities to point to accepted quote
}
else
{
SetFieldValue("Quote Id", currentQuoteId);
//If the Account on the new revision has changed since the previous revision, the account on the service activities
//should be updated as well
if (accountId != GetFieldValue("Account Id"))
{
TheApplication().Utility.logVars("Old / New Account Id", accountId + " / " + GetFieldValue("Account Id"));
SetFieldValue("Account Id", accountId);
}
WriteRecord();
}
}
activityFound = NextRecord();
}
}
}
catch (e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
bcAction = null;
boAction = null;
TheApplication().Utility.logUnstack();
}
}

CMI Parts Tracker BS
GetTotalPickedQty
function GetTotalPickedQty(bcOrderLine, productId, quoteNum)
{
try {
TheApplication().Utility.logStack("GetTotalPickedQty", this);
var sumPicked:Number = 0;
var partsFound = false;
var typePartReq = TheApplication().InvokeMethod("LookupValue", "FS_ORDER_TYPE", "Parts Request");
var typeIntRet = TheApplication().InvokeMethod("LookupValue", "FS_ORDER_TYPE", "Internal Parts Return");
var statPending = TheApplication().InvokeMethod("LookupValue", "FS_ORDER_STATUS", "Pending");
var statCancelled = TheApplication().InvokeMethod("LookupValue", "FS_ORDER_STATUS", "Cancelled");
//Find all fulfilled line items for Part Request orders related to the Part Tracker's Quote #
with(bcOrderLine) {
ActivateField("CMI Qty Consumed");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Product Id", productId);
SetSearchSpec("CMI Quote Number",quoteNum);
SetSearchSpec("CMI Parent Order Type", typePartReq);
SetSearchSpec("CMI Qty Consumed", "IS NOT NULL");
ExecuteQuery(ForwardBackward);
partsFound = FirstRecord();
while(partsFound) {
sumPicked += ToNumber(GetFieldValue("CMI Qty Consumed"));
partsFound = NextRecord();
}//End of while(partsFound)
}//End of with(bcOrderLine)
//Find all fulfilled line items for Internal Parts Return orders related to the Part Tracker's Quote #
with(bcOrderLine) {
ActivateField("Quantity Requested");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Product Id", productId);
SetSearchSpec("CMI Quote Number",quoteNum);
SetSearchSpec("CMI Parent Order Type", typeIntRet);
SetSearchSpec("CMI Order Status", "<> '"+statPending+"' AND <> '"+statCancelled+"'");
ExecuteQuery(ForwardBackward);
partsFound = FirstRecord();
while(partsFound) {
sumPicked -= ToNumber(GetFieldValue("Quantity Requested"));
partsFound = NextRecord();
}//End of while(partsFound)
}//End of with(bcOrderLine)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(sumPicked);
}
return(sumPicked);
}

CMI Parts Tracker BS
GetPartTrackerLines
function GetPartTrackerLines(SRId, sQuoteNum)
{
/*CMI DBU:JQ487:15/Apr/2011: The Below function is used to Query on Part Tracker BC to valdate that Picked Qty on
Part Tracker Record is Less than sum of Quoted Qty and Qty request on current revision. */
try {
TheApplication().Utility.logStack("GetPartTrackerLines", this);
var iCount = 0;
var IsActivityRec;
var IsPartTrackRec;
with(bcPartTracker) {
ActivateField("CMI Quote Number");
ActivateField("Type");
ActivateField("CMI Status");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Activity SR Id", SRId);
SetSearchSpec("CMI Quote Number",sQuoteNum);
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker"));
ExecuteQuery(ForwardOnly);
IsActivityRec = FirstRecord();
if(IsActivityRec) {
currentPTStatus = GetFieldValue("CMI Status");
TheApplication().Utility.logVars("Part Tracker ("+GetFieldValue("Id")+") Status", currentPTStatus);
with(bcPTLines) {
SetViewMode(AllView);
ActivateField("Product Name");
ActivateField("Product Id");
ActivateField("CMI Parts Allocated");
ActivateField("CMI Quoted Quantity");
ActivateField("CMI EBS Product Id");
ClearToQuery();
ExecuteQuery(ForwardOnly);
var sPCNextRecord = FirstRecord();
while(sPCNextRecord) {
//Implementing the array logic for performance tuning.By jq486.
//Since all write in products have the same siebel product row id, we indicate uniqueness by specifying the EBS Id
aProdArr[iCount] = (GetFieldValue("CMI EBS Product Id") != "" ? GetFieldValue("CMI EBS Product Id") : GetFieldValue("Product Id"));
aQuotedQtyArr[iCount] = GetFieldValue("CMI Quoted Quantity");
aAllocQtyArr[iCount] = GetFieldValue("CMI Parts Allocated");
TheApplication().Utility.logStep("Process "+iCount+" - "+GetFieldValue("Product Name")+" ("+aProdArr[iCount]+") - Quoted/Picked: "+ aQuotedQtyArr[iCount]+" / "+aAllocQtyArr[iCount]);
iCount++;
sPCNextRecord = NextRecord();
}
}
}//End of while(IsActivityRec)
}//End of with(oBCAction)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(IsActivityRec);
}
return(IsActivityRec);
}

CMI Parts Tracker BS
GetItemQty
function GetItemQty(sProdId)
{
/*CMI DBU:JQ486:18/Apr/2011: The Below function is used to traverse through each non serialized product LI. */
try {
TheApplication().Utility.logStack("GetItemQty", this);
var i = 0;
if(sProdId != null || sProdId != "") {
for(i = 0; i < aProdArr.length; i++) {
if(aProdArr[i] == sProdId) {
break;
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(i);
}
return i;
}

CMI Parts Tracker BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: JQ486,CMI DBU, Build Quote Repair Functionality(Part Tracker Section)
DESCRIPTION: This Script will be triggered for creation of records in the
part tracker BC based on the number of Part Line Items available on the Quote Line
Item for an Accepted Quote.
DATE CREATED: 19 Nov 2010
UPDATES:
*********************************************************/
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
switch(MethodName) {
case "PartsTracking":
PartsTracking(Inputs, Outputs);
break;
//triggered by updates to picked qty on order line items via RT Event
case "UpdatePickedQty":
UpdatePickedQty();
break;
case "UpdatePTStatusOnShipment":
UpdatePTStatusOnShipment(Inputs, Outputs);
break;
case "UpdateLineShipComplete":
UpdateLineShipComplete(Inputs, Outputs);
break;
case "CallIPRUpdate":
CallIPRUpdate(Inputs, Outputs);
break;
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcQuote = null;
boQuote = null;
bcPTLines = null;
bcPartTracker = null;
boPartTracker = null;
//TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Parts Tracker BS
GetDirtyReturnQty
////Added by KM326 for 4455 on 18/11/2011
//This funcntion will return the Quantity on the Dirty Core
function GetDirtyReturnQty(sQuoteId, sQuoteItemId) {
try {
TheApplication().Utility.logStack("GetDirtyReturnQty", this);
var oBOQuoteDirty:BusObject = TheApplication().GetBusObject("Quote");
var OBCQuoteItemDirty:BusComp = oBOQuoteDirty.GetBusComp("Quote Item (Simple)");
var sDirtyReturnQty = "";
with(OBCQuoteItemDirty) {
ActivateField("Quantity Requested");
ClearToQuery();
SetSearchSpec("Quote Id",sQuoteId);
SetSearchSpec("Covered Quote Item Id",sQuoteItemId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
sDirtyReturnQty = GetFieldValue("Quantity Requested");
sDirtyReturnQty = ToNumber(sDirtyReturnQty) * (-1);
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
OBCQuoteItemDirty = null;
oBOQuoteDirty = null;
TheApplication().Utility.logUnstack(sDirtyReturnQty);
}
return (sDirtyReturnQty);
}

CMI Parts Tracker Validation
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: Shyamal Nath
DESCRIPTION:
INPUTS:
OUTPUTS:
DATE CREATED:
UPDATES:
*********************************************************/
try
{
if (MethodName == "CMIMessage")
{
var boAction = TheApplication().ActiveBusObject();
var bcAction = boAction.GetBusComp("Action");
var bcFSActPartsMvt = boAction.GetBusComp("CMI FS Activity Parts Movement");
var sActvtyId = bcAction.GetFieldValue ("Id");
//var sStatus = bcAction.GetFieldValue ("Status");
//if (sStatus == 'Work Complete')
//{
with (bcFSActPartsMvt) //Parts Tracker
{
ActivateField("Activity Id");
ActivateField("Charged Flag");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec ("Activity Id", sActvtyId);
SetSearchSpec ("Charged Flag", 'Y');
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
TheApplication().RaiseErrorText("A part has been identified as MUST RETURN. Please check your parts list and handle accordingly." );
}
}
//}
return (CancelOperation);
}
else
return (ContinueOperation);
}//try
catch(e)
{
throw(e);
}
finally
{
bcFSActPartsMvt = null;
bcAction = null;
boAction = null;
}
}

CMI Pricing Dirty Core BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
// Added/Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
switch(MethodName)
{
case "CMIPriceAll":
CMIPriceAll(Inputs, Outputs);
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
}
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
/*
//Commented the finally block as no variable is nullified ,by jw920 20/8/11
<Code clean up>
finally
{
}*/
//<End>
return (ContinueOperation);
}

CMI Pricing Dirty Core BS
CMIPriceAll
function CMIPriceAll(Inputs, Outputs)
{
/***********************************************************************************
Created by IY794 - Praveen for Dirty Core Pricing.
************************************************************************************/
try
{
var aHeaderId = Inputs.GetProperty("HeaderId");
var aObject = Inputs.GetProperty("Object");
var aItemId = Inputs.GetProperty("ItemId");
var aBO;
var aBC;
var aHeaderName;
var aNetPrice;
var aEBSNetPrice;
if (aHeaderId)
{
switch (aObject)
{
case "Order":
aBO = TheApplication().GetBusObject("Order Entry (Sales)");
aBC = aBO.GetBusComp("Order Entry - Line Items (Simple)");
aHeaderName = "Order Header Id";
break;
case "Quote":
aBO = TheApplication().GetBusObject("Quote");
aBC = aBO.GetBusComp("Quote Item (Simple)");
aHeaderName = "Quote Id";
break;
}
with (aBC)
{
ActivateField("CMI Dirty Core Flag");
ActivateField("Net Price");
ActivateField("CMI EBS Net Price");
ClearToQuery();
SetViewMode(AllView);
if (aItemId)
SetSearchExpr("[CMI Dirty Core Flag] = 'Y' AND [Id] = '" + aItemId + "' AND [" + aHeaderName + "] = '" + aHeaderId + "'");
else
SetSearchExpr("[CMI Dirty Core Flag] = 'Y' AND [" + aHeaderName + "] = '" + aHeaderId + "'");
ExecuteQuery(ForwardOnly);
var aHasRec = FirstRecord();
while (aHasRec)
{
aNetPrice = GetFieldValue("Net Price");
aEBSNetPrice = GetFieldValue("CMI EBS Net Price");
if (aNetPrice >= 0)
{
aNetPrice = ToNumber(aNetPrice) * -1;
aEBSNetPrice = ToNumber(aEBSNetPrice) * -1;
SetFieldValue("Net Price",aNetPrice);
SetFieldValue("CMI EBS Net Price",aEBSNetPrice);
WriteRecord();
}
aHasRec = NextRecord();
}
}
}
}
catch (e)
{
throw(e);
}
finally
{
aBC = null;
aBO = null;
}
}

CMI Product Check
(declarations)
var oBO;
var oBCQuote;
var sId;
var oBCQuoteItem;
var sProductId;
var sProdType;

CMI Product Check
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: JQ487,CMI DBU, Defect 353
DESCRIPTION: This Script will be triggered for creation of new Records on
the Quote Line and will check that if a product is already existing and is
non serialized, then an error message will be displayed telling user to
increase the quantity as product is already in line item and is non serialized.
DATE CREATED: 25 Apr 2011
*********************************************************/
try
{
if (MethodName == "ProductCheck")
{
oBO = TheApplication().ActiveBusObject();
oBCQuote = oBO.GetBusComp("Quote");
sId = oBCQuote.GetFieldValue("Id");
oBCQuoteItem = oBO.GetBusComp("Quote Item (Simple)");
sProductId = TheApplication().GetProfileAttr("ProdId");
sProdType = TheApplication().GetProfileAttr("ProdType");
var sProdVal1 = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Product");
var sProdVal2 = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Part");
var sProdVal3 = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
var sProdVal4 = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Misc");
var sFlag;
with (oBCQuoteItem)
{
SetViewMode(AllView);
ActivateField("CMI Serialized Flag");
ActivateField("Product Id");
ActivateField("CMI SRT Id");
ActivateField("Product Type");
ClearToQuery();
SetSearchSpec("Quote Id",sId);
ExecuteQuery(ForwardBackward);
var isRec = FirstRecord();
while(isRec)
{
var sProd = GetFieldValue("Product Id");
var sFlg = GetFieldValue("CMI Serialized Flag");
if((sProdType == sProdVal1) || (sProdType == sProdVal2) || (sProdType == sProdVal4))
{
if ((sProd == sProductId) && (sFlg != "Y"))
{
sFlag = "Y";
}//end if
}
/*else
{
if(sProdType == sProdVal3)
{
//var sSRT = GetFieldValue("CMI SRT Id");
if (((sProd == sProductId) && (sFlg != "Y")) && (sSRT != null))
{
sFlag = "Y";
}//end if
}
}*/
isRec = NextRecord();
}//end While
if(sFlag == "Y")
{
TheApplication().RaiseErrorText("Product already exist, Please either increase Quantity or choose another Product.");
}//end if
}//end with
return(CancelOperation);
}//end if
if (MethodName == "LaborCheck")
{
oBO = TheApplication().ActiveBusObject();
oBCQuote = oBO.GetBusComp("Quote");
sId = oBCQuote.GetFieldValue("Id");
oBCQuoteItem = oBO.GetBusComp("Quote Item (Simple)");
sProductId = TheApplication().GetProfileAttr("ProdId");
sProdType = TheApplication().GetProfileAttr("ProdType");
var sSRTId = TheApplication().GetProfileAttr("SRTId");
var sFlag1;
with (oBCQuoteItem)
{
SetViewMode(AllView);
ActivateField("Product Id");
ActivateField("CMI SRT Id");
ActivateField("Product Type");
ClearToQuery();
SetSearchSpec("Quote Id",sId);
ExecuteQuery(ForwardBackward);
var isRec1 = FirstRecord();
while(isRec1)
{
var sProdId = GetFieldValue("Product Id");
if(sProdType == sProdVal3)
{
var sSRT = GetFieldValue("CMI SRT Id");
if ((sProdId == sProductId) && (sSRT == sSRTId))
{
sFlag1 = "Y";
}//end if
}
isRec1 = NextRecord();
}//end While
if(sFlag1 == "Y")
{
TheApplication().RaiseErrorText("The selected combination of SRT and Labor already exist, please select another record or undo the record and increase the SRT Quantity of the existing record");
}//end if
}//end with
return(CancelOperation);
}//end if
}//end try
catch(e)
{
throw(e);
}
finally
{
sProdVal1 = null;
sProdVal2 = null;
sProdVal3 = null;
sProdVal4 = null;
oBCQuoteItem = null;
sId = null;
oBCQuote = null;
oBO = null;
}
}

CMI Product Inventory Check BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : Pankaj Sinha
Created On : 14th January 2010
Method Name: function BusComp_PreInvokeMethod (MethodName) == "Query"
Functionality: This method will be triggered when the user clicks the "Check Availability" Button from Order Line Item,
Service Request and Product. This BS is invoked from VBC.
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try{
switch (MethodName)
{
case "Init" :
Outputs.SetProperty ("CMI Available Quantity", "");
Outputs.SetProperty ("CMI Primary Stocking Indicator", "");
Outputs.SetProperty ("CMI Quantity Reserved", "");
Outputs.SetProperty ("CMI Short Quantity", "");
Outputs.SetProperty ("CMI Special Care/Emergency Down Quantity","");
Outputs.SetProperty ("CMI Warehouse","");
Outputs.SetProperty ("CMI Product Id","");
Outputs.SetProperty ("CMI On Order Quantity","");
// Added For Care
Outputs.SetProperty ("CMI Picked Quantity","");
// Care End
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
case "Query" :
var val=TheApplication().GetProfileAttr("Flag");
if (val=="Y"){
var sId = TheApplication().GetProfileAttr("RowId");
var sPBU = TheApplication().GetProfileAttr("BU");
var oBS;
var inpPS;
var outPS;
var tempOutPS;
var sSRFlag;
var oCacheBS;
TheApplication().SetProfileAttr("InterfaceErrMsg","");
inpPS = TheApplication().NewPropertySet();
outPS = TheApplication().NewPropertySet();
tempOutPS = TheApplication().NewPropertySet();
sSRFlag = TheApplication().GetProfileAttr("SRFlag");
// commented per Ticket#INC000000975863 if (sSRFlag == "N")
{
oBS = TheApplication().GetService("Workflow Process Manager");
inpPS.SetProperty("CumminsPart#", sId);
inpPS.SetProperty("BusinessUnit", sPBU);
inpPS.SetProperty("ProcessName", "CMI Inventory Check Integration Workflow");
oBS.InvokeMethod("RunProcess", inpPS, outPS);
// commented per Ticket#INC000000975863 oCacheBS = TheApplication().GetService("CMI Cache PropertySet Integration");
// commented per Ticket#INC000000975863 oCacheBS.InvokeMethod("StorePS", outPS, tempOutPS);
}
/* commented per Ticket#INC000000975863 else
{
oCacheBS = TheApplication().GetService("CMI Cache PropertySet Integration");
oCacheBS.InvokeMethod("RecallPS", inpPS, tempOutPS);
outPS = tempOutPS.GetChild(0).Copy();
oCacheBS.InvokeMethod("ClearPS", inpPS, tempOutPS);
} */
var strErrCode = outPS.GetProperty("Error Code");
var strErrMsg = outPS.GetProperty("Error Message");
var strAIAErrCode = outPS.GetProperty("AIAErrorCode");
var strAIAErrMsg = outPS.GetProperty("AIAErrorMessage");
if ((strErrMsg == "")&&(strAIAErrMsg == ""))
{
if (outPS.GetChild(0).GetChild(0).GetChild(0).GetChildCount() > 1) //Checks the presence of ListOfbody
{
if (outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChildCount() > 0) //Checks the presence of body
{
if(outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChildCount() > 0) //Checks the presence of ListOfInventory
{
if(outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChildCount() > 0) //Checks the presence of Inventory
{
if (outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChildCount() > 0) //Checks the presence of ListOfProductInventory
{
var InvChildCount = outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChildCount();
if( InvChildCount > 0)
{
var sListOfProdInventory = TheApplication().NewPropertySet();
sListOfProdInventory = outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0);
var sWarehouse = new Array;
var sAvailableQty = new Array;
var sPSIndicator = new Array;
var sSpecialCareQty = new Array;
var sReservedQty = new Array;
var sShortQty = new Array;
var sOnOrderQty = new Array;
// Added For Care
var sPickedQty = new Array;
// Care End
for (var i=0;i<InvChildCount;i++)
{
sWarehouse[i] = sListOfProdInventory.GetChild(i).GetProperty("Warehouse");
sAvailableQty[i] = sListOfProdInventory.GetChild(i).GetProperty("AvailableQuantity");
sPSIndicator[i] = sListOfProdInventory.GetChild(i).GetProperty("PrimaryStockingIndicator");
sSpecialCareQty[i] = sListOfProdInventory.GetChild(i).GetProperty("SpecialCareQuantity");
sReservedQty[i] = sListOfProdInventory.GetChild(i).GetProperty("QuantityReserved");
sShortQty[i] = sListOfProdInventory.GetChild(i).GetProperty("ShortQuantity");
sOnOrderQty[i] = sListOfProdInventory.GetChild(i).GetProperty("OnOrderQuantity");
// Added For Care
sPickedQty[i] = sListOfProdInventory.GetChild(i).GetProperty("PickedQuantity");
// Care End
var InventoryItem = TheApplication().NewPropertySet();
InventoryItem.SetProperty ("CMI Warehouse",sWarehouse[i]);
InventoryItem.SetProperty ("CMI Available Quantity",sAvailableQty[i]);
InventoryItem.SetProperty ("CMI Special Care/Emergency Down Quantity",sSpecialCareQty[i]);
InventoryItem.SetProperty ("CMI Primary Stocking Indicator",sPSIndicator[i]);
InventoryItem.SetProperty ("CMI Quantity Reserved", sReservedQty[i]);
InventoryItem.SetProperty ("CMI Short Quantity", sShortQty[i]);
InventoryItem.SetProperty ("CMI On Order Quantity", sOnOrderQty[i]);
// Added For Care
InventoryItem.SetProperty ("CMI Picked Quantity", sPickedQty[i]);
// Care End
Outputs.AddChild(InventoryItem);
}
}
}
}
}
}
}
}
else
{
TheApplication().SetProfileAttr("InterfaceErrMsg",strErrMsg);
TheApplication().SetProfileAttr("AIAInterfaceErrMsg",strAIAErrMsg);
}
if(TheApplication().GetProfileAttr("SRFlag")=="Y")
{
TheApplication().SetProfileAttr("Flag", "N");
TheApplication().SetProfileAttr("SRFlag", "N");
}
return (CancelOperation);
}
else
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
}
}// end of try
catch(e)
{
/*if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " +"ERROR: " + e.errText +"STACK: " + e.toString());
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "ERROR: " + e.errText +"STACK: " + e.toString());
}*/
TheApplication().SetProfileAttr("InterfaceErrMsg",e.toString());
}// end of catch
finally
{
tempOutPS = null;
outPS = null;
inpPS = null;
oBS = null;
sPBU = null;
sId = null;
val = null;
sOnOrderQty = null;
sShortQty = null;
sReservedQty = null;
sSpecialCareQty = null;
sPSIndicator = null;
sAvailableQty = null;
sWarehouse = null;
sListOfProdInventory = null; // nullify the objects by jw920 on 22/08/11<Code Clean Up>
//oCacheBS = null;
//added by shanmukh for code clean up 08/27/2011
InventoryItem = null;
sPickedQty = null;
}
return (ContinueOperation);
}

CMI Product Supersession Toolkit Service
ShowRecommendations
function ShowRecommendations(Inputs, Outputs) {
try{
TheApplication().Utility.logStack("ShowRecommendations", this);
//Active BC
var boActive:BusObject = TheApplication().ActiveBusObject();
var bcQuote:BusComp = boActive.GetBusComp("Quote");
var bcQuoteItem:BusComp = boActive.GetBusComp("Quote Item");
var quoteItemFound = false;
var superStatusPending = TheApplication().InvokeMethod("LookupValue", "CMI_QUOTE_SUPER_STAT_CD", "Pending");
if (bcQuote.GetFieldValue("CMI Supersession Status") == superStatusPending) {
//Query for those items requiring attention for Supersession an prompt the user with a message
with (bcQuoteItem) {
ClearToQuery();
SetSearchSpec("CMI Supersession Product Id", "IS NOT NULL");
SetSearchSpec("CMI Supersession Flag", "N");
SetSortSpec("CMI Supersession Item Id , CMI Supersession Sequence");
ExecuteQuery(ForwardBackward);
quoteItemFound = FirstRecord();
TheApplication().Utility.logVars("Recommendation Item found?", quoteItemFound);
if (quoteItemFound) {
TheApplication().RaiseError("CMI Process Supersession Prompt");
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcQuoteItem = null;
bcQuote = null;
boActive = null;
TheApplication().Utility.logUnstack();
}
}

CMI Product Supersession Toolkit Service
(declarations)
var boQuoteUpd:BusObject;
var bcQuoteUpd:BusComp;
var bcQuoteItemUpd:BusComp;
var serviceQuote = TheApplication().InvokeMethod("LookupValue", "QUOTE_TYPE", "Service Quote");

CMI Product Supersession Toolkit Service
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
switch(MethodName) {
case "AddHierarchichalRec":
AddHierarchichalRec(Inputs, Outputs);
break;
//LC657 CQ#12198
case "AddHierarchichalRecInterface":
AddHierarchichalRecInterface(Inputs, Outputs);
break;
case "CMIAddLines":
AddLines(Inputs, Outputs);
break;
case "CMIMakeRecommendations":
MakeRecommendations(Inputs, Outputs);
break;
case "CMIShowRecommendations":
ShowRecommendations(Inputs, Outputs);
break;
case "CMIApplyRecommendations":
ApplyRecommendations(Inputs, Outputs);
break;
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Product Supersession Toolkit Service
MakeRecommendations
function MakeRecommendations(Inputs, Outputs) {
try{
TheApplication().Utility.logStack("MakeRecommendations", this);
//Active BC
var bcActive:BusComp = TheApplication().ActiveBusObject().GetBusComp("Quote");
//Objects to cycle through quote and update records. Instantiate active Quote to get SS Status and update it
//and quote item simple to improve performace since no RT events should be triggered at this step
var boQuote:BusObject = TheApplication().GetBusObject("CMI Quote");
var bcQuoteItem:BusComp = boQuote.GetBusComp("Quote Item (Simple)");
var quoteId = bcActive.GetFieldValue("Id")
var quoteItemFound = false;
var quoteFound = false;
var currentProduct = "";
var currentSuperProduct = "";
var currentSuperItemId = "";
var lastSuperItemId = "^";
var neededQuantity:Number = 0;
var recmndQuantity:Number = 0;
var availableQuantity:Number = 0;
var updateQuantity:Number = 0;
var splitQuantity:Number = 0;
var supersessions = false;
var superStatusFound = TheApplication().InvokeMethod("LookupValue", "CMI_QUOTE_SUPER_STAT_CD", "Found");
var superStatusPending = TheApplication().InvokeMethod("LookupValue", "CMI_QUOTE_SUPER_STAT_CD", "Pending");
var superStatusNA = TheApplication().InvokeMethod("LookupValue", "CMI_QUOTE_SUPER_STAT_CD", "N/A");
var recType = "";
var split = false;
//Instantiate the Quote to evaluate SS Status and update when done
with (bcActive) {
//quoteFound = FirstRecord();
//TheApplication().Utility.logVars("Quote found?", quoteFound);
if (GetFieldValue("CMI Supersession Status") == superStatusFound) {
//Query and loop through same items available in List for ATP
with (bcQuoteItem) {
ClearToQuery();
ActivateField("CMI Recommended Quantity");
ActivateField("Quantity Requested");
ActivateField("CMI Supersession Original Quantity");
ActivateField("CMI Supersession Product Id");
ActivateField("Available Quantity");
ActivateField("Product");
ActivateField("CMI Supersessied Product Name");
ActivateField("CMI Supersession Recommendation Type");
ActivateField("CMI Supersession Item Id");
SetViewMode(AllView);
SetSearchSpec("Quote Id", quoteId);
SetSearchSpec("CMI Supersession Product Id", "IS NOT NULL");
SetSearchSpec("CMI Supersession Flag", "N");
SetSortSpec("CMI Supersession Item Id, CMI Supersession Sequence");
ExecuteQuery(ForwardBackward);
quoteItemFound = FirstRecord();
TheApplication().Utility.logVars("Recommendation Item found?", quoteItemFound);
while (quoteItemFound) {
currentProduct = GetFieldValue("Product");
currentSuperProduct = GetFieldValue("CMI Supersessied Product Name");
currentSuperItemId = GetFieldValue("CMI Supersession Item Id");
//if new item, reset variables
if (lastSuperItemId != currentSuperItemId) {
lastSuperItemId = currentSuperItemId;
split = false;
neededQuantity = GetFieldValue("CMI Supersession Original Quantity");
TheApplication().Utility.logStep("Process "+currentSuperProduct+" - Needed: "+neededQuantity);
}
recType = GetFieldValue("CMI Supersession Recommendation Type");
availableQuantity = ToNumber(GetFieldValue("Available Quantity"));
recmndQuantity = ToNumber(GetFieldValue("CMI Recommended Quantity"));
recmndQuantity = (recmndQuantity == null ? 0 : recmndQuantity);
availableQuantity = (availableQuantity == null ? 0 : availableQuantity);
TheApplication().Utility.logVars(currentProduct+" - Rmng/Avail/Type",neededQuantity+" / "+availableQuantity+" / "+recType);
if (neededQuantity >= availableQuantity) {
updateQuantity = availableQuantity;
if (recType == "Split Recommendation") {
if (split == false) { //First split record, store recommendation
split = true;
splitQuantity = updateQuantity;
neededQuantity = neededQuantity - availableQuantity;
} else { //Remaining split records, use the same quantity, do not decrement needed qty
updateQuantity = splitQuantity;
}
} else {
neededQuantity = neededQuantity - availableQuantity;
}
} else if (neededQuantity < availableQuantity) {
updateQuantity = neededQuantity;
if (recType == "Split Recommendation") {
if (split == false) { //First split record, store recommendation
split = true;
splitQuantity = updateQuantity;
neededQuantity = 0;
} else { //Remaining split records, use the same quantity, do not decrement needed qty
updateQuantity = splitQuantity;
}
} else {
neededQuantity = 0;
}
}
SetFieldValue("CMI Recommended Quantity", updateQuantity)
WriteRecord();
supersessions = true;
quoteItemFound = NextRecord();
//If there is leftover needed quantity that could not be fulfilled by available inventory,
//assign to the last product in the supersession sequence which should be reorderable
if ((!quoteItemFound||(lastSuperItemId != GetFieldValue("CMI Supersession Item Id"))) && neededQuantity > 0) {
TheApplication().Utility.logVars("Excess Needed - Recmd/Rmng/Type",updateQuantity+" / "+neededQuantity+" / "+recType);
if (quoteItemFound) PreviousRecord(); //Navigate back to the prior record
else LastRecord(); //Navigate back to the last record
SetFieldValue("CMI Recommended Quantity", updateQuantity+neededQuantity);
WriteRecord();
//If a split, the same excess needed quantity needs to be added to all splits for the same SS source
while (recType == "Split Recommendation" && lastSuperItemId == GetFieldValue("CMI Supersession Item Id")) {
PreviousRecord(); //Navigate back to the previous split
recType = GetFieldValue("CMI Supersession Recommendation Type");
if (recType == "Split Recommendation") {
SetFieldValue("CMI Recommended Quantity", updateQuantity+neededQuantity);
WriteRecord();
}
}
//Advance the row back to the first record in the next SS
do {
quoteItemFound = NextRecord();
} while (quoteItemFound && lastSuperItemId == GetFieldValue("CMI Supersession Item Id")) ;
}
}
}
if (supersessions) {
SetFieldValue("CMI Supersession Status", superStatusPending);
WriteRecord();
} else {
SetFieldValue("CMI Supersession Status", superStatusNA);
WriteRecord();
}
}
}
//bcActive.InvokeMethod("RefreshBusComp");
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcQuoteItem = null;
// bcQuote = null;
boQuote = null;
TheApplication().Utility.logUnstack();
}
}

CMI Product Supersession Toolkit Service
ApplyRecommendations
function ApplyRecommendations(Inputs, Outputs) {
try{
TheApplication().Utility.logStack("ApplyRecommendations", this);
//Active BC
var bcActive:BusComp = TheApplication().ActiveBusObject().GetBusComp("Quote");
//Objects to cycle through quote and update records. Instantiate Quote and use UI Objects
//as Core item quantity updates need to trigger same to clean/dirty lines. Add to Quote needs to trigger Pricing
var boQuote:BusObject = TheApplication().GetBusObject("Quote");
var bcQuote:BusComp = boQuote.GetBusComp("Quote");
var bcQuoteItem:BusComp = boQuote.GetBusComp("Quote Item");
var quoteId = bcActive.GetFieldValue("Id")
var quoteItemFound = false;
var quoteFound = false;
var currentProduct = "";
var recmndQuantity:Number = 0;
var requestQuantity:Number = 0;
var supersessions = false;
var superStatusApplied = TheApplication().InvokeMethod("LookupValue", "CMI_QUOTE_SUPER_STAT_CD", "Applied");
var superStatusPending = TheApplication().InvokeMethod("LookupValue", "CMI_QUOTE_SUPER_STAT_CD", "Pending");
var superStatusNA = TheApplication().InvokeMethod("LookupValue", "CMI_QUOTE_SUPER_STAT_CD", "N/A");
var newFulfillSetId = "";
var oldFulfillSetId;
var ssItemId = "CURRENT";
var lastSSId = "OLD";
var currentId;
var quoteId;
var storeDltIds = new Array();
var fulSetId = "";
//Forces the Core service not to refresh the BO in case qty is updated on a Core. Refresh will occur in this service
TheApplication().SetProfileAttr("SkipRefresh", "TRUE");
//Instantiate the Quote so new quote items can be created underneath it
with (bcQuote) {
ClearToQuery();
ActivateField("CMI Supersession Status");
SetViewMode(AllView);
SetSearchSpec("Id", quoteId);
ExecuteQuery(ForwardBackward);
quoteFound = FirstRecord();
TheApplication().Utility.logVars("Quote found?", quoteFound, 5);
if (quoteFound && GetFieldValue("CMI Supersession Status") == superStatusPending) {
with (bcQuoteItem) {
ClearToQuery();
ActivateField("CMI Recommended Quantity");
ActivateField("Quantity Requested");
ActivateField("Product");
ActivateField("CMI Add To Quote Total")
ActivateField("CMI Supersession Item Id")
ActivateField("CMI Fulfillment Set Id");
ActivateField("CMI Supersession Flag");
ActivateField("CMI Supersession Original Fulfillment Set Id");
SetViewMode(AllView);
SetSearchSpec("CMI Supersession Product Id", "IS NOT NULL");
SetSearchSpec("CMI Supersession Flag", "N");
//Records to be deleted will be last so the survivor row id can be used as fulfillment set id
SetSortSpec("CMI Supersession Item Id, CMI Recommended Quantity (DESC)");
ExecuteQuery(ForwardBackward);
quoteItemFound = FirstRecord();
TheApplication().Utility.logVars("Recommendation Item found?", quoteItemFound);
while (quoteItemFound) {
supersessions = true;
currentProduct = GetFieldValue("Product");
recmndQuantity = ToNumber(GetFieldValue("CMI Recommended Quantity"));
requestQuantity = ToNumber(GetFieldValue("Quantity Requested"));
quoteId = GetFieldValue("Quote Id");
currentId = GetFieldValue("Id");
ssItemId = GetFieldValue("CMI Supersession Item Id");
fulSetId = GetFieldValue("CMI Fulfillment Set Id");
oldFulfillSetId = GetFieldValue("CMI Supersession Original Fulfillment Set Id");
//Group lines from the same SS record together. Reset variables when processing 1st line of new SS
if (ssItemId != lastSSId) {
newFulfillSetId = currentId;
lastSSId = ssItemId;
}
TheApplication().Utility.logVars(currentProduct+" - Rcmd/Req/New FS Id",recmndQuantity+" / "+requestQuantity+" / "+newFulfillSetId);
//Update Requested Quantity and Add to Quote if a recommendation is being made, otherwise delete the line
if (recmndQuantity > 0) {
//Updates to Add To Quote triggers SetFieldValue logic to cascade the value to all component items.
//This update triggers a WriteRecord to the Root line as well so no Write is needed.
SetFieldValue("CMI Fulfillment Set Id", oldFulfillSetId);
SetFieldValue("CMI Supersession Flag", "Y");
SetFieldValue("Quantity Requested", recmndQuantity);
SetFieldValue("CMI Add To Quote Total", "Y");
quoteItemFound = NextRecord();
} else {
if (ssItemId == currentId) storeDltIds[currentId] = newFulfillSetId;
DeleteRecord();
}
}
//Process after finishing the whole loop to avoid Selected Record errors
//if deleting the source SS Line, update all related lines Fulfill Set Id to the Id of the
//first line in the SS Group
for (var key in storeDltIds) {
TheApplication().Utility.logVars("Process Deletes - "+key,storeDltIds[key], 4);
TheApplication().Utility.cascade(bcQuoteItem, "Quote", "Quote Item (Simple)",
"[Quote Id] = '"+quoteId+"' AND [CMI Fulfillment Set Id] = '"+key+"'", false, "",
"CMI Fulfillment Set Id", storeDltIds[key]);
}
}
}
if (supersessions) {
SetFieldValue("CMI Supersession Status", superStatusApplied);
WriteRecord();
} else {
SetFieldValue("CMI Supersession Status", superStatusNA);
WriteRecord();
}
}
bcActive.InvokeMethod("RefreshBusComp");
with(TheApplication().ActiveBusObject().GetBusComp("Quote Item")) {
ClearToQuery();
ExecuteQuery();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().SetProfileAttr("SkipRefresh", "");
bcActive.InvokeMethod("SetRefreshRollups");
bcQuoteItem = null;
bcQuote = null;
boQuote = null;
TheApplication().Utility.logUnstack();
}
}

CMI Product Supersession Toolkit Service
AddQuoteLine
function AddQuoteLine(quoteId, recProductId, recProduct, recId, currentProduct, currentProductId, currentQuoteItemId, currentFulSetId, mode, sequence) {
try{
TheApplication().Utility.logStack("AddQuoteLine", this, false);
//Objects to cycle through quote and insert new records
var quoteItemFound = false;
var quoteFound = false;
var recProdFound = false;
var currentComments = "";
var supersessionNote = "Superseded Part: " + currentProduct;
//Instantiate the Quote so new quote items can be created underneath it; use UI Objects
//as Core item quantity updates need to trigger same to clean/dirty lines
if (!defined(boQuoteUpd)) {
boQuoteUpd = TheApplication().GetBusObject("Quote");
bcQuoteUpd = boQuoteUpd.GetBusComp("Quote");
with (bcQuoteUpd) {
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Id", quoteId);
ExecuteQuery(ForwardOnly);
quoteFound = FirstRecord();
if (quoteFound) {
bcQuoteItemUpd = boQuoteUpd.GetBusComp("Quote Item");
}
}
}
with(bcQuoteItemUpd) {
ClearToQuery();
//BB 08012013: Add comments for original product.
ActivateField("CMI Supersessied Product Name");
ActivateField("Description");
ActivateField("CMI Recommended Quantity");
ActivateField("Quantity Requested");
ActivateField("CMI Supersession Item Id");
ActivateField("CMI Supersession Flag");
ActivateField("CMI Supersession Product Id");
ActivateField("CMI Add To Quote Total");
ActivateField("CMI Supersession Sequence");
ActivateField("CMI Fulfillment Set Id");
ActivateField("CMI Supersession Recommendation Id");
ActivateField("CMI Quote Type");
SetViewMode(AllView);
SetSearchSpec("Product Id", recProductId);
ExecuteQuery(ForwardBackward)
recProdFound = FirstRecord();
TheApplication().Utility.logStep("Recommendation ("+sequence+") "+currentProduct+" "+mode+" "+recProduct+" ("+recProductId+") - Exists on Quote? "+recProdFound);
if (recProdFound && GetFieldValue("CMI Quote Type")==serviceQuote) {
//If the product already exists on the quote (and it was not added as the result of a previous run) stamp it with supersession attributes
if (GetFieldValue("CMI Supersession Product Id") == "") {
//If product already exists on the quote, recommended qty starting point is the Requested Quantity
if (GetFieldValue("Quantity Requested") != GetFieldValue("CMI Recommended Quantity")) {
SetFieldValue("CMI Recommended Quantity", GetFieldValue("Quantity Requested"));
}
SetFieldValue("CMI Supersession Item Id", currentQuoteItemId);
SetFieldValue("CMI Supersession Recommendation Id", recId);
SetFieldValue("CMI Supersession Product Id", currentProductId);
SetFieldValue("CMI Supersession Sequence", sequence);
SetFieldValue("CMI Fulfillment Set Id", currentFulSetId);
// BB 080113: Add comment with original product:
currentComments = GetFieldValue("Description");
if (currentComments.length > 0) {
SetFieldValue("Description", currentComments + ". " + supersessionNote);
} else {
SetFieldValue("Description", supersessionNote);
}
sequence += 1;
WriteRecord();
}
} else {
NewRecord(NewAfter);
SetFieldValue("CMI Supersession Item Id", currentQuoteItemId);
SetFieldValue("CMI Supersession Recommendation Id", recId);
SetFieldValue("CMI Supersession Product Id", currentProductId);
SetFieldValue("CMI Supersession Sequence", sequence);
SetFieldValue("CMI Add To Quote Total", "N");
SetFieldValue("Product", recProduct);
SetFieldValue("CMI Fulfillment Set Id", currentFulSetId);
// BB 080113: Add comment with original product:
SetFieldValue("Description", supersessionNote);
sequence += 1;
WriteRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
return (sequence);
}

CMI Product Supersession Toolkit Service
AddLines
function AddLines(Inputs, Outputs) {
try{
TheApplication().Utility.logStack("AddLines", this);
//Active BC
var bcActive:BusComp = TheApplication().ActiveBusObject().GetBusComp("Quote");
//Objects to cycle through quote and insert new records.
var boQuote:BusObject = TheApplication().GetBusObject("CMI Quote");
var bcQuoteItem:BusComp = boQuote.GetBusComp("Quote Item (Simple)");
var bcProdRec:BusComp = boQuote.GetBusComp("CMI Product Recommendation");
var bcProdRecRev:BusComp = boQuote.GetBusComp("CMI Product Recommendation - Reverse");
var quoteId = bcActive.GetFieldValue("Id")
var quoteItemFound = false;
var quoteFound = false;
var found = false;
var currentQuoteItemId = "";
var currentProductId = "";
var currentProduct = "";
var currentSuperStatus = "";
var currentFulSetId = "";
var recProductId = "";
var recProduct = "";
var recId = "";
var supersessions = false;
var lineSupersessions = false;
var superStatusFound = TheApplication().InvokeMethod("LookupValue", "CMI_QUOTE_SUPER_STAT_CD", "Found");
var superStatusRun = TheApplication().InvokeMethod("LookupValue", "CMI_QUOTE_SUPER_STAT_CD", "Run");
var superStatusNA = TheApplication().InvokeMethod("LookupValue", "CMI_QUOTE_SUPER_STAT_CD", "N/A");
var sequence = 0;
var originalLineSequence = 0;
//Forces the Core service not to refresh the BO in case qty is updated on a Core. Refresh will occur in this service
TheApplication().SetProfileAttr("SkipRefresh", "TRUE");
//Instantiate the Quote to evaluate SS Status and update when done
with (bcActive) {
ActivateField("CMI Supersession Status");
currentSuperStatus = GetFieldValue("CMI Supersession Status");
TheApplication().Utility.logVars("Supersession Status", currentSuperStatus);
//Only process quotes that have not already been checked (check for Blank as well for quotes created before this feature was implemented)
if (currentSuperStatus == superStatusRun || currentSuperStatus == "") {
//for Blank quotes created before this feature was implemented, update to Run so remaining logic will work
if (currentSuperStatus == "") {
SetFieldValue("CMI Supersession Status", superStatusRun);
WriteRecord();
}
//Query and loop through same items available in List for ATP
with (bcQuoteItem) {
ClearToQuery();
ActivateField("CMI Supersession Item Id");
ActivateField("CMI Supersession Flag");
ActivateField("CMI Supersession Product Id");
ActivateField("CMI Supersession Sequence");
ActivateField("CMI Fulfillment Set Id");
ActivateField("CMI Quote Sold From Inv Loc Id");
ActivateField("Product");
ActivateField("Product Id");
ActivateField("Quantity Requested");
ActivateField("CMI Recommended Quantity");
SetViewMode(AllView);
SetSearchSpec("Quote Id", quoteId);
SetSearchSpec("CMI NO ATP FLAG", "Y");
SetSearchSpec("CMI Write In Identifier", "<> 'Yes' OR IS NULL");
SetSearchSpec("CMI NO ATP Category Flag", "Y");
SetSearchSpec("CMI Main Assembly Flag", "<> 'Y' OR IS NULL");
SetSearchSpec("CMI Dirty Calc ATP Qty", "Y");
SetSearchSpec("CMI Supersession Flag", "N");
ExecuteQuery(ForwardBackward);
quoteItemFound = FirstRecord();
TheApplication().Utility.logVars("ATP Item found?", quoteItemFound);
while (quoteItemFound) {
currentQuoteItemId = GetFieldValue("Id");
currentProductId = GetFieldValue("Product Id");
currentProduct = GetFieldValue("Product");
currentFulSetId = GetFieldValue("CMI Fulfillment Set Id");
TheApplication().Utility.logStep("Process "+currentProduct+" - Line Id: "+currentQuoteItemId, 5);
//Check for superceded product recommendations
bcProdRecRev.ClearToQuery();
bcProdRecRev.ActivateField("Recommeded Product Name");
bcProdRecRev.ActivateField("Recommended Product ID");
bcProdRecRev.ActivateField("Recommendation Id");
bcProdRecRev.SetViewMode(AllView);
bcProdRecRev.SetSearchSpec("CMI Product Status", "'SS Use' OR 'Active'");
bcProdRecRev.SetSearchSpec("CMI Product Orderable", "'Y'");
bcProdRecRev.SetSearchSpec("Effective Start Date", "IS NULL OR <= Today()");
bcProdRecRev.SetSearchSpec("Effective End Date", "IS NULL OR >= Today()");
bcProdRecRev.SetSearchSpec("UMS Type", "Like 'Superseded*' or Like 'Substitute*'");
bcProdRecRev.ExecuteQuery(ForwardBackward);
found = bcProdRecRev.FirstRecord();
//If Superceded product recommendations exist, add them as line items
while(found) {
recProductId = bcProdRecRev.GetFieldValue("Recommended Product ID");
recProduct = bcProdRecRev.GetFieldValue("Recommeded Product Name");
recId = bcProdRecRev.GetFieldValue("Recommendation Id");
lineSupersessions = true;
//check if line already exists. Use 2nd instantiation to avoid Selected record errors while keeping the main cursor open
sequence = AddQuoteLine(quoteId, recProductId, recProduct, recId, currentProduct, currentProductId, currentQuoteItemId, currentFulSetId, "Supercedes", sequence);
found = bcProdRecRev.NextRecord();
}
//Need to set the original line sequence to a value between the superceded and superceding values
originalLineSequence = sequence;
sequence += 1;
//Check for Superceding product recommendations
bcProdRec.ClearToQuery();
bcProdRec.ActivateField("Recommeded Product Name");
bcProdRec.ActivateField("Recommended Product ID");
bcProdRec.ActivateField("Recommendation Id");
bcProdRec.SetViewMode(AllView);
bcProdRec.SetSearchSpec("CMI Product Status", "'SS Use' OR 'Active'");
bcProdRec.SetSearchSpec("CMI Product Orderable", "'Y'");
bcProdRec.SetSearchSpec("Effective Start Date", "IS NULL OR <= Today()");
bcProdRec.SetSearchSpec("Effective End Date", "IS NULL OR >= Today()");
bcProdRec.ExecuteQuery(ForwardBackward);
found = bcProdRec.FirstRecord();
//If Superceding product recommendations exist, add them as line items
while(found) {
recProductId = bcProdRec.GetFieldValue("Recommended Product ID");
recProduct = bcProdRec.GetFieldValue("Recommeded Product Name");
recId = bcProdRec.GetFieldValue("Recommendation Id");
lineSupersessions = true;
//check if line already exists. Use 2nd instantiation to avoid Selected record errors while keeping the main cursor open
sequence = AddQuoteLine(quoteId, recProductId, recProduct, recId, currentProduct, currentProductId, currentQuoteItemId, currentFulSetId, "Superceded by", sequence);
found = bcProdRec.NextRecord();
}
//If the line being processed has supersession recommendations mark this line as well so it can be grouped with its recommendations when processing them
if (lineSupersessions && GetFieldValue("CMI Supersession Flag") == "N") {
TheApplication().Utility.logStep("Recommendation ("+originalLineSequence+") "+currentProduct);
supersessions = true;
SetFieldValue("CMI Supersession Item Id", currentQuoteItemId);
SetFieldValue("CMI Supersession Product Id", currentProductId);
SetFieldValue("CMI Supersession Sequence", originalLineSequence);
WriteRecord();
}
lineSupersessions = false;
sequence = 0;
quoteItemFound = NextRecord();
}
//If the quote has recommendations, indicate that some were found so that later methods will know to process them
//bcActive.InvokeMethod("RefreshRecord"); //gbay 080613 CQ11865
if (supersessions) {
bcActive.SetFieldValue("CMI Supersession Status", superStatusFound);
WriteRecord();
//TheApplication().Utility.logStep("Quote Id after Write", bcActive.GetFieldValue("Id"));
} else {
bcActive.SetFieldValue("CMI Supersession Status", superStatusNA);
WriteRecord();
//TheApplication().Utility.logStep("Quote Id after Write", bcActive.GetFieldValue("Id"));
}
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().SetProfileAttr("SkipRefresh", "");
bcProdRecRev = null;
bcProdRec = null;
bcQuoteItem = null;
boQuote = null;
TheApplication().Utility.logUnstack();
}
}

CMI Product Supersession Toolkit Service
AddHierarchichalRecInterface
function AddHierarchichalRecInterface(Inputs, Outputs)
{
//LC657 Created for Product supercession integration CQ#12198
try{
TheApplication().Utility.logStack("AddHierarchichalRecInterface", this);
//var boActive:BusObject = TheApplication().ActiveBusObject();
var boActive:BusObject = TheApplication().GetBusObject("Admin ISS Product Definition");
//var sProdId = TheApplication().GetProfileAttr("CMISSParentProductId");
var bcProduct:BusComp;
var bcProductRec:BusComp;
var bcReverseRec:BusComp;
var oldProdId = TheApplication().GetProfileAttr("SSParProdId");
var newProdId = TheApplication().GetProfileAttr("SSRecProdId");
var recFound = false;
var currScore:Number;
var newTypeId = TheApplication().GetProfileAttr("SSUMSTypeId");
var newType = TheApplication().GetProfileAttr("SSUMSType");
var reverseRec = "";
var reverseType = "";
//lc657 CQ#12222
var sEffectiveDate:String = TheApplication().GetProfileAttr("SSEffectiveDate");
if (defined(boActive) && boActive.Name() != "") {
bcProduct = boActive.GetBusComp("Internal Product - ISS Admin");
bcProductRec = boActive.GetBusComp("Product Recommendation");
bcReverseRec = boActive.GetBusComp("CMI Product Recommendation - Reverse Admin");
TheApplication().Utility.logVars("oldProdId", oldProdId);
TheApplication().Utility.logVars("newProdId", newProdId);
TheApplication().Utility.logVars("newTypeId", newTypeId);
TheApplication().Utility.logVars("newType", newType);
TheApplication().Utility.logVars("sEffectiveDate", sEffectiveDate);
TheApplication().Utility.logStep("Process "+ oldProdId +" - Type: "+newType);
with(bcProduct) {
ClearToQuery();
SetViewMode(AllView);
SetSearchExpr("[Id] = '" + oldProdId + "'");
ExecuteQuery(ForwardBackward);
if (FirstRecord())
{
with (bcReverseRec) {
ClearToQuery();
ActivateField("Score");
ActivateField("Parent Product ID");
ActivateField("Recommeded Product Name");
ActivateField("UMS Type Id");
ActivateField("UMS Type");
SetViewMode(AllView);
ExecuteQuery(ForwardBackward);
recFound = FirstRecord();
TheApplication().Utility.logVars("ReverseRec?",recFound);
while (recFound) {
currScore = ToNumber(GetFieldValue("Score"));
TheApplication().Utility.logVars("currScore", currScore);
reverseRec = GetFieldValue("Recommeded Product Name");
TheApplication().Utility.logVars("reverseRec", reverseRec);
reverseType = GetFieldValue("UMS Type");
TheApplication().Utility.logVars("reverseType", reverseType);
TheApplication().Utility.logVars(reverseRec+" - Score/Type",currScore+" / "+reverseType);
//This is to update records where the score has not already been set such as those predating SS Implementation
if (currScore == "") {
SetFieldValue("Score", 1);
WriteRecord();
currScore = 1;
}
//The interface creates subsitute recommendations in both directions. Reverse multi level relationships should only be created
//once therefore stop processing if it is found that they already exist
//if (reverseType.indexOf("Substitute") == 0) { //gbay 08/01/13 CQ11874
// break; //gbay 08/01/13 CQ11874
//} else { //gbay 08/01/13 CQ11874
NewRecord(NewAfterCopy);
SetFieldValue("Parent Product ID", newProdId);
SetFieldValue("UMS Type Id", newTypeId);
SetFieldValue("Score", currScore + 1);
//LC657 CQ#12222
SetFieldValue("Effective Start Date", sEffectiveDate);
WriteRecord();
recFound = NextRecord();
//} //gbay 08/01/13 CQ11874
}
ClearToQuery();
ExecuteQuery(ForwardBackward);
}
} //end if FirstRecord
} //end with bcProduct
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcReverseRec = null;
bcProductRec = null;
bcProduct = null;
boActive = null;
TheApplication().Utility.logUnstack();
}
}

CMI Product Supersession Toolkit Service
AddHierarchichalRec
function AddHierarchichalRec(Inputs, Outputs)
{
try{
TheApplication().Utility.logStack("AddHierarchichalRec", this);
var boActive:BusObject = TheApplication().ActiveBusObject();
var bcProduct:BusComp;
var bcProductRec:BusComp;
var bcReverseRec:BusComp;
var oldProdId = "";
var newProdId = "";
var recFound = false;
var currScore:Number;
var newTypeId = "";
var newType = "";
var reverseRec = "";
var reverseType = "";
if (defined(boActive) && boActive.Name() != "") {
bcProduct = boActive.GetBusComp("Internal Product - ISS Admin");
bcProductRec = boActive.GetBusComp("Product Recommendation");
bcReverseRec = boActive.GetBusComp("CMI Product Recommendation - Reverse Admin");
oldProdId = bcProduct.GetFieldValue("Id");
TheApplication().Utility.logVars("oldProdId", oldProdId);
newProdId = bcProductRec.GetFieldValue("Recommended Product ID");
TheApplication().Utility.logVars("newProdId", newProdId);
newTypeId = bcProductRec.GetFieldValue("UMS Type Id");
TheApplication().Utility.logVars("newTypeId", newTypeId);
newType = bcProductRec.GetFieldValue("UMS Type");
TheApplication().Utility.logVars("newType", newType);
TheApplication().Utility.logStep("Process "+bcProduct.GetFieldValue("Name")+" - Type: "+newType);
with (bcReverseRec) {
ClearToQuery();
ActivateField("Score");
ActivateField("Parent Product ID");
ActivateField("Recommeded Product Name");
ActivateField("UMS Type Id");
SetViewMode(AllView);
ExecuteQuery(ForwardOnly);
recFound = FirstRecord();
TheApplication().Utility.logVars("ReverseRec?",recFound);
while (recFound) {
currScore = ToNumber(GetFieldValue("Score"));
TheApplication().Utility.logVars("currScore", currScore);
reverseRec = GetFieldValue("Recommeded Product Name");
TheApplication().Utility.logVars("reverseRec", reverseRec);
reverseType = GetFieldValue("UMS Type");
TheApplication().Utility.logVars("reverseType", reverseType);
TheApplication().Utility.logVars(reverseRec+" - Score/Type",currScore+" / "+reverseType);
//This is to update records where the score has not already been set such as those predating SS Implementation
if (currScore == "") {
SetFieldValue("Score", 1);
WriteRecord();
currScore = 1;
}
//The interface creates subsitute recommendations in both directions. Reverse multi level relationships should only be created
//once therefore stop processing if it is found that they already exist
//if (reverseType.indexOf("Substitute") == 0) { //gbay 08/01/13 CQ11874
// break; //gbay 08/01/13 CQ11874
//} else { //gbay 08/01/13 CQ11874
NewRecord(NewAfterCopy);
SetFieldValue("Parent Product ID", newProdId);
SetFieldValue("UMS Type Id", newTypeId);
SetFieldValue("Score", currScore + 1);
WriteRecord();
recFound = NextRecord();
//} //gbay 08/01/13 CQ11874
}
ClearToQuery();
ExecuteQuery(ForwardBackward);
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcReverseRec = null;
bcProductRec = null;
bcProduct = null;
boActive = null;
TheApplication().Utility.logUnstack();
}
}

CMI Product Transit BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : Pankaj Sinha
Created On : 14th January 2010
Method Name: function BusComp_PreInvokeMethod (MethodName) == "Query"
Functionality: This method will be triggered when the user clicks the "Check Availability" Button from Order Line Item,
Service Request and Product. This BS is invoked from VBC.
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try{
switch (MethodName)
{
case "Init" :
Outputs.SetProperty ("CMI Plant Supplier", "");
Outputs.SetProperty ("CMI Shippment Id", "");
Outputs.SetProperty ("CMI In Transit Quantity", "");
Outputs.SetProperty ("CMI Estimated Delivery Date", "");
Outputs.SetProperty ("CMI Destination Warehouse", "");
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
case "Query" :
var val=TheApplication().GetProfileAttr("Flag");
if (val=="Y"){
var sId = TheApplication().GetProfileAttr("RowId");
var sPBU = TheApplication().GetProfileAttr("BU");
var oBS;
var inpPS;
var outPS, tempOutPS;
var sSRFlag;
var oCacheBS;
inpPS = TheApplication().NewPropertySet();
outPS = TheApplication().NewPropertySet();
tempOutPS = TheApplication().NewPropertySet();
sSRFlag = TheApplication().GetProfileAttr("SRFlag");
// commented per Ticket#INC000000975863 if (sSRFlag == "Y")
{
oBS = TheApplication().GetService("Workflow Process Manager");
inpPS.SetProperty("CumminsPart#", sId);
inpPS.SetProperty("BusinessUnit", sPBU);
inpPS.SetProperty("ProcessName", "CMI Inventory Check Integration Workflow");
oBS.InvokeMethod("RunProcess", inpPS, outPS);
// commented per Ticket#INC000000975863 oCacheBS = TheApplication().GetService("CMI Cache PropertySet Integration");
// commented per Ticket#INC000000975863 oCacheBS.InvokeMethod("StorePS", outPS, tempOutPS);
}
/* commented per Ticket#INC000000975863 else
{
oCacheBS = TheApplication().GetService("CMI Cache PropertySet Integration");
oCacheBS.InvokeMethod("RecallPS", inpPS, tempOutPS);
outPS = tempOutPS.GetChild(0).Copy();
oCacheBS.InvokeMethod("ClearPS", inpPS, tempOutPS);
} */
var strErrCode = outPS.GetProperty("Error Code");
var strErrMsg = outPS.GetProperty("Error Message");
var strAIAErrCode = outPS.GetProperty("AIAErrorCode");
var strAIAErrMsg = outPS.GetProperty("AIAErrorMessage");
if ((strErrMsg == "")&&(strAIAErrMsg == ""))
{
if (outPS.GetChild(0).GetChild(0).GetChild(0).GetChildCount() > 1) //Checks the presence of ListOfbody
{
if (outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChildCount() > 0) //Checks the presence of body
{
if(outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChildCount() > 0) //Checks the presence of ListOfInventory
{
if(outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChildCount() > 0) //Checks the presence of Inventory
{
if (outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChildCount() > 1) //Checks the presence of ListOfInTransitInventory
{
var InTransChildCount = outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChildCount();
if( InTransChildCount > 0)
{
var sListOfInTransitInventory = TheApplication().NewPropertySet();
sListOfInTransitInventory = outPS.GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetChild(0);
var sPlantSupplier = new Array;
var sWarehouse = new Array;
var sShipmentId = new Array;
var sEstDeliveryDate = new Array;
var sInTransitQty = new Array;
for (var i=0;i<InTransChildCount;i++)
{
sPlantSupplier[i] = sListOfInTransitInventory.GetChild(i).GetProperty("PlantSupplier");
sWarehouse[i] = sListOfInTransitInventory.GetChild(i).GetProperty("DestinationWarehouse");
sShipmentId[i] = sListOfInTransitInventory.GetChild(i).GetProperty("ShipmentId");
sEstDeliveryDate[i] = sListOfInTransitInventory.GetChild(i).GetProperty("EstimatedDeliveryDate");
sInTransitQty[i] = sListOfInTransitInventory.GetChild(i).GetProperty("InTransitQuantity");
var InTransitItem = TheApplication().NewPropertySet();
InTransitItem.SetProperty ("CMI Plant Supplier",sPlantSupplier[i]);
InTransitItem.SetProperty ("CMI Destination Warehouse",sWarehouse[i]);
InTransitItem.SetProperty ("CMI Shippment Id",sShipmentId[i]);
InTransitItem.SetProperty ("CMI In Transit Quantity",sInTransitQty[i]);
InTransitItem.SetProperty ("CMI Estimated Delivery Date",sEstDeliveryDate[i]);
Outputs.AddChild(InTransitItem);
}
}
}
}
}
}
}
}
else
{
TheApplication().SetProfileAttr("InterfaceErrMsg",strErrMsg);
TheApplication().SetProfileAttr("AIAInterfaceErrMsg",strAIAErrMsg);
}
return (CancelOperation);
}
else
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
}
}// end of try
catch(e)
{
/*if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " +"ERROR: " + e.errText +"STACK: " + e.toString());
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "ERROR: " + e.errText +"STACK: " + e.toString());
}*/
TheApplication().SetProfileAttr("InterfaceErrMsg",e.toString());
}// end of catch
finally
{
tempOutPS = null;
outPS = null;
inpPS = null;
oBS = null;
sPBU = null;
sId = null;
val = null;
sInTransitQty = null;
sEstDeliveryDate = null;
sShipmentId = null;
sWarehouse = null;
sPlantSupplier = null;
sListOfInTransitInventory = null; // nullify this object ,by jw920 19/08/11
InTransitItem = null; // nullify this object ,by jw920 19/08/11
InTransChildCount = null; // nullify this object ,by jw920 19/08/11
//oCacheBS = null;
}
return (ContinueOperation);
}

CMI QSOL Integration BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/************************************************************************
CMI <Release# 2 - CRP1.5- DBU>, <Req# xxx>, C&I# xxxx <Integration>:
<BS to invoke QSOL page> By <KrishnaPriya> On <10 Aug 2010>.
*************************************************************************/
try
{
var sId = Inputs.GetProperty("RowId");
var sSource = Inputs.GetProperty("Source");
if(MethodName == "InvokeQSOL")
{
InvokeQSOL(sSource,sId);
return(CancelOperation);
}
else if(MethodName == "CloseQSOL")
{
CloseQSOL(sSource,sId);
return(CancelOperation);
}
return (ContinueOperation);
}
catch(e)
{
throw(e)
}
finally
{
sId = null;
sSource = null;
inpPS = null;
outPS = null;
bs = null;
}
}

CMI QSOL Integration BS
InvokeQSOL
function InvokeQSOL(sSource,sId)
{
// Added/Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
var sId;
switch (sSource)
{
case "Action":
// TheApplication().GotoView("CMI QSOL Action View","Action");
sId = TheApplication().ActiveBusObject().GetBusComp("Action").GetFieldValue("Id");
inpPS.SetProperty("Business Component","Action");
inpPS.SetProperty("View","CMI QSOL Action URL View");
break;
case "Quote":
sId = TheApplication().ActiveBusObject().GetBusComp("Quote").GetFieldValue("Id");
inpPS.SetProperty("Business Component","Quote");
inpPS.SetProperty("View","CMI QSOL Quote URL View");
TheApplication().SetProfileAttr("QSOL_SALES_SERVICE","SERVICE");
break;
case "Quote_Sales":
sId = TheApplication().ActiveBusObject().GetBusComp("Quote").GetFieldValue("Id");
inpPS.SetProperty("Business Component","Quote");
inpPS.SetProperty("View","CMI QSOL Quote URL View");
TheApplication().SetProfileAttr("QSOL_SALES_SERVICE","SALES");
break;
case "Order":
// TheApplication().GotoView("CMI QSOL Order View","Order Entry");
sId = TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetFieldValue("Id");
inpPS.SetProperty("Business Component","Order Entry - Orders");
inpPS.SetProperty("View","CMI QSOL Order URL View");
break;
}
inpPS.SetProperty("Row Id",sId);
TheApplication().SetProfileAttr("QSOL_ACTIVE_RECORD",sId);
// bs = TheApplication().GetService("PUB Workflow Service");
outPS = bs.InvokeMethod("GotoView",inpPS,outPS);
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
} finally {
sId = null;
}
//<End>
}
/* var oQuoteBO = TheApplication().GetBusObject("Quote");
var oQuoteBC = oQuoteBO.GetBusComp("Quote");
with(oQuoteBC)
{
ClearToQuery();
SetViewMode(5);
SetSearchSpec("Id", sId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
TheApplication().GotoView("CMI QSOL Quote URL View",oQuoteBO);
}
}
*/ //TheApplication().GotoView("CMI QSOL Quote URL View");

CMI QSOL Integration BS
CloseQSOL
function CloseQSOL(sSource,sId)
{
// Added/Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
var sId;
switch (sSource)
{
case "Action":
// TheApplication().GotoView("FS Activity Recommended Parts and Tools","Action");
sId = TheApplication().ActiveBusObject().GetBusComp("Action").GetFieldValue("Id");
inpPS.SetProperty("Business Component","Action");
inpPS.SetProperty("View","FS Activity Recommended Parts and Tools");
break;
case "Quote":
sId = TheApplication().ActiveBusObject().GetBusComp("Quote").GetFieldValue("Id");
inpPS.SetProperty("Business Component","Quote");
switch (TheApplication().GetProfileAttr("QSOL_SALES_SERVICE"))
{
case "SALES":
inpPS.SetProperty("View","CMI Parts Quote Detail View");
break;
case "SERVICE":
inpPS.SetProperty("View","Quote Detail View");
break;
}
break;
case "Order":
// TheApplication().GotoView(Order Entry - Line Items Detail View (Sales),"Order Entry");
sId = TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetFieldValue("Id");
inpPS.SetProperty("Business Component","Order Entry - Orders");
inpPS.SetProperty("View","Order Entry - Line Items Detail View (Sales)");
break;
}
sId = TheApplication().GetProfileAttr("QSOL_ACTIVE_RECORD");
inpPS.SetProperty("Row Id",sId);
// bs = TheApplication().GetService("PUB Workflow Service");
outPS = bs.InvokeMethod("GotoView",inpPS,outPS);
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
} finally {
sId = null;
}
//<End>
}
/* var oQuoteBO = TheApplication().GetBusObject("Quote");
var oQuoteBC = oQuoteBO.GetBusComp("Quote");
with(oQuoteBC)
{
ClearToQuery();
SetViewMode(5);
SetSearchSpec("Id", sId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
TheApplication().GotoView("Quote Detail View",oQuoteBO);
}
}
*/

CMI QSOL Integration BS
(declarations)
var inpPS = TheApplication().NewPropertySet();
var outPS = TheApplication().NewPropertySet();
var bs = TheApplication().GetService("PUB Workflow Service");

CMI QSOL Parts Validation
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
// Added/Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
switch (MethodName) {
case "Check Part in Siebel":
CheckPartinSiebel(Inputs, Outputs);
break;
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI QSOL Parts Validation
CheckPartinSiebel
/****************************************************************************************
**Function to Query for Products coming from QSOL, and remove invalid ones from the property set
**Prepared By: Praveen Pentyela
**Date: 12-Aug-2010
**C&I: 4312
**Input: Payload from MW
**Output: UserKeys for Quote/Order/Action and Item. Updated Payload.
****************************************************************************************/
function CheckPartinSiebel(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("CheckPartinSiebel", this);
var psSiebelMessage = TheApplication().NewPropertySet();
psSiebelMessage = Inputs.GetChild(0).Copy();
var sProdExists = "N";
var sProdName = "";
var sProdQty = "";
var sErrMessage = "";
var sErrMessage1 = null;
var sErrCode = "";
var sSource = "";
var sDataMap = "Wrong Source";
var iProdCount = "";
var iCount = "";
var iTotal = ""; //to capture total number of items
var iInvalid = 0; //to capture number of invalid items
var qAccountId = "";
var qName = "";
var qRevision = "";
var qPrimaryOrganizationId = "";
var qActivityId = "";
var qOrderNum = "";
var sObjectId = "";
var BoHeader = "";
var BcItem = "";
var sBOProduct:BusObject = TheApplication().GetBusObject("CMI Product Update Integration");// Added by ki795 on 7-Feb-2012 for bug # 2192
var BcPick:BusComp = sBOProduct.GetBusComp("Internal Product - ISS Admin");// Modified by ki795 on 7-Feb-2012 for bug # 2192
var boQuote = "";
var bcQuote = "";
var bo = null;
var bc = null;
var boAction = "";
var bcAction = "";
var boOrder = "";
var bcOrder = "";
var sSearchExpr = "";
var qItemUserKey = "";
var bodynum = 1; //to make the process work if header is not provided
var found = false;
var sSearchProdSpec = ""; // Added by ki795 on 7-Feb-2012 for bug # 2192
if (psSiebelMessage.GetChild(0).GetChild(0).GetChildCount() == 1) {
bodynum = 0;
}
iProdCount = psSiebelMessage.GetChild(0).GetChild(0).GetChild(bodynum).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChildCount();
iTotal = iProdCount;
sSource = psSiebelMessage.GetChild(0).GetChild(0).GetChild(bodynum).GetChild(0).GetChild(0).GetChild(0).GetProperty("ObjectName");
sObjectId = psSiebelMessage.GetChild(0).GetChild(0).GetChild(bodynum).GetChild(0).GetChild(0).GetChild(0).GetProperty("SiebelObjectId");
//sProdName = psSiebelMessage.GetChild(0).GetChild(0).GetChild(bodynum).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(iCount).GetProperty("PartNumber");
TheApplication().Utility.logVars("Source", sSource);
switch (sSource) {
case "Action":
sDataMap = TheApplication().InvokeMethod("LookupValue","EAI_QSOL_DM", "ActionDM");
bo = TheApplication().InvokeMethod("LookupValue","EAI_QSOL_DM", "ActionBO");
//bc = TheApplication().InvokeMethod("LookupValue","EAI_QSOL_DM", "ActionBC");
bc = "FS Activity Recommended Parts & Tools";
//sDataMap = "QSOL Msg to Action";
//sSearchExpr = "[Product Name] = '" + sProdName + "' AND [Activity Id] = '" + sObjectId + "'"
boAction = TheApplication().GetBusObject("Action");
bcAction = boAction.GetBusComp("Action");
with (bcAction) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("Activity UID");
ActivateField("Id");
SetSearchSpec("Id",sObjectId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Activity ("+sObjectId+") found?", found);
if(found) {
qActivityId = GetFieldValue("Activity UID");
}
}
break;
case "Quote":
sDataMap = TheApplication().InvokeMethod("LookupValue","EAI_QSOL_DM", "QuoteDM");
bo = TheApplication().InvokeMethod("LookupValue","EAI_QSOL_DM", "QuoteBO");
bc = TheApplication().InvokeMethod("LookupValue","EAI_QSOL_DM", "QuoteBC");
boQuote = TheApplication().GetBusObject("Quote");
bcQuote = boQuote.GetBusComp("Quote");
with (bcQuote) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("Account Id");
ActivateField("Id");
ActivateField("Name");
ActivateField("Revision");
ActivateField("Primary Organization Id");
SetSearchSpec("Id",sObjectId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Quote ("+sObjectId+") found?", found);
if(found) {
qAccountId = GetFieldValue("Account Id");
qName = GetFieldValue("Name");
qRevision = GetFieldValue("Revision");
qPrimaryOrganizationId = GetFieldValue("Primary Organization Id");
}
}
break;
case "Order":
sDataMap = TheApplication().InvokeMethod("LookupValue","EAI_QSOL_DM", "OrderDM");
bo = TheApplication().InvokeMethod("LookupValue","EAI_QSOL_DM", "OrderBO");
bc = TheApplication().InvokeMethod("LookupValue","EAI_QSOL_DM", "OrderBC");
//sSearchExpr = "[Product] = '" + sProdName + "' AND [Order Header Id] = '" + sObjectId + "'"
// sDataMap = "QSOL Msg to Order";
boOrder = TheApplication().GetBusObject("Order Entry (Sales)");
bcOrder = boOrder.GetBusComp("Order Entry - Orders");
with (bcOrder) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("Order Number");
ActivateField("Id");
SetSearchSpec("Id",sObjectId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Order ("+sObjectId+") found?", found);
if(found) {
qOrderNum = GetFieldValue("Order Number");
qPrimaryOrganizationId = GetFieldValue("Primary Organization Id");
}
}
break;
}
for (iCount = 0; iCount <= iProdCount - 1; iCount++) {
sProdExists = "N";
sProdName = psSiebelMessage.GetChild(0).GetChild(0).GetChild(bodynum).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(iCount).GetProperty("PartNumber");
TheApplication().Utility.logStep("Process Product "+iCount+": "+sProdName);
if (sProdName != "") {
sSearchProdSpec = "[Name] = '" + sProdName + "' AND "+
"EXISTS([CMI Org Orderable Flag] = 'Y' AND [Organization Id] = '"+qPrimaryOrganizationId+"')"+
" AND [Prod Prom Instance Flag] = 'Y'";
BoHeader = TheApplication().GetBusObject(bo);
BcItem = BoHeader.GetBusComp(bc);
TheApplication().Utility.logVars("Business Component", bc);
if(bc == "FS Activity Recommended Parts & Tools") {
with (BcItem) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("Product Name");
ActivateField("CMI QSOL Qty");
SetSearchExpr("[Product Name] = '" + sProdName + "' AND [Activity Id] = '" + sObjectId + "'");
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Item found?", found);
if(found) {
sProdExists = "Y";
SetFieldValue("CMI QSOL Qty",'0');
qItemUserKey = GetFieldValue("Id"); //added on 22Mar2011 // will set the rowid of item, will be used as user key
WriteRecord();
} else {
//BcPick = GetPicklistBusComp("Product Name"); // Commented by ki795 on 7-Feb-2012 for bug # 2192
with (BcPick) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("Name");
//SetSearchSpec("Name",sProdName);// Commented by ki795 on 7-Feb-2012 for bug # 2192
SetSearchExpr(sSearchProdSpec);// Added by ki795 on 7-Feb-2012 for bug # 2192
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Product found?", found);
if(found) {
sProdExists = "Y";
sProdQty = psSiebelMessage.GetChild(0).GetChild(0).GetChild(bodynum).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(iCount).GetProperty("Quantity");
psSiebelMessage.GetChild(0).GetChild(0).GetChild(bodynum).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(iCount).SetProperty("Quantity",sProdQty - 1);
}
}
}
}
} else {
if(bc == "Quote Item") {
sSearchExpr = "[Product] = '" + sProdName + "' AND [Quote Id] = '" + sObjectId + "' AND [Integration Id] = '" + sProdName + "'";
} else if(bc == "Order Entry - Line Items") {
sSearchExpr = "[Product] = '" + sProdName + "' AND [Order Header Id] = '" + sObjectId + "' AND [Integration Id] = '" + sProdName + "'";
}
with (BcItem) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("Product");
ActivateField("CMI QSOL Qty");
SetSearchExpr(sSearchExpr);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Item found?", found);
if(found) {
sProdExists = "Y";
SetFieldValue("CMI QSOL Qty",'0');
qItemUserKey = GetFieldValue("Id"); //added on 22Mar2011 // will set the rowid of item, will be used as user key
WriteRecord();
} else {
with (BcPick) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("Name");
//SetSearchSpec("Name",sProdName);// Commented by ki795 on 7-Feb-2012 for bug # 2192
SetSearchExpr(sSearchProdSpec);// Added by ki795 on 7-Feb-2012 for bug # 2192
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Product found?", found);
if(found) {
sProdExists = "Y";
sProdQty = psSiebelMessage.GetChild(0).GetChild(0).GetChild(bodynum).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(iCount).GetProperty("Quantity");
psSiebelMessage.GetChild(0).GetChild(0).GetChild(bodynum).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(iCount).SetProperty("Quantity",sProdQty - 1);
}
}
}
}
}
//write a code to verify if the prod is valid or not
//Product also should be available at line item level, in Care we need a Xref and the product should be released
//in vanilla we would need the product should have a catalog category
//if Productmatches all such criterion set sProdExists = "Y"
}
TheApplication().Utility.logVars("Product Exists", sProdExists);
if (sProdExists == "N") {
if (sProdName == null) {
sErrMessage1 = sSource;
} else {
sErrMessage = sProdName + "," + sErrMessage;
}
psSiebelMessage.GetChild(0).GetChild(0).GetChild(bodynum).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).RemoveChild(iCount); //removing the item from the siebel message //alternatively we can set status of the product to some dummy value and we can catch this in Datamap
//iProdCount = psSiebelMessage.GetChild(0).GetChild(0).GetChild(bodynum).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChildCount(); //will get the count of ListOfItem, every ListofItem will have only one product under it//even we can use iProdCount--
iProdCount--;
iInvalid++; //to get the number of invalid items sent
iCount--; //because we are deleting the item
}
}
TheApplication().Utility.logVars("Invalid Count", iInvalid);
if (iInvalid >= 1) {
sErrMessage = sErrMessage + " are invalid Items.'"
if (sErrMessage1 != null) {
sErrMessage = sErrMessage + " Also Object Id '" + sErrMessage1 + "' has null Items."
}
sErrMessage = sErrMessage + " Intotal " + iInvalid + " Out of " + iTotal + "Items are invalid";
sErrCode = "SBL_QSOL_ERR";
}
Outputs.AddChild(psSiebelMessage);
Outputs.SetProperty("ErrorMessage", sErrMessage);
Outputs.SetProperty("ErrorCode", sErrCode);
Outputs.SetProperty("DataMap", sDataMap);
Outputs.SetProperty("qAccountId", qAccountId);
Outputs.SetProperty("qName", qName);
Outputs.SetProperty("qRevision", qRevision);
Outputs.SetProperty("qPrimaryOrganizationId", qPrimaryOrganizationId);
Outputs.SetProperty("qActivityId", qActivityId);
Outputs.SetProperty("qOrderNum", qOrderNum);
Outputs.SetProperty("qId", sObjectId);
Outputs.SetProperty("qItemUserKey", qItemUserKey);
//Outputs.SetProperty("qOrderTypeId", qOrderTypeId);
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sProdExists = null;
sProdName = null;
sProdQty = null;
sErrMessage = null;
sSource = null;
sDataMap = null;
iProdCount = null;
iCount = null;
iTotal = null; //to capture total number of items
iInvalid = null;
BcItem = null;
BoHeader = null;
bodynum = null;
sErrMessage1 = null;
sErrCode = null;
qAccountId = null;
qName = null;
qRevision = null;
qPrimaryOrganizationId = null;
qActivityId = null;
qOrderNum = null;
sObjectId = null;
//qOrderTypeId = null;
BcPick = null;
bcAction = null;
boAction = null;
bcQuote = null;
boQuote = null;
bcOrder = null;
boOrder = null;
qItemUserKey = null;
bc = null;
bo = null;
sBOProduct = null; // Added by ki795 on 7-Feb-2012 for bug # 2192
sSearchProdSpec = null; // Added by ki795 on 7-Feb-2012 for bug # 2192
psSiebelMessage = null; // added by jw920 <Code clean up process > on 19/08/2011
TheApplication().Utility.logUnstack(sErrMessage);
}
}

CMI Quick View BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/***************************************************************************************************************
Created By : KL968
Created On : 11/15/2011
Method Name: CMIGetURL
C&I Number: 5162
Functionality: This BS gets called from Browser script on CMI Quick View BS.
It queries the LOV BC to fetch the EBS Application URL.
****************************************************************************************************************/
try
{
if(MethodName == "CMIGetURL")
{
var oLovBo:BusObject = TheApplication().GetBusObject("List Of Values");
var oLovBC:BusComp = oLovBo.GetBusComp("List Of Values");
with(oLovBC)
{
ActivateField("Description");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Type", "CMI_QUICK_VIEW_URL");
SetSearchSpec("Value", "CMI Quick View URL");
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var sURL:String = GetFieldValue("Description");
Outputs.SetProperty("CMI URL", sURL);
}
}
return(CancelOperation);
}
}
catch(e)
{
throw(e);
}
finally
{
oLovBC = null;
oLovBo = null;
}
return (ContinueOperation);
}

CMI Quote Acceptence Check
QuoteValidation
function QuoteValidation(sQuoteNum)
{
try {
TheApplication().Utility.logStack("QuoteValidation", this);
var oBO = TheApplication().GetBusObject("Quote");
var oBCQuote = oBO.GetBusComp("Quote");
with (oBCQuote) {
SetViewMode(AllView);
ActivateField("Quote Number");
ActivateField("Active");
ActivateField("Status");
ActivateField("Revision");
ClearToQuery();
SetSearchSpec("Quote Number",sQuoteNum);
ExecuteQuery(ForwardBackward);
var isRec = FirstRecord();
TheApplication().Utility.logVars("Quote ("+sQuoteNum+") found?", isRec);
while(isRec) {
var sActive = GetFieldValue("Active")
var sRev = GetFieldValue("Revision");
sStatus = GetFieldValue("Status");
var accepted = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Accepted")
var altQuoteSelected = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Alternative Quote Selected")
var cancelled = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Cancelled")
TheApplication().Utility.logVars("Status", sStatus);
if (sStatus != accepted && sStatus != cancelled) {
TheApplication().Utility.logVars("Active", sActive);
if (sActive == "Y") {
SetFieldValue("CMI Status", altQuoteSelected);
SetFieldValue("Active", "N");
WriteRecord();
}
}
isRec = NextRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCQuote = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Acceptence Check
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs) {
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if (MethodName == "QuoteAcceptanceCheck") {
var oBO = TheApplication().ActiveBusObject();
var oBCQuote = oBO.GetBusComp("Quote");
var sQuoteId = TheApplication().GetProfileAttr("Quote Id");
with (oBCQuote) {
SetViewMode(AllView);
ActivateField("Quote Number");
ActivateField("Status");
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardOnly);
sQuoteNum = oBCQuote.GetFieldValue("Quote Number");
sStatus = oBCQuote.GetFieldValue("Status");
QuoteValidation(sQuoteNum);
}
UpdatePaymentLines(sQuoteId);
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCQuote = null;
oBO = null;
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Quote Acceptence Check
UpdatePaymentLines
function UpdatePaymentLines(sQuoteId)
{
try {
TheApplication().Utility.logStack("UpdatePaymentLines", this);
// var oBO = TheApplication().ActiveBusObject();
var bcPayment = TheApplication().ActiveBusObject().GetBusComp("Payments");
if (sQuoteId != "" && bcPayment != null) {
with (bcPayment) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("Quote Id");
ActivateField("CMI Payments Accept Flag");
ActivateField("Payment Status");
SetSearchSpec("Quote Id", sQuoteId);
// SetSearchSpec("Payment Status", "Approved");
ExecuteQuery(ForwardOnly);
var isRec = FirstRecord();
while (isRec) {
TheApplication().Utility.logVars("Quote Id", sQuoteId);
SetFieldValue("CMI Payments Accept Flag","Y");
WriteRecord();
isRec = NextRecord();
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPayment = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Acceptence Check
(declarations)
var sQuoteNum;
var sStatus;

CMI Quote Approval BS
ApproveItem
/******************************************
Created By : Created by Tiger Luo and migrated by JN705
Created On : May 11, 2011
Method Name: ApproveItem
C&I Number:
Requirement #:
Functionality: This method is used for quote approval process.
Input:
Output:
******************************************/
function ApproveItem()
{
//If the resolution is pending then the quote will be sent
//for approval as an inbox item to the supervisor and customer
// will be notified by email.
//Locate the approver first.
try {
var oBOQuote = TheApplication().ActiveBusObject();
var oBCQuote = oBOQuote.GetBusComp("Quote");
if (oBCQuote == null)
return;
var sQuoteId = oBCQuote.GetFieldValue("Id");
var sQuoteName = oBCQuote.GetFieldValue("Name");
var sPrimPosId = oBCQuote.GetFieldValue("Sales Rep Position Id");
if(sPrimPosId == "")
{
TheApplication().RaiseErrorText("Sales Team can not be blank for approval");
}
var bcPosition = TheApplication().GetBusObject("Position").GetBusComp("Position");
with(bcPosition)
{
ActivateField("Position Type");
ActivateField("Employee Id");
ActivateField("CMI Parent Employee Id");
ClearToQuery();
SetSearchSpec("Id", sPrimPosId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var sPosType = GetFieldValue("Position Type");
if(sPosType == "Service Supervisor")// supervisor does not need approval
with(oBCQuote)
{
SetFieldValue("Status","Price All");//added by Jn705 on May 11 for quote state model.
SetFieldValue("Status","Quote Verification");//added by Jn705 on May 11 for quote state model.
SetFieldValue("Status","Approved");
WriteRecord();
InvokeMethod("RefreshBusComp");
return;
}
// service wirte needs approval
else if(sPosType == "Service Writer")
{
var sParEmpId = GetFieldValue("CMI Parent Employee Id");
//send message to parent
var sPartyId = GetFieldValue("Employee Id");
SentMessage(sPartyId, sParEmpId, sQuoteId, sQuoteName);
with(oBCQuote)
{
SetFieldValue("Status","Price All");//added by Jn705 on May 11 for quote state model.
SetFieldValue("Status","Quote Verification");//added by Jn705 on May 11 for quote state model.
SetFieldValue("Status","Awaiting Approval");
WriteRecord();
InvokeMethod("RefreshBusComp");
return;
}
}
//ignore other roles which are not finalized by business
else
{
TheApplication().RaiseErrorText("Can not Generate Approval if Sales Team is not Service Writer or Service Supervisor");
}
}
}
}
catch(e)
{
throw (e);
}
finally
{
oBCQuote = null;
oBOQuote = null;
//added by shanmukh for code clean up 08/27/2011
bcPosition = null;
}
}

CMI Quote Approval BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//try catch added by shanmukh for code clean up 08/22/2011
try
{
//Created by Jn705 on May 11, 2011 for migrating the applet server script to BS
if (MethodName == "ApproveItem")
{
ApproveItem();
return (CancelOperation);
}
}//end of try
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
} //end of catch
return (ContinueOperation);
}

CMI Quote Approval BS
SentMessage
/******************************************
Created By : Created by Tiger Luo and migrated by JN705
Created On : May 11, 2011
Method Name: ApproveItem
C&I Number:
Requirement #:
Functionality: If the resolution is pending then the quote will be sent
for approval as an inbox item to the supervisor and customer
will be notified by email.
Input: sPartyId, sOwnerId, sQuoteId, sQuoteName
Output:
******************************************/
function SentMessage(sPartyId, sOwnerId, sQuoteId, sQuoteName)
{
try
{
var bs = TheApplication().GetService("Universal Inbox");
var psIn = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();
//check whether the approver item exists or not
//var sQuoteId = this.BusComp().GetFieldValue("Id"); //Commented out by jn705, passing value
psIn.SetProperty("InboxTypeName", "Quote");
psIn.SetProperty("ObjectId",sQuoteId);
bs.InvokeMethod("IsInboxItemExisted",psIn,psOut);
if(psOut.GetProperty("IsInboxItemExisted") == "Y")
{
return;
}
// send message if not exists.
psIn.Reset();
psOut.Reset();
//psIn.SetProperty("InboxName",this.BusComp().GetFieldValue("Name")); //Commented out by Jn705, passing value
psIn.SetProperty("InboxName", sQuoteName);
psIn.SetProperty("InboxPartyId", sPartyId);
psIn.SetProperty("InboxTypeName", "Quote");
psIn.SetProperty("OwnerPartyId", sOwnerId);
psIn.SetProperty("ObjectId",sQuoteId);
bs.InvokeMethod("CreateInboxEx",psIn,psOut);
}
catch(e)
{
throw (e);
}
finally
{
bs=null;
psIn=null;
psOut=null;
}
}

CMI Quote Check
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: JQ487,CMI DBU, Build Quote Repair Functionality(Defect 429)
DESCRIPTION: This Script will be triggered for Predefaulting Product Line
on Quote Template Line item, when ne record is created.
DATE CREATED: 25 Apr 2011
*********************************************************/
try
{
if (MethodName == "QuoteCheck")
{
var oBO = TheApplication().ActiveBusObject();
var oBCQuote = oBO.GetBusComp("CMI Quote Template");
//var sId = oBCQuote.GetFieldValue("Id");
var oBCQuoteItem = oBO.GetBusComp("Quote Item");
var sQuoteId = TheApplication().GetProfileAttr("QuoteId");
with (oBCQuote)
{
SetViewMode(AllView);
ActivateField("CMI Product Line");
ActivateField("CMI Fail Vendor");
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardBackward);
var isRec = FirstRecord()
if(isRec)
{
var sProdId = GetFieldValue("CMI Product Line");
var sBU = GetFieldValue("CMI Fail Vendor");
with (oBCQuoteItem)
{
SetViewMode(AllView);
ActivateField("CMI Product Line");
ActivateField("CMI Vendor");
ClearToQuery();
SetSearchSpec("Quote Id",sQuoteId);
ExecuteQuery(ForwardBackward);
var isRec1 = FirstRecord()
while (isRec1)
{
var sProd = GetFieldValue("CMI Product Line");
if((sProd == null)||(sProd == ""))
{
SetFieldValue("CMI Product Line", sProdId);
SetFieldValue("CMI Vendor", sBU);
WriteRecord();
}
isRec1 = NextRecord();
}//end While
}//end with
}//end if
}//end with
return(CancelOperation);
}//end if
}//end try
catch(e)
{
throw(e);
}
finally
{
oBCQuoteItem = null;
oBCQuote = null;
oBO = null;
}
}

CMI Quote Creation BS
(declarations)
var sTemplateName;
var sQuoteId;//Added by jr429 on 12/28/2010

CMI Quote Creation BS
CreateActivityPlan
/*******************************************************************************************
Created By :< Dinesh Thirukonda>
Created On : <12/20/2010>
Method Name:CreateActivityPlan(sTemplateName,sQuoteId)
C&I Number:
Requirement #:
Functionality: Creat Activity plan//Modified for code clean up and to solve refresh issues while creating Quote.
Changed the logic from ActiveBugObject to new BO instanse. by ki795
Input:
Output:
****************************************************************************************** */
function CreateActivityPlan(sTemplateName,sQuoteId,sQuoteSRId) {
try {
TheApplication().Utility.logStack("CreateActivityPlan", this);
TheApplication().Utility.logVars("Template", sTemplateName);
var boSR:BusObject = TheApplication().GetBusObject("Service Request");
var bcSR:BusComp = boSR.GetBusComp("Service Request");
var bcActivityPlan:BusComp = boSR.GetBusComp("Activity Plan");
var bcActivityPlanAction:BusComp = boSR.GetBusComp("Activity Plan Action");
var bcTemplate:BusComp;
var isRecord = false;
var templateFound = false;
var sPriority = "";
var sCurrency = "";
var parentFound = false;
var activityCreated = false;
//If the Quote is a child of an SR, instantiate it to get SR fields that will need to be set on
//Service Labor and Parts Tracker activities. Create the activity plan as a child of the SR
if (sQuoteSRId != "") {
with (bcSR) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("Priority");
ActivateField("CMI SR Local Currency");
SetSearchSpec("Id",sQuoteSRId);
ExecuteQuery(ForwardOnly)
parentFound = FirstRecord();
TheApplication().Utility.logVars("Service Request ("+sQuoteSRId+") found?", parentFound);
if (parentFound) {
sPriority = GetFieldValue("Priority");
sCurrency = GetFieldValue("CMI SR Local Currency");
}
}
}
//Create the Activity Plan, then once child activities are created, loop through them to update fields
if (parentFound) {
var SRChanged = TheApplication().GetProfileAttr("CMISetSRQuoteId");
TheApplication().Utility.logVars("SR Changed?", SRChanged);
if (SRChanged == sQuoteId) {
//If the SR is changed on the quote, this updates a profile attribute to store the current Quote Id
//When changed, first query to see if the activity has been created and if not create new. If Created,
//reassociate to the new SR
var boAction:BusObject = TheApplication().GetBusObject("Action");
var bcAction:BusComp = boAction.GetBusComp("Action (Quote Order)");
var typeSvcLabor = TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Service Labor")
var typePtTrack = TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker")
with(bcAction) {
SetViewMode(AllView);
ActivateField("Activity SR Id");
ClearToQuery();
SetSearchSpec("Quote Id", sQuoteId);
if (sTemplateName=="Part Tracker Template") {
SetSearchSpec("Type", typePtTrack);
} else {
SetSearchSpec("Type", typeSvcLabor);
}
ExecuteQuery(ForwardOnly);
activityCreated = FirstRecord();
if(activityCreated) {
TheApplication().Utility.logStep("Activity moved from SR "+GetFieldValue("Activity SR Id")+" to "+sQuoteSRId);
SetFieldValue("Activity SR Id", sQuoteSRId);
WriteRecord();
}
}
}
//If activity has not been created already, create one via activity template
TheApplication().Utility.logVars("Activity Created?", activityCreated);
if (!activityCreated) {
with(bcActivityPlan) {
NewRecord(NewAfter);
bcTemplate = bcActivityPlan.GetPicklistBusComp("Template");
with(bcTemplate) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Name",sTemplateName);
ExecuteQuery(ForwardOnly);
templateFound = FirstRecord();
if(templateFound) {
Pick();
}
}
WriteRecord();
}
with(bcActivityPlanAction) {
SetViewMode(AllView);
ActivateField("CMI Quote Id");
ActivateField("CMI Rate List Id");
ActivateField("Currency Code");
ActivateField("Priority");
ClearToQuery();
ExecuteQuery(ForwardOnly);
isRecord = FirstRecord();
if(isRecord) {
SetFieldValue("CMI Quote Id", sQuoteId);
SetFieldValue("Planned", "");
if (sTemplateName=="Part Tracker Template") {
SetFieldValue("Primary Owner Id",TheApplication().LoginId());
// SetFieldValue("Primary Owner Id",TheApplication().LoginId());
} else {
//MJB 1/2/12 Commented for performance. Display Owner defaults to null
// SetFieldValue("CMI Owner FullName", "");
// SetFieldValue("Primary Owner Id","");
SetFieldValue("Priority",sPriority);
}
SetFieldValue("Currency Code", sCurrency); //KK: 5/23/12: CQ# 7346
WriteRecord();
}
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcTemplate = null;
bcActivityPlanAction = null;
bcActivityPlan = null;
bcAction = null;
boAction = null;
bcSR = null;
boSR = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Creation BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
switch(MethodName) {
case "CreateActivityPlan":
sQuoteId = TheApplication().GetProfileAttr("QuoteId");
sTemplateName = Inputs.GetProperty("Context");
var boQuote:BusObject = TheApplication().GetBusObject("CMI Quote");
var bcQuote:BusComp = boQuote.GetBusComp("CMI Quote Simple");
var boActive:BusObject = TheApplication().ActiveBusObject();
var bcActive:BusComp = boActive.GetBusComp("Quote");
var sQuoteSRId:String;
TheApplication().Utility.logVars("Active Quote ("+sQuoteId+")?", bcActive.FirstSelected());
if (bcActive.FirstSelected()) {
sQuoteSRId = bcActive.GetFieldValue("Service Request Id");
} else {
with(bcQuote) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardBackward);
if(FirstRecord()) {
sQuoteSRId = GetFieldValue("Service Request Id");
}
}
}
CreateActivityPlan(sTemplateName,sQuoteId,sQuoteSRId);
}//end method switch
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
bcQuote = null;
boQuote = null;
bcActive = null;
boActive = null;
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Quote Credit Check Service
(declarations)
//r OrderCreditCheckNeeded = "Y";
//var QuoteCreditCheckNeeded = "Y";
var aActiveBO = "";
var aActiveBC = "";
var aField = "";
var CreditToBeValidated = 0;
var CreditValidated = 0;
var QuoteTotal = 0;
var payMethodPO = TheApplication().InvokeMethod("LookupValue","PAYMENT_METHOD_CODE","Purchase Order");
var payMethodCash = TheApplication().InvokeMethod("LookupValue","PAYMENT_METHOD_CODE","Cash");
var row_id;
var OrderPaymentId = ""; //this will hold the Payment Id at the Order
var bcQuote;
var bcPayment;
var sQuoteDisplay;
var BillToSite;
var aQuotePaymentMethod;
var sCreditCheck;
var sRelatedSRId; //CMI DBU Release#1, Defect#5151, Script : Declared a new variable to hold the value of SR Id By KL968 On 02/08/2011
//var aActiveBusComp;
//var aActiveBusObject;
// aActiveBusObject = TheApplication().ActiveBusObject();
// aActiveBusComp = aActiveBusObject.GetBusComp(aActiveBC);

CMI Quote Credit Check Service
CallCreditCheckOrderInterface
function CallCreditCheckOrderInterface(row_id,OrderPaymentId)
{
// Added/Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
TheApplication().Utility.logStack("CallCreditCheckOrderInterface", this);
// Function to Call Credit Check OOTB interface
var tempBS = TheApplication().GetService("Workflow Process Manager");
var tempInput = TheApplication().NewPropertySet();
var tempOutput = TheApplication().NewPropertySet();
// tempInput.SetProperty("RowId",paymentId);
tempInput.SetProperty("RowId",OrderPaymentId);
tempInput.SetProperty("ProcessName","SWISendCreditCheck");
tempBS.InvokeMethod("RunProcess",tempInput,tempOutput);
var bcOrderHold = TheApplication().ActiveBusObject().GetBusComp("PDS Simplified Order");
var hold_flg = "N"
with (bcOrderHold)
{
ActivateField("Hold Flag");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Id",row_id);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
hold_flg = GetFieldValue("Hold Flag");
}
}
if (hold_flg == "Y")
{
//raise a soft warning to user.
}
}
catch(e)
{
//TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
TheApplication().Utility.RaiseError(e);
}
finally
{
tempBS = null;
tempInput = null;
tempOutput = null;
bcOrderHold = null;
hold_flg = null;
TheApplication().Utility.logUnstack();
}
//<End>
}

CMI Quote Credit Check Service
ChangeStatusToVerification
function ChangeStatusToVerification(Inputs, Outputs)
{
// Added/Modified By <jr419> for <try catch block code review> on <24/05/2011>
//<Begin>
try
{
TheApplication().Utility.logStack("ChangeStatusToVerification", this);
row_id = Inputs.GetProperty("Object Id");
bcPayment = TheApplication().GetBusObject("Quote").GetBusComp("Payments");
with(bcPayment) {
ActivateField("Id");
ActivateField("Base Quote Id");
ActivateField("Quote Id");
ActivateField("Payment Method");
ActivateField("Payment Term");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Base Quote Id",row_id);
//SetSearchSpec("Payment Method",payMethodPO);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Payment Found?", FirstRecord());
if(FirstRecord()) {
var sPay = GetFieldValue("Payment Method"); //JQ487: added for fixing defect 657
var NodoPaymentTerm = TheApplication().InvokeMethod("LookupValue","CMI_CREDIT_ABOUT","NoCreditTerm");
var tempPaymentTerm = GetFieldValue("Payment Term");
//MJB 7/17/12 cq 7612 Call credit check regardless of Payment method
// if(sPay == payMethodPO) {
TheApplication().Utility.logVars("Payment Terms", tempPaymentTerm);
if(tempPaymentTerm != NodoPaymentTerm) {
var paymentId = GetFieldValue("Id");
var tempBS = TheApplication().GetService("Workflow Process Manager");
var tempInput = TheApplication().NewPropertySet();
var tempOutput = TheApplication().NewPropertySet();
tempInput.SetProperty("RowId",row_id);
tempInput.SetProperty("FromSingal","N");
tempInput.SetProperty("Payment #",paymentId);
tempInput.SetProperty("ProcessName","CMISendQuoteCreditCheck");
tempBS.InvokeMethod("RunProcess",tempInput,tempOutput);
var tempBS2 = TheApplication().GetService("Workflow Process Manager");
var tempAfterInput = TheApplication().NewPropertySet();
var tempAfterOutput = TheApplication().NewPropertySet();
tempAfterInput.SetProperty("RowId",paymentId);
tempAfterInput.SetProperty("RefreshSkip","Yes"); //Added by ki795 for Internal Bug # 40 on 21-Sep-2011
tempAfterInput.SetProperty("ProcessName","CMI Credit Check After Flow Process Payment WF");
tempBS2.InvokeMethod("RunProcess",tempAfterInput,tempAfterOutput);
var RaiseBS = TheApplication().GetService("CMI DBU Raise Error BS");
var RaiseInput = TheApplication().NewPropertySet();
var RaiseOutput = TheApplication().NewPropertySet();
RaiseInput.SetProperty("row_id",row_id);//Added by ki795 for Internal Bug # 40 on 21-Sep-2011
RaiseBS.InvokeMethod("CallByCreditCheckSingle",RaiseInput,RaiseOutput);
//Nag; 1/17/2013; Added for CQ# 8645.
TheApplication().Utility.logVars("Error Code", RaiseOutput.GetProperty("Error Code"));
TheApplication().Utility.logVars("Error Message", RaiseOutput.GetProperty("Error Message"));
Outputs.SetProperty("Error Code", RaiseOutput.GetProperty("Error Code"));
Outputs.SetProperty("Error Message", RaiseOutput.GetProperty("Error Message"));
}
// } else {//end if(sPay == payMethodPO)
//If payment method is cash, call the Approval process
TheApplication().Utility.logVars("Payment Method", sPay);
if(sPay == payMethodCash) {
var tempBS1 = TheApplication().GetService("Workflow Process Manager");
var tempInput1 = TheApplication().NewPropertySet();
var tempOutput1 = TheApplication().NewPropertySet();
tempInput1.SetProperty("Object Id",row_id);
tempInput1.SetProperty("ProcessName","CMI ISS Approval Quote");
tempBS1.InvokeMethod("RunProcess",tempInput1,tempOutput1);
}//end if(sPay == payMethodPO)
// }//end else
}
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
tempBS = null;
bcPayment = null;
NodoPaymentTerm = null;
tempPaymentTerm = null;
tempPaymentTerm = null;
tempInput = null;
tempOutput = null;
tempBS2 = null;
tempInput1 = null;
tempOutput1 = null;
tempBS1 = null;
tempAfterInput = null;
tempAfterOutput = null;
RaiseBS = null;
RaiseInput = null;
RaiseOutput = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Credit Check Service
CheckFulfillmentSetPair
function CheckFulfillmentSetPair()
{
try
{
TheApplication().Utility.logStack("ValidateQuoteOrder", this);
var oQuoteBO = TheApplication().GetBusObject("Quote");
var oQuoteBC = oQuoteBO.GetBusComp("Quote");
var oQuoteItemBC = oQuoteBO.GetBusComp("Quote Item (Simple)");
var oQuoteItemFreightBC = oQuoteBO.GetBusComp("Quote Item (No Hierarchy)");
var sSearchExpr = "";
var isFreightValid = "";
var i =0;
var j = 0;
var sFulfillmentSetId;
with (oQuoteBC)
{
sSearchExpr = "[Id] = '" + row_id + "'";
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr (sSearchExpr);
ExecuteQuery (ForwardOnly);
if (FirstRecord())
{
with (oQuoteItemBC)
{
sSearchExpr = "[Quote Id] = '" + row_id + "' AND [Product Type] = 'Misc' AND [CMI Line Type] = 'Bill Only'";
ClearToQuery();
ActivateField("Product Type");
ActivateField("CMI Line Type");
ActivateField("CMI Fulfillment Set Id");
SetSearchExpr(sSearchExpr);
ExecuteQuery (ForwardOnly);
var isRecord = FirstRecord();
while (isRecord)
{
j = j + 1;
sFulfillmentSetId = GetFieldValue("CMI Fulfillment Set Id");
//var oBCPick = GetPicklistBusComp("CMI Fulfillment Set");
with (oQuoteItemFreightBC)
{
sSearchExpr = "[CMI Fulfillment Set Id] = '" + sFulfillmentSetId + "' AND [Product Type] <> 'Misc'";
ClearToQuery();
// ActivateField("CMI Product Sub Type");
// ActivateField("CMI Line Type");
SetSearchExpr(sSearchExpr);
ExecuteQuery (ForwardBackward);
if (FirstRecord())
{
i = i+1;
}
}
//oBCPick = "";
isRecord = NextRecord();
}
}
}
} // oQuoteBC
} //end try
catch (e)
{
TheApplication().Utility.RaiseError(e);
//TheApplication().RaiseErrorText(e.toString());
}
finally
{
oQuoteItemBC = null;
oQuoteItemFreightBC = null;
oQuoteBC = null;
oQuoteBO = null;
TheApplication().Utility.logUnstack();
if (j == i)
isFreightValid = "Y";
return (isFreightValid);
}
}

CMI Quote Credit Check Service
CheckOneOffItem
function CheckOneOffItem(Inputs, Outputs)
{
try{
TheApplication().Utility.logStack("CheckOneOffItem", this);
var tBO = TheApplication().GetBusObject("PDS Simplified Quote");
var tQuoteItem = tBO.GetBusComp("PDS Simplified Quote Item");
var QuoteId = Inputs.GetProperty("RowId");
var raiseErrorFlag = "N";
var FailedProdsNotsend = "";
var FailedProdsNotsync = "";
var PickBC;
var WriteInName;
var WriteInStatus;
with(tQuoteItem)
{
InvokeMethod("SetAdminMode", "TRUE");
ActivateField("Id");
ActivateField("Quote Id");
ActivateField("CMI Write-In Status Code");
/*==================below added by jr418=================*/
/*===================Date: Apr 08, 2011==================*/
/*=====Purpose: Change Write-In product name ============*/
ActivateField("Write-In Product");
ActivateField("CMI Write In Description");
ActivateField("CMI Write-In Message");
ActivateField("CMI Write-In Product Type");
ActivateField("Product");
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr("[Quote Id] = '"+QuoteId+"' AND ([Part Number] = 'SEBLRSVWIP1' OR [Part Number] = 'SEBLRSVLP1')");
ExecuteQuery(ForwardOnly);
var isRecord = FirstRecord();
while(isRecord)
{
WriteInName = GetFieldValue("Write-In Product");
WriteInStatus = GetFieldValue("CMI Write-In Status Code");
if (WriteInStatus =="SUCCESS")
{
PickBC = GetPicklistBusComp("Product");
with(PickBC)
{
InvokeMethod("SetAdminMode", "TRUE");
ActivateField("Name");
ClearToQuery();
SetSearchSpec("Product Name", WriteInName);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
Pick();
tQuoteItem.SetFieldValue("CMI Write In Description", "");
tQuoteItem.SetFieldValue("CMI Write-In Status Code", "");
tQuoteItem.SetFieldValue("CMI Write-In Message", "");
tQuoteItem.SetFieldValue("CMI Write-In Product Type", "");
tQuoteItem.SetFieldValue("Write-In Product", "");
tQuoteItem.WriteRecord();
}
else
{
raiseErrorFlag = "Y";
FailedProdsNotsync = WriteInName + "," + FailedProdsNotsync;
}
}
}
else
{
raiseErrorFlag = "Y";
FailedProdsNotsend = WriteInName + "," + FailedProdsNotsend;
}
PickBC = null;
isRecord = NextRecord();
}//end of while(isRecord)
}//end of with(tQuoteItem)
if (raiseErrorFlag == "Y")
{
if(FailedProdsNotsend != "" && FailedProdsNotsync == "")
{
TheApplication().RaiseError("CMI One Off Error Message1", FailedProdsNotsend);
}
if(FailedProdsNotsend != "" && FailedProdsNotsync != "")
{
TheApplication().RaiseError("CMI One Off Error Message3", FailedProdsNotsend, FailedProdsNotsync);
}
if(FailedProdsNotsend == "" && FailedProdsNotsync != "")
{
TheApplication().RaiseError("CMI One Off Error Message2", FailedProdsNotsync);
}
}
/*===========above added by jr418===========*/
}//end of try
catch(e){
//throw e;
TheApplication().Utility.RaiseError(e);
}
finally{
tQuoteItem = null;
tBO = null;
QuoteId = null;
QuoteId = null;
raiseErrorFlag = null;
FailedProdsNotsend = null;
FailedProdsNotsync = null;
PickBC=null;
WriteInName=null;
WriteInStatus=null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Credit Check Service
CreditCheckOrder
function CreditCheckOrder(Inputs,Outputs)
{
// Function to Call credit check after performing the validations related to Quote its created from
try
{
TheApplication().Utility.logStack("CreditCheckOrder", this);
row_id = Inputs.GetProperty("RowId");
var inPS = TheApplication().NewPropertySet();
var outPS = TheApplication().NewPropertySet();
inPS.SetProperty("Id","");
inPS.SetProperty("Quote Id","");
inPS.SetProperty("Order Total","");
inPS.SetProperty("CMI Payment Method","");
inPS.SetProperty("CMI Bill To Profile Id","");
TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetMultipleFieldValues(inPS,outPS);
if(row_id =="")
row_id = outPS.GetProperty("Id"); //TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetFieldValue("Id");
var Order_QuoteId = outPS.GetProperty("Quote Id"); //TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetFieldValue("Quote Id");
var Order_TotalAmt = outPS.GetProperty("Order Total"); //TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetFieldValue("Order Total");
var aPaymentMethod = outPS.GetProperty("CMI Payment Method"); //TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetFieldValue("CMI Payment Method");
//OrderCreditCheckNeeded = "Y";
if (outPS.GetProperty("CMI Bill To Profile Id") == "")
TheApplication().RaiseError("CMI Credit Check Bill To");
// TheApplication().RaiseErrorText("Bill To Site is a Required Field");
var PaymentLineAmt = 0;
var CreditValidated = 0;
var CreditToBeValidated = 0;
TheApplication().SetProfileAttr("CMIOrderCreditCheck","N");
if (Order_TotalAmt != 0 && aPaymentMethod == payMethodPO)
{
//get the Order Payment Details
//Assumin there will be only one Order (no Revisions exists)
/*if there can be more than one revision, then Set Search spec to Order Id instead on Base Order Id and
use while loop to parse through all Purchase Order Payment Lines. Inside While loop get the Base Order Id,
when base order id = order id, the payment line is created for the current order, and rest all are for previous
versions, sum up the payment lines of previous versions and reduce the amount from Order_TotalAmt (this is the
total amount to be validated at this Order)
*/
bcPayment = TheApplication().ActiveBusObject().GetBusComp("Payments");
with (bcPayment)
{
ActivateField("Base Order Id");
ActivateField("Order Id");
ActivateField("Transaction Amount");
ActivateField("Payment Method");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Order Id",row_id);
ExecuteQuery(ForwardOnly);
var RecordExists;
var BaseOrderId;
var aPaymentStatus;
var aPaymentStatusApp = TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Approved");
if (FirstRecord())
{
RecordExists = FirstRecord();
while (RecordExists)
{
var inPayPS = TheApplication().NewPropertySet();
var outPayPS = TheApplication().NewPropertySet();
inPayPS.SetProperty("Id","");
inPayPS.SetProperty("Transaction Amount","");
inPayPS.SetProperty("Base Order Id","");
inPayPS.SetProperty("Payment Status","");
GetMultipleFieldValues(inPayPS,outPayPS); //only single hit to DB.
PaymentLineAmt = outPayPS.GetProperty("Transaction Amount"); //GetFieldValue("Transaction Amount");
OrderPaymentId = outPayPS.GetProperty("Id"); //GetFieldValue("Id");
BaseOrderId = outPayPS.GetProperty("Base Order Id");
aPaymentStatus = outPayPS.GetProperty("Payment Status");
if (BaseOrderId == row_id)
CreditToBeValidated = ToNumber(CreditToBeValidated) + ToNumber(PaymentLineAmt);
else
if (aPaymentStatusApp == aPaymentStatus)
CreditValidated = ToNumber(CreditValidated) + ToNumber(PaymentLineAmt);
RecordExists = NextRecord();
}
}
else
{
ClearToQuery();
ExecuteQuery(ForwardOnly);
TheApplication().SetProfileAttr("CMIOrderCreditCheck","N");
TheApplication().RaiseError("CMI Credit Check - No Payment");
}
}
// CreditValidated -- Quotes Payment Line's total amount
// Order_TotalAmt -- Order Amount
// CreditToBeValidated --
var ActualCreditToBeValidated = ToNumber(Order_TotalAmt) - ToNumber(CreditValidated);
//Below added by jr418 on May 27,2011 to fix numberic error
var ActualCreditToBeValidated2 = ActualCreditToBeValidated.toFixed(2);
if (ActualCreditToBeValidated2 > 0)
{
//Below added by jr418 on May 27,2011 to fix numberic error
var CreditToBeValidated2 = CreditToBeValidated.toFixed(2);
if (CreditToBeValidated2 <= ActualCreditToBeValidated2)
{
if (CreditToBeValidated2 == 0) //no payment line created or payment amount = 0
TheApplication().RaiseError("CMI Credit Check - No Payment");
if (ActualCreditToBeValidated2 != CreditToBeValidated2)
TheApplication().RaiseError("CMI Credit Check - Order Quote",CreditValidated,ActualCreditToBeValidated2);
else
TheApplication().SetProfileAttr("CMIOrderCreditCheck","Y");
}
else
{
TheApplication().RaiseErrorText("Credit Check is Already done for " + CreditValidated + " Credit Check is needed only for: "+ ActualCreditToBeValidated2 );
}
}
}
TheApplication().SetProfileAttr("CMIOrderCreditCheckPayment",OrderPaymentId);
}
catch(e)
{
//throw e;
TheApplication().Utility.RaiseError(e);
}
finally
{
bcPayment = null;
inPS=null;
outPS= null;
inPayPS = null;
outPayPS = null;
PaymentLineAmt = null;
aPaymentMethod = null;
Order_TotalAmt = null;
Order_QuoteId = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Credit Check Service
DeletePaymentLines
function DeletePaymentLines(Inputs, Outputs)
{
//Esnure that the RTE calling this is having a conditional expression that the [Payment Method] is not null, this will ensure
//that we are not calling this script when there are no payment lines. Reason: Payment Method is OOTB Column which is join from child payment line
try
{
TheApplication().Utility.logStack("DeletePaymentLines", this);
row_id = Inputs.GetProperty("RowId");
aActiveBO = TheApplication().ActiveBusObject().Name();
aActiveBC = "";
aField = "";
bcPayment = TheApplication().ActiveBusObject().GetBusComp("Payments");
switch (aActiveBO)
{
case "Order Entry (Sales)":
aActiveBC = "Order Entry - Orders";
aField = "Order Id"
break;
case "Quote":
aActiveBC = "Quote";
aField = "Quote Id";
break;
}
if(row_id =="")
row_id = TheApplication().ActiveBusObject().GetBusComp(aActiveBC).GetFieldValue("Id");
with (bcPayment)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec(aField,row_id);
ExecuteQuery(ForwardOnly);
while (FirstRecord())
{
DeleteRecord();
NextSelected();
}
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
bcPayment = null;
aActiveBC = null;
aActiveBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Credit Check Service
GetPaymentId
function GetPaymentId(Inputs,Outputs)
{
try
{
TheApplication().Utility.logStack("GetPaymentId", this);
var sQuoteId = Inputs.GetProperty("Object Id");
bcPayment = TheApplication().GetBusObject("Quote").GetBusComp("Payments");
TheApplication().Utility.logVars("QuoteId", sQuoteId)
with(bcPayment) {
ActivateField("Base Quote Id");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Base Quote Id",sQuoteId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Payment Found?", FirstRecord());
if(FirstRecord())
{
var paymentId = GetFieldValue("Id");
TheApplication().Utility.logVars("Payment Id", paymentId)
Outputs.SetProperty("Payment Id", paymentId);
}
}
}
catch(e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
bcPayment = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Credit Check Service
OrderCreditCheck
function OrderCreditCheck(Inputs, Outputs)
{
try
{
TheApplication().Utility.logStack("OrderCreditCheck", this);
row_id = Inputs.GetProperty("RowId");
if(row_id =="")
row_id = TheApplication().ActiveBusObject().GetBusComp("Quote").GetFieldValue("Id");
var tempBS = TheApplication().GetService("Workflow Process Manager");
var tempInput = TheApplication().NewPropertySet();
var tempOutput = TheApplication().NewPropertySet();
tempInput.SetProperty("RowId",TheApplication().GetProfileAttr("CMIOrderCreditCheckPayment"));
tempInput.SetProperty("ProcessName","SWISendCreditCheck");
tempBS.InvokeMethod("RunProcess",tempInput,tempOutput);
var aOrderHoldFlag = TheApplication().ActiveBusObject().GetBusComp("Order Entry - Orders").GetFieldValue("Hold Flag");
if (aOrderHoldFlag == "Y")
TheApplication().RaiseError("CMI Credit Check - Fail");
}
catch (e)
{
//throw e;
TheApplication().Utility.RaiseError(e);
}
finally
{
tempOutput = null;
tempInput = null;
tempBS = null;
//Added by shanmukh for code clean up 08/26/2011
aOrderHoldFlag = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Credit Check Service
QuoteCreditToBeValidated
function QuoteCreditToBeValidated()
{
try
{
TheApplication().Utility.logStack("QuoteCreditToBeValidated", this);
var oQuoteBO = null;
var oSRBC = null;
if (sQuoteDisplay != TheApplication().InvokeMethod("LookupValue","QUOTE_TYPE","Wholegoods Quote")) {
bcPayment = TheApplication().GetBusObject("Quote").GetBusComp("Payments");
var approved = TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Approved");
var authorized = TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Authorized");
var aBaseQuoteId = "";
var newPaymentFound = false;
var oldPaymentFound = false;
var paymentFound = false;
with (bcPayment) {
ActivateField("Payment Method");
ActivateField("Payment Status");
ActivateField("Quote Id");
ActivateField("Base Quote Id");
ActivateField("Transaction Amount");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Quote Id",row_id);
ExecuteQuery(ForwardOnly);
var RecordExists = FirstRecord();
TheApplication().Utility.logVars("Payment Exists", RecordExists);
while (RecordExists) {
paymentFound = true;
aBaseQuoteId = GetFieldValue("Base Quote Id");
TheApplication().Utility.logVars("Base Quote Id", aBaseQuoteId);
if (aBaseQuoteId == row_id) {
newPaymentFound = true;
CreditToBeValidated = ToNumber(CreditToBeValidated) + ToNumber(GetFieldValue("Transaction Amount"));
TheApplication().Utility.logVars("Credit To Be Validated", CreditToBeValidated);
} else {
oldPaymentFound = true;
CreditValidated = ToNumber(CreditValidated) + ToNumber(GetFieldValue("Transaction Amount"));
TheApplication().Utility.logVars("Credit Validated", CreditValidated);
}
RecordExists = NextRecord();
}
}
var balanceRemaining = QuoteTotal - CreditValidated;
var balanceRemaining2 = balanceRemaining.toFixed(2);
var CreditToBeValidated2 = CreditToBeValidated.toFixed(2);
var CreditCheckDiff = CreditToBeValidated2 - balanceRemaining2;
TheApplication().Utility.logVars("Balance Remaining", balanceRemaining2, "Credit To Be Validated", CreditToBeValidated2);
if (CreditToBeValidated2 != 0 && balanceRemaining2 > 0) {
switch (balanceRemaining2/CreditToBeValidated2) {
case 1:
sCreditCheck = "Yes";
break;
default:
TheApplication().Utility.logVars("Credit Check Diff", CreditCheckDiff);
if (balanceRemaining <= 0)
sCreditCheck = "ByPass";
else if (CreditCheckDiff < 0) {
sCreditCheck = "No";
//UpdateQuoteError(row_id, "Price All");
TheApplication().RaiseError("CMI Credit Check - Transaction Amount",CreditToBeValidated2,balanceRemaining2);
} else {
sCreditCheck = "No";
//UpdateQuoteError(row_id, "Price All");
TheApplication().RaiseError("CMI Credit Check - Transaction Amount",CreditToBeValidated2,balanceRemaining2);
}
break;
}
} else if (balanceRemaining2 > 0) { //CreditToBeValidated2 = 0: No new Payments or 0 value new payments with >0 Quote Total
sCreditCheck = "Yes";
TheApplication().Utility.logVars("New Payment Found (0 Payment)", newPaymentFound);
if (newPaymentFound == true) {
//UpdateQuoteError(row_id, "Price All");
TheApplication().RaiseError("CMI Credit Check - Zero Transaction", balanceRemaining2 );
} else {
ValidatePayments(sRelatedSRId);
}
} else {//Negative or 0 Balance
//KK: 6/20/12 CQ# 7612
TheApplication().Utility.logVars("New Payment Found (QT<=0)", newPaymentFound);
if ((newPaymentFound == false) && (sQuoteDisplay == TheApplication().InvokeMethod("LookupValue","QUOTE_TYPE","Service Quote"))) {
TheApplication().Utility.logVars("Old Payment Found", oldPaymentFound, "Credit Check Diff", CreditCheckDiff);
if (oldPaymentFound==true && (CreditCheckDiff == 0 || balanceRemaining2 <= 0)) {
//Because there are old payments, this is a revision. Skip CC and pay line requirement
//if the revision is <= the original
sCreditCheck = "ByPass";
} else {
sCreditCheck = "Yes";
ValidatePayments(sRelatedSRId);
}
} else if (sQuoteDisplay == TheApplication().InvokeMethod("LookupValue","QUOTE_TYPE","Service Quote")) {
sCreditCheck = "Yes";
} else {
sCreditCheck = "ByPass";
}
}
}
TheApplication().Utility.logVars("sCreditCheck", sCreditCheck);
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
RecordExists = null;
bcPayment = null;
oSRBC = null;
oQuoteBO = null;
TheApplication().Utility.logUnstack(sCreditCheck);
}
}

CMI Quote Credit Check Service
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
try {
var retVal = CancelOperation;
switch(MethodName) {
case "ValidateQuote":
ValidateQuote(Inputs, Outputs);
break;
case "ValidateOrder":
CreditCheckOrder(Inputs, Outputs);
break;
case "ChangeStatusToVerification":
ChangeStatusToVerification(Inputs, Outputs);
break;
case "CheckOneOffItem":
CheckOneOffItem(Inputs, Outputs);
break;
case "DeletePaymentLines":
DeletePaymentLines(Inputs, Outputs);
break;
case "CreditCheckOrder":
OrderCreditCheck(Inputs, Outputs);
break;
case "GetPayment":
GetPaymentId(Inputs, Outputs);
break;
}
/* if(MethodName=="ChangeStatusToVerification"){
ChangeStatusToVerification(Inputs, Outputs);
return (CancelOperation);
}
if(MethodName = "CheckOneOffItem"){
CheckOneOffItem(Inputs, Outputs);
return (CancelOperation);
}
*/
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Quote Credit Check Service
UpdateQuoteError
function UpdateQuoteError(row_id, sStatus)
{
try
{
TheApplication().Utility.logStack("UpdateQuoteError", this);
var oQuoteBO:BusObject = TheApplication().GetBusObject("Quote");
var oQuoteBC:BusComp = oQuoteBO.GetBusComp("Quote");
var bFound = false;
with (oQuoteBC)
{
ActivateField("CMI Status");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",row_id);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
bFound = true;
TheApplication().Utility.logVars("Quote Found for Update", bFound);
SetFieldValue("CMI Status", sStatus);
WriteRecord();
}
}
//Nag; 01/17/2013; Commented for CQ# 8645.
//var oRefreshbusService = TheApplication().GetService("FINS Teller UI Navigation");
//var pInputs = TheApplication().NewPropertySet();
//var pOutputs = TheApplication().NewPropertySet();
//pInputs.SetProperty("Refresh All","Y");
//oRefreshbusService.InvokeMethod("RefreshCurrentApplet",pInputs,pOutputs);
}
catch (e)
{
//throw e;
TheApplication().Utility.RaiseError(e);
}
finally
{
//pInputs = null;
//pOutputs = null;
//oRefreshbusService = null;
oQuoteBC = null;
oQuoteBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Credit Check Service
ValidatePayments
function ValidatePayments(sRelatedSRId)
{
try {
TheApplication().Utility.logStack("ValidatePayments", this);
//Defect#5151: Payment Line doesnt remain mandatory when
//SR Sub-Type is "Respec" or Category is "Remanufacturer" By KL968 On 02/08/2011
var boQuote:BusObject = TheApplication().GetBusObject("Quote");
var bcSR:BusComp = boQuote.GetBusComp("Service Request");
with(bcSR) {
ActivateField("CMI Sub Type Category");
ActivateField("Sub Type");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("SR Id", sRelatedSRId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
var respec = TheApplication().InvokeMethod("LookupValue","FINS_SRV_COMPLAINTS","Respec");
var remanufacture = TheApplication().InvokeMethod("LookupValue","CMI_SR_SUB_TYPE_CATEGORY","Remanufacture");
TheApplication().Utility.logVars("Sub Type Category", GetFieldValue("CMI Sub Type Category"), "Sub Type", GetFieldValue("Sub Type"));
if(GetFieldValue("CMI Sub Type Category") != remanufacture || GetFieldValue("Sub Type") != respec) {
//UpdateQuoteError(row_id, "Price All");
TheApplication().RaiseError("CMI Credit Check - No Payment");
}
}
}
} catch (e) {
TheApplication().Utility.RaiseError(e);
} finally {
bcSR = null;
boQuote = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Credit Check Service
ValidateQuote
function ValidateQuote(Inputs,Outputs)
{
try {
TheApplication().Utility.logStack("ValidateQuote", this);
row_id = Inputs.GetProperty("Object Id");
QuoteTotal = Inputs.GetProperty("Quote Total");
aQuotePaymentMethod = Inputs.GetProperty("CMI Payment Method");
BillToSite = Inputs.GetProperty("CMI Bill To Profile Id");
sQuoteDisplay = Inputs.GetProperty("Quote Display Type");
sRelatedSRId = Inputs.GetProperty("CMI Related SR Id"); //CMI DBU Release#1, Defect#5151, Script : Declared a new variable to hold the value of SR Id By KL968 On 02/08/2011
TheApplication().Utility.logVars("Bill To Site", BillToSite);
if (BillToSite == "")
TheApplication().RaiseError("CMI Credit Check Bill To");
//var sPartsSales = TheApplication().InvokeMethod("LookupValue","QUOTE_TYPE","Parts Quote");
TheApplication().Utility.logVars("Fulfillment Set", sQuoteDisplay);
if (sQuoteDisplay == TheApplication().InvokeMethod("LookupValue","QUOTE_TYPE","Parts Quote") || sQuoteDisplay == TheApplication().InvokeMethod("LookupValue","QUOTE_TYPE","Over the Counter"))
{
var isFreightValid = CheckFulfillmentSetPair();
if (isFreightValid != "Y")
TheApplication().RaiseErrorText("All child lines and bill only lines must have a valid fulfillment set value");
}
TheApplication().Utility.logVars("Quote Total", QuoteTotal, "Quote Type", sQuoteDisplay, "Payment Method", aQuotePaymentMethod, "Object Id", row_id);
if (sQuoteDisplay == TheApplication().InvokeMethod("LookupValue","QUOTE_TYPE","Wholegoods Quote")) {
// to ensure that Credit check is bypassed for Whole Goods Quote..only Bill To Site is checked for a whole goods Quote
Outputs.SetProperty("CreditCheck","ByPass");
} else if((sQuoteDisplay == TheApplication().InvokeMethod("LookupValue","QUOTE_TYPE","Service Quote")) ||
(QuoteTotal > 0)) { //Purchase Order
QuoteCreditToBeValidated();
//Nag; Commented for CQ# 12049.
//if (aQuotePaymentMethod == payMethodCash) {
// Outputs.SetProperty("CreditCheck","ByPass");
//}
if(sCreditCheck == "Yes")
{
Outputs.SetProperty("CreditCheck","Yes");
}
else if(sCreditCheck == "ByPass")
{
Outputs.SetProperty("CreditCheck","ByPass");
}
else
{
Outputs.SetProperty("CreditCheck","No");
}
}
else
{
Outputs.SetProperty("CreditCheck","ByPass");
}
BillToSite = null;
TheApplication().Utility.logVars("CreditCheck", Outputs.GetProperty("CreditCheck"));
//Added by shanmukh for code clean up 08/26/2011
} catch (e) {
TheApplication().Utility.RaiseError(e);
} finally {
aQuotePaymentMethod = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Credit Check Service
ValidateQuoteOrder
function ValidateQuoteOrder(row_id,Order_TotalAmt,Order_QuoteId,PaymentLineAmt)
{
try
{
//function to fetch the Quote Total Amount, and if credit check is done on it.
TheApplication().Utility.logStack("ValidateQuoteOrder", this);
var QuoteAmount = 0;
var CreditCheckDone = "N";
var boOrder_Quote = TheApplication().GetBusObject("Quote");
var bcOrder_Quote = boOrder_Quote.GetBusComp("Quote");
if (Order_QuoteId != "")
{
// var bcQuotePayment = boOrder_Quote.GetBusComp("Payments");
with (bcOrder_Quote)
{
ActivateField("Quote Total");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",Order_QuoteId);
SetSearchSpec("Payment Method",payMethodPO);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
QuoteAmount = GetFieldValue("Quote Total");
}
}
}
var CreditToBeVerified = Order_TotalAmt - QuoteAmount;
switch ((CreditToBeVerified/PaymentLineAmt))
{
case 0:
break;
case 1:
TheApplication().SetProfileAttr("CMIOrderCreditCheck","Y");
//Only when Payment line has correct value we will proceed for credit check
break;
default:
if (QuoteAmount == 0)
TheApplication().RaiseError("CMI Credit Check - Order Full" , CreditToBeVerified);
else
TheApplication().RaiseError("CMI Credit Check - Order Quote",QuoteAmount,CreditToBeVerified);
break;
}
}
catch (e)
{
//throw e;
TheApplication().Utility.RaiseError(e);
}
finally
{
bcOrder_Quote = null;
boOrder_Quote = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Price Calculate BS
UpdateObject
/*************************************************************************************************************************
Functionality: Created the BS to trigger Signal "SetFieldValue" on update of CMI Net Price Calc Flag for Bug # DBUNG00003019
************************************************************************************************************************/
function UpdateObject(Inputs, Outputs, mode) {
try {
TheApplication().Utility.logStack("UpdateObject", this);
var headerId = Inputs.GetProperty("Quote Id");
// var lineId = Inputs.GetProperty("Quote Item Id");
var sSearchSpec;
var i = 0;
var boHeader:BusObject;
var bcHeader:BusComp;
var bcLine:BusComp;
var refresh = true;
switch (mode) {
case "Quote":
boHeader = TheApplication().GetBusObject("Quote");
bcHeader = boHeader.GetBusComp("Quote");
bcLine = boHeader.GetBusComp("Quote Item");
break;
case "Order":
boHeader = TheApplication().GetBusObject("Order Entry (Sales)");
bcHeader = boHeader.GetBusComp("Order Entry - Orders");
bcLine = boHeader.GetBusComp("Order Entry - Line Items");
break;
}
with (bcHeader) {
SetViewMode(AllView);
ActivateField("TimeStamp");
ActivateField("CMI Refresh Rollups");
ClearToQuery();
// Exclude Respec Defect 776 by KM101 on 2-Dec-2011
// Internal Bug # 912 Added OR [CMI SR Sub Type] IS NULL to the search expression by ki795 on 8-Dec-2011
// SetSearchExpr("[Id] = '"+headerId+"' AND ([CMI SR Sub Type] <> 'Respec' OR [CMI SR Sub Type] IS NULL)");
SetSearchSpec("Id", headerId);
if (mode == "Quote") SetSearchSpec("CMI SR Sub Type", "IS NULL OR <> 'Respec'");
ExecuteQuery(ForwardOnly);
var headerFound = FirstRecord();
TheApplication().Utility.logVars("Header Found?", headerFound);
if (headerFound) {
if (mode == "Quote") {
var sDispQuoteType = GetFieldValue("Quote Display Type");
if (sDispQuoteType == "Wholegoods Quote" || sDispQuoteType == "Over the Counter") {
with (bcLine) {
ActivateField("Quote Id");
ActivateField("Unit Price");
ActivateField("CMI Warranty Discount");
ActivateField("Adjusted List Price");
SetViewMode(AllView);
ClearToQuery();
ExecuteQuery(ForwardBackward);
var sRec = FirstRecord();
while (sRec) {
var sId = GetFieldValue("Id");
var sUnitPrice = ToNumber(GetFieldValue("Unit Price"));
var sNetPrice = ToNumber(GetFieldValue("Net Price"));
i=i+1
if (sUnitPrice > 0) {
SetFieldValue("Net Price", sUnitPrice);
WriteRecord();
}
sRec = NextRecord();
}
}
refresh = false;
}
}
// SetFieldValue("CMI Refresh Rollups", GetFieldValue("TimeStamp"));
// TheApplication().Utility.logVars("Refresh Rollups", GetFieldValue("CMI Refresh Rollups"), 4);
// WriteRecord();
}
}
Outputs.SetProperty("CMI Count", i);
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcLine = null;
bcHeader = null;
boHeader = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Price Calculate BS
Service_PreInvokeMethod
//Created the BS to trigger Signal "SetFieldValue" on update of CMI Net Price Calc Flag for Bug # DBUNG00003019
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
switch (MethodName) {
case "Update Quote":
UpdateObject(Inputs, Outputs, "Quote");
break;
case "Update Order":
UpdateObject(Inputs, Outputs, "Order");
break;
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Quote Status Check
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
/*************************************************************************************************************************
Created By : Shanmukha Srinivas Donepudi (KM326)
Created On : 2011-09-29
C&I Number : 4647
Functionality: Method to restrict quote status from Approved to Quote Ready, until all
Activities related to Quote Approval are in Done Status.
Invoked using Runtime event Action Set "CMI Quote Status Check"
************************************************************************************************************************/
if(MethodName == "CheckQuoteStatus")
{
//TheApplication().SetProfileAttr("QuoteStatusApproved", "");
//Commented out the following line and added Getproperty statement. JW918.Defect# 775
//var sQuoteId:String = TheApplication().GetProfileAttr("CMI Approval Quote Id");
var sQuoteId:String = Inputs.GetProperty("CMI Approval Quote Id");
var sQuoteBO:BusObject = TheApplication().GetBusObject("Quote");
var sActionBC:BusComp = sQuoteBO.GetBusComp("Action");
var sLOVBO:BusObject = TheApplication().GetBusObject("List Of Values");
var sLOVBC:BusComp = sLOVBO.GetBusComp("List Of Values");
var curRec;
var sTemp:String;
var sLOVSearchSpec:String = "";
var sValidActivities:Number;
with(sLOVBC)
{
SetViewMode(AllView);
ActivateField("High");
ActivateField("Value");
ActivateField("Type");
ClearToQuery();
SetSearchSpec("Type", "TODO_TYPE");
SetSearchSpec("High", "1");
SetSearchSpec("Active", "Y");
ExecuteQuery(ForwardOnly);
curRec = FirstRecord();
while(curRec)
{
sTemp = GetFieldValue("Value");
if(sLOVSearchSpec == "")
{
sLOVSearchSpec = sTemp;
}
else
{
sLOVSearchSpec = sLOVSearchSpec + " OR " + "[Type] = '" + sTemp + "'";
}
curRec = NextRecord();
}
}
with(sActionBC)
{
SetViewMode(AllView);
ActivateField("Type");
ActivateField("Status");
ActivateField("Quote Id");
ClearToQuery();
SetSearchSpec("Quote Id", sQuoteId);
SetSearchSpec("Type", sLOVSearchSpec);
SetSearchSpec("Status", "<> 'Done'");
ExecuteQuery(ForwardOnly);
sValidActivities = CountRecords();
if(sValidActivities != 0)
{
TheApplication().RaiseError("CMI Quote Approval Check");
}
}
return(CancelOperation);
}
}
catch(e)
{
throw(e);
}
finally
{
sActionBC = null;
sLOVBC = null;
sQuoteBO = null;
sLOVBO = null;
sLOVSearchSpec = null;
sTemp = null;
sQuoteId = null;
}
return (ContinueOperation);
}

CMI Quote To Order BS
QuoteToOrder
function QuoteToOrder(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("QuoteToOrder", this);
var sQuoteId = Inputs.GetProperty("QuoteId");
var oBOQuote = TheApplication().GetBusObject("Quote");
var oBCQuote = oBOQuote.GetBusComp("Quote");
var oBCQuoteItem = oBOQuote.GetBusComp("Quote Item");
var oBOOrder = TheApplication().GetBusObject("Order Entry (Sales)");
var oBCOrderHeader = oBOOrder.GetBusComp("Order Entry - Orders");
var outputVal;
var sOrderId;
with (oBCQuote) {
SetViewMode(AllView);
ActivateField("Status");
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardOnly);
//Set a profile attribute to prevent the refresh in the signal when called from script
TheApplication().SetProfileAttr("SkipRefresh", "TRUE");
oBCQuote.InvokeMethod("AutoOrderSalesQuote");
//Profile Attribute set in Order Entry - Orders new record event
sOrderId = TheApplication().GetProfileAttr("OrderId")
Outputs.SetProperty("OrderId", sOrderId);
}// end with
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBOQuote = null;
oBCQuote = null;
oBCQuoteItem = null;
oBOOrder = null;
oBCOrderHeader = null;
TheApplication().SetProfileAttr("SkipRefresh", "FALSE");
TheApplication().Utility.logUnstack(sOrderId);
}
}

CMI Quote To Order BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : ix964
Created On : 09 Dec 2010
Method Name:
Functionality:
Input: Quote Number, Order Id
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs){
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if (MethodName == "QuoteToOrder") {
QuoteToOrder(Inputs, Outputs);
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Quote To Return Order BS
UpdateQuantity
/***************************************************************************************************************
Created By : JF344
Created On : 4-Mar-2011
****************************************************************************************************************/
function UpdateQuantity(sOrderId, sSRId, sQuoteId) {
try {
TheApplication().Utility.logStack("UpdateQuantity", this);
if(sOrderId == "" || sSRId == "") return;
var boOrder:BusObject = TheApplication().GetBusObject("Order Entry");
var bcOrder:BusComp = boOrder.GetBusComp("Order Entry - Orders");
var bcOrderItem:BusComp = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
var boSR:BusObject = TheApplication().GetBusObject("Service Request");
var bcSR:BusComp = boSR.GetBusComp("Service Request");
var sBU = "";
var sLineType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Internal Return Line");
var bDeleteOrder = "";
var sZero = 0;
var found;
var defaultInv;
//Get fields from the SR in order to set them on the Order
with(bcSR) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("CMI SR Business Unit");
SetSearchSpec("Id", sSRId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("SR ("+sSRId+") found?", found);
if(found) {
sBU = GetFieldValue("CMI SR Business Unit");
TheApplication().Utility.logVars("SR Business Unit", sBU);
}
}
with(bcOrder) {
ActivateField("Primary Organization Id");
ActivateField("CMI SR Primary Division Id");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Order ("+sOrderId+") found?", found);
if(found) {
var divisionId = GetFieldValue("CMI SR Primary Division Id");
defaultInv = GetDefaultInv(divisionId);
var sOrderPriOrgId = GetFieldValue("Primary Organization Id");
TheApplication().Utility.logVars("SR Division Id", divisionId);
SetFieldValue("Service Request Id", sSRId);
SetFieldValue("CMI Business Unit", sBU);
WriteRecord();
//Update fields for Main assembly since it does not exist on the parts tracker
if (mainFound) {
with(bcOrderItem) {
ClearToQuery();
ActivateField("Destination Inventory Loc Id");
ActivateField("Source Inventory Loc Id");
ActivateField("Quantity Requested");
ActivateField("CMI Actual Quantity");
ActivateField("CMI Serial Number");
SetViewMode(AllView);
SetSearchExpr("[CMI Main Assembly Flag] = 'Y'");
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Main Assembly on Order?", found);
if(FirstRecord()) {
SetFieldValue("Quantity Requested", GetFieldValue("CMI Actual Quantity"));
SetFieldValue("Source Inventory Loc Id", GetInventoryLocId("WIP",sOrderPriOrgId));
SetFieldValue("Destination Inventory Loc Id", GetInventoryLocId("FG",sOrderPriOrgId));
WriteRecord();
}
}
}
}
}
var boAction:BusObject = TheApplication().GetBusObject("Action");
var bcAction:BusComp = boAction.GetBusComp("Action");
var bcPartTracker:BusComp = boAction.GetBusComp("FS Activity Parts Movement");
//Instantiate the Part Tracker and loop through each record to insure it exists on the return
//Order if the Picked Quantity is greater than the Used Quantity
with(bcAction) {
ActivateField("Quote Id");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Quote Id", sQuoteId);
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker"));
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker Found?", found);
if(found) { //process part tracker
with(bcPartTracker) {
ClearToQuery();
ActivateField("Trunk Invloc Id");
ActivateField("Used Quantity");
ActivateField("CMI Parts Allocated");
ActivateField("CMI Return");
ActivateField("CMI Return Quantity");
ActivateField("CMI Unit of Measure");
SetViewMode(AllView);
ExecuteQuery(ForwardOnly);
var bHasRecord = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker Item Found?", bHasRecord);
while(bHasRecord) {
var sTrunkInvlocId = GetFieldValue("Trunk Invloc Id");
var sQtyUsed = GetFieldValue("Used Quantity");
var sReturn = GetFieldValue("CMI Return");
var sReturnQty = GetFieldValue("CMI Return Quantity");
var sQtyAllocated = GetFieldValue("CMI Parts Allocated");
var sQtyReturn = parseInt(sQtyAllocated) - parseInt(sQtyUsed);
var sOILId;
TheApplication().Utility.logVars("PT - Picked / Used / Returned",sQtyAllocated+" / "+sQtyUsed+" / "+sQtyReturn);
if(sQtyReturn <0) sQtyReturn = 0;
var sProdId = GetFieldValue("Product Id");
TheApplication().Utility.logStep(GetFieldValue("Product Name")+" ("+sProdId+") - Return: "+sReturnQty);
with(bcOrderItem) {
ClearToQuery();
ActivateField("Destination Inventory Loc Id");
ActivateField("Source Inventory Loc Id");
ActivateField("Quantity Requested");
ActivateField("CMI Serial Number");
SetViewMode(AllView);
SetSearchExpr("[Product Id] = '" + sProdId + "' AND [Quantity Requested] = '" + sZero + "'");
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Line for Product Found?", found);
//If matching line item is found, update it, otherwise create a new record
if(FirstRecord()) {
sOILId = GetFieldValue("Id");
//For Cores, find the linked dirty core line and update the qty or delete
if (sReturn != "") { //will either be 'No Return' or 'Core'
UpdateDirtyCore(sOrderId, sOILId, sReturnQty, sTrunkInvlocId, sReturn, sOrderPriOrgId);
}
//If the order item is all used, there is no need show in the return order.
if(sQtyReturn == 0) {
DeleteRecord();
} else {
SetFieldValue("Source Inventory Loc Id", sTrunkInvlocId);
SetFieldValue("Destination Inventory Loc Id", defaultInv);
SetFieldValue("Quantity Requested", sQtyReturn);
WriteRecord();
}
//Part Tracker item exists without corresponding Order Line. If Part Tracker line has a
//return quantity create the Return Order line item
} else if (sQtyReturn > 0) {
NewRecord(NewAfter);
SetFieldValue("CMI Actual Quantity",sQtyReturn);
SetFieldValue("Product Id",sProdId);
SetFieldValue("Quantity Requested",sQtyReturn);
SetFieldValue("Extended Quantity Requested",sQtyReturn);
SetFieldValue("Action Code", TheApplication().InvokeMethod("LookupValue", "DELTA_ACTION_CODE", "New"));
SetFieldValue("CMI Action Code", TheApplication().InvokeMethod("LookupValue", "DELTA_ACTION_CODE", "New"));
SetFieldValue("CMI Quantity Quoted", 0);
SetFieldValue("CMI Unit of Measure",bcPartTracker.GetFieldValue("CMI Unit of Measure"));
SetFieldValue("CMI Line Type","Service Internal Return Line");
SetFieldValue("Source Inventory Loc Id", sTrunkInvlocId);
SetFieldValue("Destination Inventory Loc Id", defaultInv);
WriteRecord();
}
}
bHasRecord = NextRecord();
}
}
}
}
//Jn705: Added to delete the return order if no line item exists
with(bcOrder) {
with(bcOrderItem) {
ClearToQuery();
ExecuteQuery(ForwardOnly);
bDeleteOrder = FirstRecord();
}
TheApplication().Utility.logVars("Order Items Found?", bDeleteOrder);
if(!bDeleteOrder) DeleteRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPartTracker = null;
bcAction = null;
boAction = null;
bcSR = null;
boSR = null;
bcOrderItem = null;
bcOrder = null;
boOrder = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote To Return Order BS
UpdateDirtyCore
//Added by KM326 for 4455 on 22/11/2011
// This function is used to update or delete the dirty core created via datamap depending upon
// the CMI Return and CMI Return Quantity field values in Parts Tracker
function UpdateDirtyCore(sOrderId, sOILId, sReturnQty, sTrunkInvlocId, sReturn, sOrderPriOrgId)
{
try {
TheApplication().Utility.logStack("UpdateDirtyCore", this);
var oBOOrderDirty:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var OBCOrderItemDirty:BusComp = oBOOrderDirty.GetBusComp("Order Entry - Line Items (Simple)");
var sCore = TheApplication().InvokeMethod("LookupValue", "CMI_RETURN", "Core");
var found;
with(OBCOrderItemDirty) {
ActivateField("Quantity Requested");
ActivateField("Source Inventory Loc Id");
ActivateField("Destination Inventory Loc Id");
ClearToQuery();
SetSearchSpec("Order Header Id",sOrderId);
SetSearchSpec("Covered Quote Item Id",sOILId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Dirty Core Line Found?", found);
if(found) {
TheApplication().Utility.logVars("Return - Type/Qty", sReturn+" / "+sReturnQty);
if(sReturn == sCore && sReturnQty != 0) {
SetFieldValue("Source Inventory Loc Id", sTrunkInvlocId);
SetFieldValue("Destination Inventory Loc Id", GetInventoryLocId("Dirty Core",sOrderPriOrgId));
SetFieldValue("Quantity Requested", sReturnQty);
WriteRecord();
} else {
DeleteRecord();
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
OBCOrderItemDirty = null;
oBOOrderDirty = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote To Return Order BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*************************************************************************************************************************
Modified By : JQ486
Modified On : 03rd Aug 2011
Method Name: function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
C&I Number : 4460
Requirement #: S236
Functionality: This BS is called from the RTE on SetFieldValue of "CMI Line Type" Field.This invokes the function "GetDirtyCoreInv".
Input: NA
Output: NA
************************************************************************************************************************/
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
//For Enhancement S236, added the below variable section , by jq486 on 05 Aug 2011
var retVal = CancelOperation;
var sOLIId:String = "";
var oBO:BusObject;
var oBCOrderLI:BusComp;
var sSubInv:String = "";
var isRec:Boolean;
switch(MethodName) {
case "QuoteToReturnOrder":
QuoteToReturnOrder(Inputs,Outputs);
break;
//For Enhancement S236, added the below Code to invoke the GetDirtyCoreInv fn to set the destination
//inventory for "Dirty Core" , by jq486 on 05 Aug 2011
case "GetDirtyCoreInv":
sOLIId = TheApplication().GetProfileAttr("CMIDirtyCoreOLIId");
oBO = TheApplication().GetBusObject("Order Entry (Sales)");
oBCOrderLI = oBO.GetBusComp("Order Entry - Line Items");
with(oBCOrderLI) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("CMI Default Inventory Location Id");
ActivateField("Organization Id");
SetSearchSpec("Id", sOLIId);
ExecuteQuery(ForwardOnly);
isRec = FirstRecord();
TheApplication().Utility.logVars("Order Line found?", isRec);
if(isRec) {//Setting the Default Inventory Location ID with the Dirty Core Sub Inventory ID, added by JQ486, 05 Aug 2011.
sSubInv = GetInventoryLocId("Dirty Core", GetFieldValue("Organization Id"))
SetFieldValue("CMI Default Inventory Location Id",sSubInv);
}
WriteRecord();
}
break;
default:
retVal = ContinueOperation;
}//end of switch
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
isRec = null;
sSubInv = null;
oBCOrderLI = null;
oBO = null;
sOLIId = null;
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Quote To Return Order BS
GetInventoryLocId
function GetInventoryLocId(inventoryType,sOrgId) {
try {
TheApplication().Utility.logStack("GetInventoryLocId", this, 4);
var boInventory:BusObject = TheApplication().GetBusObject("FS Inventory Location Mgmt");
var bcInventory:BusComp = boInventory.GetBusComp("FS Inventory Location");
var sInvLocId = "";
with(bcInventory) {
SetViewMode(AllView);
ActivateField("Inventory Type");
ActivateField("Primary Organization Id");
ClearToQuery();
SetSearchSpec("Inventory Type", inventoryType);
SetSearchSpec("Primary Organization Id", sOrgId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
sInvLocId = GetFieldValue("Id");
TheApplication().Utility.logVars(inventoryType+" - Inventory Location Id", sInvLocId);
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcInventory = null;
boInventory = null;
TheApplication().Utility.logUnstack(sInvLocId, 4);
}
return (sInvLocId);
}

CMI Quote To Return Order BS
GetDefaultInv
/***************************************************************************************************************
Created By : JF344
Created On : 4-Mar-2011
C&I Number :
Requirement # :
Method Name: GetDefaultInv
Functionality:
Input: None
Output: None
Customization Approval #: NA
********************************************************************************************************************/
function GetDefaultInv(defaultInv)
{
try{
TheApplication().Utility.logStack("GetDefaultInv", this);
var sReturn = "";
var bcDivision:BusComp = TheApplication().GetBusObject("Internal Division").GetBusComp("Internal Division");
with(bcDivision) {
ClearToQuery();
SetSearchSpec("Id", defaultInv);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
sReturn = GetFieldValue("CMI Default Inventory Location Id");
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcDivision = null;
TheApplication().Utility.logUnstack(sReturn);
}
return(sReturn);
}

CMI Quote To Return Order BS
QuoteToReturnOrder
/***************************************************************************************************************
Created By : JF344
Created On : 28-Feb-11
C&I Number :
Requirement # :
Method Name: uoteToReturnOrder
Functionality:
Input: None
Output: None
Customization Approval #: NA
******************************************************************************************************************/
function QuoteToReturnOrder(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("QuoteToReturnOrder", this);
var sQuoteId = Inputs.GetProperty("QuoteId");
var boQuote:BusObject = TheApplication().GetBusObject("Quote");
var bcQuote:BusComp = boQuote.GetBusComp("Quote");
var bcQuoteItem:BusComp = boQuote.GetBusComp("Quote Item (Simple)");
var oBOAction:BusObject = TheApplication().GetBusObject("Action");
var oBCAction:BusComp = oBOAction.GetBusComp("Action");
var oBCPartsTracker:BusComp = oBOAction.GetBusComp("FS Activity Parts Movement");
var sPartsTracker = TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker");
var createReturnOrder = false;
var quoteFound = false;
var found = false;
//If the Quote has a Main Assembly, a return order must be created for it regardless of Parts Tracker
//Quantities
with (bcQuote) {
SetViewMode(AllView);
ActivateField("Status");
ActivateField("Service Request Id");
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardOnly);
quoteFound = FirstRecord();
TheApplication().Utility.logVars("Quote ("+sQuoteId+") found?", quoteFound);
if (quoteFound) {
with(bcQuoteItem) {
SetViewMode(AllView);
ActivateField("Extended Quantity Requested");
ClearToQuery();
SetSearchSpec("CMI Main Assembly Flag","Y");
ExecuteQuery(ForwardOnly);
mainFound = FirstRecord();
TheApplication().Utility.logVars("Main Assembly found?", mainFound);
}
}
}
//if no Main Assembly present, determine if Return order is needed by checking used qty on parts tracker
if (!mainFound) {
with(oBCAction) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("Quote Id");
var sSearch1 = "[Quote Id] = '" + sQuoteId + "' AND [Type] = '" + sPartsTracker + "'";
SetSearchExpr(sSearch1);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Quote Id", sQuoteId, "Parts Tracker found?", found);
if(found) {
with(oBCPartsTracker) {
ActivateField("CMI Parts Allocated");
ActivateField("Used Quantity");
ActivateField("CMI Return Quantity");
SetViewMode(AllView);
ClearToQuery();
ExecuteQuery(ForwardOnly);
var sHaveParts = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker Item found?", sHaveParts);
while(sHaveParts) {
var sPickedQty = GetFieldValue("CMI Parts Allocated");
var sUsedQty = GetFieldValue("Used Quantity");
//Added by KM326 for 4455 on 22/11/2011
var sReturnQuantity = GetFieldValue("CMI Return Quantity");
TheApplication().Utility.logVars("Used/Picked/Return", sUsedQty+" / "+sPickedQty+" / "+sReturnQuantity);
if(ToNumber(sUsedQty) < ToNumber(sPickedQty) || sReturnQuantity != 0) {//|| sReturnQuantity != 0 by KM326 for 4455 on 22/11/2011
createReturnOrder = true;
sHaveParts = false;
} else sHaveParts = NextRecord();
}//while(sHaveParts)
}//with(oBCPartsTracker)
}//if(FirstRecord())
}// with(oBCAction)
}
TheApplication().Utility.logVars("Create Return Order", createReturnOrder);
if(createReturnOrder || mainFound) {
if (quoteFound) {
var sSRId = bcQuote.GetFieldValue("Service Request Id");
//Set a profile attribute to prevent the refresh in the signal when called from script
TheApplication().SetProfileAttr("SkipRefresh", "TRUE");
bcQuote.InvokeMethod("AutoOrderReturnQuote");
UpdateQuantity(TheApplication().GetSharedGlobal("DTUSharedGlobalDestId"),sSRId, sQuoteId);
}
}//end if(createReturnOrder)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcQuoteItem = null;
oBCAction = null;
oBOAction = null;
oBCPartsTracker = null;
bcQuote = null;
boQuote = null;
TheApplication().SetProfileAttr("SkipRefresh", "FALSE");
TheApplication().Utility.logUnstack();
}
}

CMI Quote To Return Order BS
(declarations)
var mainFound = false;

CMI Quote Update Activity Duration
QuantityUpdateActivity
function QuantityUpdateActivity()
{
try {
TheApplication().Utility.logStack("QuantityUpdateActivity", this);
var iQtyInc = 0;
var iQtyTotal = 0;
var iQtyTravel = 0;
var iQtyWork = 0;
var iQty, iPreQty, iOldDura, iOldWorkHrs, iOldTravelHrs;
var iPreQuoteStatus = "";
var boPreQuote = TheApplication().GetBusObject("CMI Quote");
var bcPreQuote = boPreQuote.GetBusComp("CMI Quote Simple"); //IY793 Defect 210 CRP 1.5
var boQuoteItem = TheApplication().GetBusObject("Quote");
var bcQuoteItem = boQuoteItem.GetBusComp("Quote Item (Simple)");
var boSR = TheApplication().GetBusObject("Service Request");
var bcAction = boSR.GetBusComp("Action");
var sLabor = TheApplication().InvokeMethod("LookupValue","PRODUCT_TYPE","Labor");
var sSerLabor = TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Service Labor");
var sCategory = TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Service");
var sQuoteReady:String = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Quote Ready");
var sQuoteAccepted:String = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Ready to Schedule");
var sAccepted:String = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Accepted");
var revised = false; //IY793 Defect 210 CRP 1.5
var sPreRevId = ""; //IY793 Defect 210 CRP 1.5
// BB CQ 12383: Check activity Status
//Cancelled
var activityCancelled:String = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Cancelled");
//Done
var activityDone:String = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Done");
//CMI DBU rel#1, Defect# 5360: script: active buscomp is fetching the different record than the current one.
//therefore added the script to fetch the Quote ID from profile attribute set in RTE by JW919 on 0130/2012
var sRowId:String = TheApplication().GetProfileAttr("UpdateLaborActQuoteId");
var sRev = TheApplication().GetProfileAttr("CurrentQuoteRevision");
TheApplication().Utility.logVars("Revision", sRev);
if (sRev > 1) {
//CMI C&I# 4467 Enhancement#S132: getting field value as this field stores Id of previous version of quote through Data map By JQ487 On 06/23/11
sPreRevId = TheApplication().GetProfileAttr("LastQuoteRevisionId");
revised = true;
}
if (revised) {
//Added code to get Previous Quote's Status for defect 210 by IY793 on 09/29/2011
with(bcPreQuote) {
ActivateField("Status");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sPreRevId);
ExecuteQuery(ForwardOnly);
var isRecord = FirstRecord();
TheApplication().Utility.logVars("Prior Revision ("+sPreRevId+") found?", isRecord);
if(isRecord) {
iPreQuoteStatus = GetFieldValue("Status");
}
}
}
with(bcQuoteItem) {
SetViewMode(AllView);
ActivateField("Product Type");
ActivateField("Quantity Requested");
ActivateField("CMI Predefault Quantity");
ActivateField("CMI Product Sub Type");
ClearToQuery();
SetSearchSpec("Quote Id", sRowId);
SetSearchSpec("Product Type", sLabor);
ExecuteQuery(ForwardBackward);
var HasRecord = FirstRecord();
TheApplication().Utility.logVars(sLabor+" for Quote ("+sRowId+") found?", HasRecord);
while (HasRecord) {
//if Labor record found then we take current qty and qty of previous version (if any) and if difference
//is greater than 0 then we add the difference to duaration hours
var sTravelFlag:String = GetFieldValue("CMI Product Sub Type");
iQty = GetFieldValue("Quantity Requested");
iPreQty = GetFieldValue("CMI Predefault Quantity");//This field is used to store Quantity or line item of previous version of Quote through data map
TheApplication().Utility.logStep(iPreQuoteStatus+" "+sTravelFlag+" - Current / Previous: "+iQty+" / "+iPreQty);
if(iPreQuoteStatus == sQuoteReady || iPreQuoteStatus == sQuoteAccepted || iPreQuoteStatus == sAccepted || iPreQuoteStatus == "") {
iQtyInc = ToNumber(iQty)-ToNumber(iPreQty);//--Delta calculation
} else {
iQtyInc = ToNumber(iQty);
}
// if (iPreQuoteStatus == "") {
// SetFieldValue("CMI Predefault Quantity", iQty);
// WriteRecord();
// }
if(iQtyInc > 0) {
iQtyTotal = ToNumber(iQtyTotal)+ToNumber(iQtyInc);
if(sTravelFlag == "Travel")
iQtyTravel = ToNumber(iQtyTravel)+ToNumber(iQtyInc);
else
iQtyWork = ToNumber(iQtyWork)+ToNumber(iQtyInc);
}
HasRecord = NextRecord();
}// END : while (HasRecord)
}// END: with(bcQuoteItem)
TheApplication().Utility.logVars("Current Work / Travel / Duration", iQtyWork+" / "+iQtyTravel+" / "+iQtyTotal);
with(bcAction) {
SetViewMode(AllView);
ActivateField("Duration Hours");
ActivateField("CMI Travel Hours");
ActivateField("CMI Work Hours");
ClearToQuery();
SetSearchSpec("Quote Id", sRowId);
SetSearchSpec("Type", sSerLabor);
SetSearchSpec("Category", sCategory);
//BB CQ 12383
SetSearchSpec("Status", "<> '" + activityCancelled + "' AND <> '" + activityDone + "'");
ExecuteQuery(ForwardOnly)
TheApplication().Utility.logVars(sSerLabor+ " / "+sCategory+" Activity found?", FirstRecord());
if (FirstRecord()) {
//Tiger: get original work hours and travel hours as well
iOldDura = GetFieldValue("Duration Hours");
if (iOldDura == null || iOldDura == "") iOldDura = 0;
iOldWorkHrs = GetFieldValue("CMI Work Hours");
if (iOldWorkHrs == "") iOldWorkHrs = 0;
iOldTravelHrs = GetFieldValue("CMI Travel Hours");
if (iOldTravelHrs == "") iOldTravelHrs = 0;
TheApplication().Utility.logVars("Old Work / Travel / Duration", iOldWorkHrs+" / "+iOldTravelHrs+" / "+iOldDura);
SetFieldValue("Duration Hours", ToNumber(iOldDura) + ToNumber(iQtyTotal));
SetFieldValue("CMI Travel Hours", ToNumber(iOldTravelHrs) + ToNumber(iQtyTravel));
SetFieldValue("CMI Work Hours", ToNumber(iOldWorkHrs) + ToNumber(iQtyWork));
WriteRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPreQuote = null;
bcAction = null;
boSR = null;
bcQuoteItem = null;
boQuoteItem = null;
boPreQuote = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote Update Activity Duration
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : Marco Wang
Created On : 30th Dec 2010
Method Name: function (MethodName) == "QuantityToActivity"
Functionality: This method will update Duration Hours Field of Action BC when Quote Status change to "Quote Ready"
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
switch (MethodName) {
case "QuantityUpdateActivity":
QuantityUpdateActivity();
break;
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Quote Validation
FindCustProduct
function FindCustProduct(Inputs, Outputs)
{
// KK : 7/21/2012: CQ# 8705
try
{
TheApplication().Utility.logStack("FindCustProduct", this);
var objQuoteItem = TheApplication().GetBusObject("Quote").GetBusComp("Quote Item");
var sQuoteId = Inputs.GetProperty("Quote Id");
var hasRec = false;
var isCustomizable = "N";
var sCfgType, brandFranchise, sIsRootItem;
with(objQuoteItem) {
SetViewMode(AllView);
ActivateField("Product Def Type Code");
ActivateField("IsRootItem");
ActivateField("Product");
ActivateField("Line Number");
ActivateField("CMI Brand Franchise Code");
ClearToQuery();
SetSearchSpec("Quote Id", sQuoteId);
ExecuteQuery();
hasRec = FirstRecord();
while (hasRec) {
sCfgType = GetFieldValue("Product Def Type Code");
sIsRootItem = GetFieldValue("IsRootItem");
brandFranchise = GetFieldValue("CMI Brand Franchise Code");
if((sIsRootItem == "N" || sCfgType == "Customizable") && brandFranchise.indexOf(" ReCon") < 0 ) {
isCustomizable = "Y";
TheApplication().Utility.logVars("Line "+GetFieldValue("Line Number")+" - Part / Brand",GetFieldValue("Product")+" / "+brandFranchise);
break;
}
hasRec = NextRecord();
}//end of while
}//end of with(objQuoteItem)
Outputs.SetProperty("CustomizableExist",isCustomizable);
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
objQuoteItem = null;
TheApplication().Utility.logUnstack(isCustomizable);
}
}

CMI Quote Validation
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
// KK : 7/21/2012: CQ# 8705
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = ContinueOperation;
switch (MethodName) {
case "ATPValidation":
FindCustProduct(Inputs, Outputs);
retVal = CancelOperation;
break;
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Quote to Order
QuoteValidation
function QuoteValidation(sQuoteId)
{
/*CMI DBU:JQ487:19/Nov/2010: The Below function is used to Query on Quote BC to valdate that product of
type Part or Product are also present in QLI before creation of parts request. IF not product of type part/Product
is present, then this script sets a variable, which controls creation pf parts request order. This script is also
used for calculating the delta changes. */
try {
TheApplication().Utility.logStack("QuoteValidation", this);
var oBO = TheApplication().GetBusObject("Service Request");//added script to make order creation work-31 Jan 2011-Dinesh
var oBCQuote = oBO.GetBusComp("Quote");
var oBCQuoteItem = oBO.GetBusComp("Quote Item");
var prodTypeLabor = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
var prodTypeMisc = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Misc");
var writeInYes = TheApplication().InvokeMethod("LookupValue", "CMI_WRITE_IN_IDENTIFIER", "Yes");
var lineTypeRecon = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type");
var lineTypeReturn = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type");
var createRequest = false;
var sUpdQty = 0;
var sQtyDiff = 0;
var iQtyIdx;//Declaring Variable to capture the Qty Index
var sRev;
var sMainFlg, sLineType, sWriteIn;
var sQty = 0;
var sQtyCal = 0;
var sMainFlgCount=0;
var found = false;
//Populate an array to get quoted/picked quantities of each product from the Parts Tracker activity
GetLineItemsInfo(sQuoteNum);
with (oBCQuote) {
SetViewMode(AllView);
ActivateField("Revision");
ClearToQuery();
SetSearchSpec("Id", sQuoteId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Quote Found?", found);
if(found) {
sRev = GetFieldValue("Revision");
TheApplication().Utility.logVars("Revisions", sRev);
with (oBCQuoteItem) {
SetViewMode(AllView);
ActivateField("Product Type");
ActivateField("CMI Revise Flag");
ActivateField("Quantity Requested");
ActivateField("CMI Quantity Requested");
ActivateField("Product Id");
ActivateField("Product");
ActivateField("CMI Serialized Flag");
ActivateField("CMI Parts Check");
ActivateField("CMI Main Assembly Flag");
ActivateField("CMI Line Type");
ClearToQuery();
ExecuteQuery(ForwardBackward);
found = FirstRecord();
//Loop through each quote item
TheApplication().Utility.logVars("Quote Items Found?", found);
while(found) {
sProdType = GetFieldValue("Product Type");
sProdId = GetFieldValue("Product Id");
sRevFlg = GetFieldValue("CMI Revise Flag");
sQty = GetFieldValue("Quantity Requested");
sQtyCal = GetFieldValue("CMI Quantity Requested");
sProdName = GetFieldValue("Product");
sSerialized = GetFieldValue("CMI Serialized Flag");
sMainFlg = GetFieldValue("CMI Main Assembly Flag");
sLineType = GetFieldValue("CMI Line Type");
sWriteIn = GetFieldValue("CMI Write In Identifier");
TheApplication().Utility.logStep(sProdName+" ("+sProdId+")");
TheApplication().Utility.logVars("Product/Line Type", sProdType+" / "+sLineType);
TheApplication().Utility.logVars("Write In/Main Assembly", sWriteIn+" / "+sMainFlg);
//Exclude Clean/Dirty Core Lines; all Labor lines; Misc Part types except for
//Write In Service; and Main Assembly lines
if ((sProdType != prodTypeLabor) &&
(sProdType != prodTypeMisc || sWriteIn == writeInYes) &&
sLineType != lineTypeRecon && sLineType != lineTypeReturn && sMainFlg != "Y") {
TheApplication().Utility.logVars("Line Revised",sRevFlg);
if (sRevFlg == "Y") {
TheApplication().Utility.logVars("New/Prev Quantity", sQty+" / "+sQtyCal);
if (sQty != sQtyCal) {
sUpdQty = GetFieldValue("CMI ATP Requested Quantity");
TheApplication().Utility.logVars("ATP Requested Quantity", sUpdQty);
if (sUpdQty > 0) {
createRequest = true;
}
}
} else {
if(sRev > 1) {
TheApplication().Utility.logVars("Serialized", sSerialized);
if (sSerialized != "Y") {//this condition invokes Serial check func
iQtyIdx = GetItemQty(sProdId);
sQuantQuoted = aQuotedQtyArr[iQtyIdx];
sPickQuan = aAllocQtyArr[iQtyIdx];
sQtyDiff = ToNumber(sQuantQuoted) + ToNumber(sQty);//<jq487> added to accomodate defect 657
//Account for pre staged products. If amount already picked is greater
//than what is requested, no need to create a Parts Request
TheApplication().Utility.logVars("Quoted Difference", sQtyDiff, "Picked", sPickQuan);
if (sQtyDiff <= ToNumber(sPickQuan)) {//<jq487> added to accomodate defect 657
SetFieldValue("CMI Parts Check", "Y");//<jq487> added to accomodate defect 657
} else {
createRequest = true;
SetFieldValue("CMI Parts Check", "N");//<jq487> added to accomodate defect 657
SetFieldValue("CMI Quantity Requested", sPickQuan);//<jq487> added to accomodate defect 657
}
WriteRecord();
} else {
createRequest = true;
}
} else {
createRequest = true;
}
}
}
found = NextRecord();
}//end while
//If all quote lines were explicitly excluded above, then set a flag to prevent the
//creation of the Parts Request
TheApplication().Utility.logVars("Create Parts Request?", createRequest);
if (createRequest == false) {
sRetCan = "Allow"; //This value indicates a Parts Request Order will NOT be created
}
}//end with
}//end if
}//end With
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCQuote = null;
oBCQuoteItem = null;
oBO = null;
createRequest = false;
sProdType = null;
sUpdQty = null;
sQty = null;
sQtyCal = null;
sRev = null;
TheApplication().Utility.logUnstack(sRetCan);
}
}

CMI Quote to Order
ProductCheck
function ProductCheck(sPrdDesc)
{
//JQ487:Added on 03 Jan 2011 for write-in product addition.This function will search in the product bc to retrieve the write-in's actual procuct name and id.
try
{
TheApplication().Utility.logStack("ProductCheck", this);
var oBO = TheApplication().ActiveBusObject();
var oBCInterProd = oBO.GetBusComp("Internal Product");
with(oBCInterProd)
{
SetViewMode(AllView);
ActivateField("Product");
ActivateField("Name");
ClearToQuery();
SetSearchSpec("Name", sPrdDesc);
ExecuteQuery(ForwardOnly);
var isRec1 = FirstRecord();
if(isRec1)
{
sProdId1 = GetFieldValue("Id");
sProdName1 = GetFieldValue("Name");
}
else
{
WriteError = "Display"; //JQ487: added new condition as per defect 572 on 08/03/11
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCInterProd = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote to Order
SerialCheck
function SerialCheck(sProdId)
{
/*CMI DBU:JQ487:15/Apr/2011: The Below function is used to Query on Part Tracker BC to valdate that Picked Qty on
Part Tracker Record is Less than sum of Quoted Qty and Qty request on current revision. */
try {
TheApplication().Utility.logStack("SerialCheck", this);
var IsActivityRec;
var IsPartTrackRec;
var oBO = TheApplication().GetBusObject("Action");
var oBCAction = oBO.GetBusComp("Action");
var oBCPartTracker = oBO.GetBusComp("FS Activity Parts Movement");
with(oBCAction) {
ActivateField("CMI Quote Number");
ActivateField("Type");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Quote Number",sQuoteNum);
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker"));
ExecuteQuery(ForwardOnly);
IsActivityRec = FirstRecord();
if(IsActivityRec)
{
var ActivityId = GetFieldValue("Id");
with(oBCPartTracker)
{
SetViewMode(AllView);
ActivateField("Product Name");
ActivateField("Product Id");
ActivateField("CMI Parts Allocated");
ActivateField("CMI Quoted Quantity");
ClearToQuery();
SetSearchSpec("Product Id", sProdId);
ExecuteQuery(ForwardOnly);
var sPCNextRecord = FirstRecord();
if(sPCNextRecord)
{
sQuantQuoted = GetFieldValue("CMI Quoted Quantity");
sPickQuan = GetFieldValue("CMI Parts Allocated");
}
}
}//End of while(IsActivityRec)
}//End of with(oBCAction)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCPartTracker = null;
oBCAction = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}//end of function

CMI Quote to Order
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs) {
/*********************************************************
AUTHOR: JQ487,CMI DBU, Build Quote Repair Functionality(Part Request Section)
DESCRIPTION: This Script will be triggered for creation of Parts Request Order
based on the number of Part/Product Line Items available on the Quote Line
Item for an Accepted Quote.
DATE CREATED: 19 Nov 2010
UPDATES: 29 March 2011 - JQ487, Added additional condition for one off.
*********************************************************/
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
var txnSvc = TheApplication().GetService("EAI Transaction Service");
var ins = TheApplication().NewPropertySet();
var outs = TheApplication().NewPropertySet();
var rollback = true;
if (MethodName == "QuoteToOrder") {
var oBO = TheApplication().ActiveBusObject();
var oBCQuote = oBO.GetBusComp("Quote");
var sQuoteId = TheApplication().GetProfileAttr("Quote Id");
var sStaSet = TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Accepted")
with (oBCQuote) {
var sStatus = GetFieldValue("Status");
InvokeMethod("SetAdminMode","TRUE");
sSRNum = GetFieldValue("Service Request Id");
sQuoteNum = GetFieldValue("Quote Number");
var sRev = GetFieldValue("Revision");
if (sStatus == TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Ready to Schedule")) {
try {
//Create a commit point before any record updates are made to the quote or order
txnSvc.InvokeMethod("BeginTransaction", ins, outs);
QuoteValidation(sQuoteId);
/*CMI DBU:JQ487:29/Mar/2011: The Below function is essential as if the condition is true
then as per requirement, parts request should not be created, only the status of quote
should change to 'Accepted'.*/
if(sRetCan == "Allow") {
SetFieldValue("Status", sStaSet);
WriteRecord();
ins.SetProperty("Is Abort", "False");
txnSvc.InvokeMethod("EndTransaction", ins, outs);
} else {
//If a revision, potentially update the parts tracker
TheApplication().Utility.logVars("Revisions", sRev, "Current Status", currentStatus);
if (sRev > 1 &&
currentStatus == TheApplication().InvokeMethod("LookupValue","EVENT_STATUS","Ship Complete")) {
UpdatePartTracker(sQuoteNum);
}
InvokeMethod("AutoOrderPartsRequestQuote");
SetFieldValue("Status", sStaSet);
WriteRecord();
ins.SetProperty("Is Abort", "False");
txnSvc.InvokeMethod("EndTransaction", ins, outs);
rollback = false;
TheApplication().Utility.RaiseError("Parts Request created. Review & submit.");
}
} catch(e) {
//If the standard user notification message is thrown to the UI, do not rollback
if (rollback) {
ins.SetProperty("Is Abort", "True");
txnSvc.InvokeMethod("EndTransaction", ins, outs);
InvokeMethod("RefreshRecord");
SetFieldValue("CMI Status", TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "Quote Ready"));
WriteRecord();
}
InvokeMethod("RefreshBusComp");
throw(e);
}
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
outs = null;
ins = null;
txnSvc = null;
sProdId1 = null;
sPrdDesc = null;
sProdName = null;
sProdName1 = null;
sStaSet = null;
sReqGen = null;
sQuoteId = null;
oBCQuote = null;
sRetCan = null;
sStatus = null;
oBO = null;
WriteError = null;
sSerialized = null;//<jq487> added to accomodate defect 657
sQuoteNum = null;//<jq487> added to accomodate defect 657
sProdId = null;//<jq487> added to accomodate defect 657
sPickQuan = null;//<jq487> added to accomodate defect 657
sQuantQuoted = null;//<jq487> added to accomodate defect 657
aProdArr = null;
aQuotedQtyArr = null;
aAllocQtyArr = null;
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Quote to Order
UpdatePartTracker
function UpdatePartTracker(sQuoteNum)
{
// If the Quote is being revised, the existing Parts Tracker may already be in Ship Complete. If that is
// the case, and a new Parts Request is going to be created, then update the status to Partial Ship
// MJB CQ 4873
try {
TheApplication().Utility.logStack("UpdatePartTracker", this);
var IsActivityRec;
var oBO = TheApplication().GetBusObject("Action");
var oBCAction = oBO.GetBusComp("Action");
with(oBCAction) {
ActivateField("CMI Status");
ActivateField("Type");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Quote Number",sQuoteNum);
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker"));
ExecuteQuery(ForwardOnly);
IsActivityRec = FirstRecord();
TheApplication().Utility.logVars("Parts Tracker Found?", IsActivityRec);
if(IsActivityRec) {
SetFieldValue("CMI Status", TheApplication().InvokeMethod("LookupValue","EVENT_STATUS","Partial Ship"));
WriteRecord();
}//End of if(IsActivityRec)
}//End of with(oBCAction)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCAction = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote to Order
QuoteToOrder
function QuoteToOrder(sQuoteId)
{
/*CMI DBU:JQ487:19/Nov/2010: The Below function is used to Query on Order BC for the new Parts request
Order created and update few fields. This script also queries in OLI BC and checks for Write in Product
replacement with actual product sent by MW and also checks for Revision Delta changes.*/
try
{
TheApplication().Utility.logStack("QuoteToOrder", this);
//MJB I do not think this method is being used anymore. Adding raise error to see if anyone triggers
//it somewhere
TheApplication().RaiseErrorText("In QuoteToOrder method");
var oBO = TheApplication().ActiveBusObject();
var oBCOrder = oBO.GetBusComp("Order Entry - Orders");
var oBCOrderItem = oBO.GetBusComp("Order Entry - Line Items");
/*Commented by JQ487 as Signal changed */
//var sProdVal1 = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Product");
//var sProdVal2 = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Part");
var sProdVal3 = "Write-In Product";
var sBU = TheApplication().InvokeMethod("LookupValue", "CMI_BUSINESS_UNIT", "Distribution");
var sSubInv = TheApplication().InvokeMethod("LookupValue", "CMI_SUB_INVENTORY", "ServiceWIP");
var sLineType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Part Request Line");
var sSourceType = TheApplication().InvokeMethod("LookupValue", "CMI_QUOTE_SRC_TYPE", "STK");
with (oBCOrder)
{
SetViewMode(AllView);
ActivateField("Quote Id");
ActivateField("CMI Order Type");
ActivateField("Service Request Id");
ActivateField("CMI Business Unit");
ClearToQuery();
SetSearchSpec("Quote Id", sQuoteId);
ExecuteQuery(ForwardBackward);
//var iCount = CountRecords();
var sOrdId = GetFieldValue("Id");
/*Commented by JQ487 as Signal changed */
//var sOrdtype = TheApplication().InvokeMethod("LookupValue", "FS_ORDER_TYPE", "Parts Request");
//SetFieldValue("CMI Order Type", sOrdtype);
SetFieldValue("Service Request Id", sSRNum);
SetFieldValue("CMI Business Unit", sBU);
WriteRecord();
}
with (oBCOrderItem)
{
SetViewMode(AllView);
ActivateField("Order Header Id");
ActivateField("Product Id");
ActivateField("Product Type");
ActivateField("Product");
ActivateField("CMI Revise Flag");
ActivateField("Quantity Requested");
ActivateField("CMI Quantity Difference");
ActivateField("CMI Sub Inventory");
ActivateField("CMI Line Type");
ActivateField("CMI Source Type");
ActivateField("CMI Write In Error Flag");
ClearToQuery();
SetSearchSpec("Order Header Id", sOrdId);
ExecuteQuery(ForwardBackward);
//var iCount1 = CountRecords();
var isRec = FirstRecord();
while(isRec)
{
sProdType = GetFieldValue("Product Type");
sProdName = GetFieldValue("Product");
sRevFlg = GetFieldValue("CMI Revise Flag");
var sQty = GetFieldValue("Quantity Requested");
var sQtyCalc = GetFieldValue("CMI Quantity Difference");
SetFieldValue("CMI Sub Inventory", sSubInv);
SetFieldValue("CMI Line Type", sLineType);
SetFieldValue("CMI Source Type", sSourceType);
WriteRecord();
/*----------------comment out by jr418 on 15th Apr 2011------------------------------/
if(sProdName == sProdVal3)
{
sPrdDesc = GetFieldValue("Write-In Product");
ProductCheck(sPrdDesc);
var sPicklistProdBC = oBCOrderItem.GetPicklistBusComp("Product");
with(sPicklistProdBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sProdId1);
ExecuteQuery(ForwardBackward);
if(FirstRecord())
{
Pick();
}
}
if(WriteError == "Display")
{
SetFieldValue("CMI Write In Error Flag", "Y");
WriteRecord();
}
isRec = NextRecord();
}
/----------------comment out by jr418 on 15th Apr 2011------------------------------*/
// else
// {
if(sRevFlg == "Y")
{
/*Commented by JQ487 as Signal changed */
/*if((sProdType != sProdVal1) && (sProdType != sProdVal2))
{
DeleteRecord();
isRec = FirstRecord();
}
else*/
if ((sQty == sQtyCalc)||(sQtyCalc == ""))
{
DeleteRecord();
isRec = FirstRecord();
}
else
{
SetFieldValue("Quantity Requested", sQtyCalc);
SetFieldValue("CMI Revise Flag", "N");
WriteRecord();
isRec = NextRecord();
}
}
else
{
isRec = NextRecord();
}
// }
/*else
{
if((sProdType != sProdVal1) && (sProdType != sProdVal2))
{
DeleteRecord();
}
if((sProdType == sProdVal1) || (sProdType == sProdVal2))
{
isRec = NextRecord();
}
else
{
isRec = FirstRecord();
}
}*/
}
sReqGen = "Execute";
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCOrder = null;
oBCOrderItem = null;
oBO = null;
sOrdId = null;
//sOrdtype = null;
isRec = null;
sProdType = null;
sRevFlg = null;
//sProdVal1 = null;
//sProdVal2 = null;
sProdVal3 = null;
sSRNum = null;
sQuoteId = null;
sBU = null;
sQty = null;
sQtyCalc = null;
//sPicklistProdBC = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote to Order
CheckDate
function CheckDate(sQuoteId)
{
/*******************************************************************************************
Created By: JQ487
Created On: 2011-8-19
C&I Number: 4467
Enhancement#: S259
Functionality: This function checks if requested date on Parts Requested is >= current date
Then it maps Requested date on header and line items else it maps current date.
**********************************************************************************************/
try {
TheApplication().Utility.logStack("CheckDate", this);
var oBOOrder:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var oBCOrder:BusComp = oBOOrder.GetBusComp("Order Entry - Orders");
var oBCOrderItem:BusComp = oBOOrder.GetBusComp("Order Entry - Line Items");
var sDate:Date = new Date;
var sReqDate:Date = new Date;
var sReqDateLI:Date = new Date;
//storing current date in var
with (oBCOrder) {
SetViewMode(AllView);
ActivateField("Quote Id");
ActivateField("Requested Ship Date");
ClearToQuery();
SetSearchSpec("Quote Id", sQuoteId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
var sOrdId = GetFieldValue("Id");
// getting field value for requested date
sReqDate = new Date(GetFieldValue("Requested Ship Date"));
// loop to compare dates
TheApplication().Utility.logVars("Requested Date", sReqDate, "Today", sDate);
if(sReqDate >= sDate) {
SetFieldValue("Requested Ship Date", ToString(sReqDate.getMonth() + 1)+"/"+ToString(sReqDate.getDate())+"/"+ToString(sReqDate.getYear() + 1900));
} else {
SetFieldValue("Requested Ship Date", ToString(sDate.getMonth() + 1)+"/"+ToString(sDate.getDate())+"/"+ToString(sDate.getYear() + 1900));
}
WriteRecord();
with (oBCOrderItem) {
SetViewMode(AllView);
ActivateField("Requested Delivery Date");
ClearToQuery();
SetSearchSpec("Order Header Id", sOrdId);
ExecuteQuery(ForwardOnly);
var isRec:bool = FirstRecord();
while(isRec) {
// getting field value for requested date
sReqDateLI = new Date(GetFieldValue("Due Date"));
// loop to compare dates
TheApplication().Utility.logVars("Line Item Due Date", sReqDateLI);
if(sReqDateLI >= sDate) {
SetFieldValue("Due Date", ToString(sReqDateLI.getMonth() + 1)+"/"+ToString(sReqDateLI.getDate())+"/"+ToString(sReqDateLI.getYear() + 1900));
} else {
SetFieldValue("Due Date", ToString(sDate.getMonth() + 1)+"/"+ToString(sDate.getDate())+"/"+ToString(sDate.getYear() + 1900));
}
WriteRecord();
isRec = NextRecord();
}
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCOrderItem = null;
oBCOrder = null;
oBOOrder = null;
TheApplication().Utility.logUnstack();
}
}

CMI Quote to Order
GetItemQty
function GetItemQty(sProdId)
{
/*CMI DBU:JQ486:18/Apr/2011: The Below function is used to traverse through each non serialized product LI. */
try
{
TheApplication().Utility.logStack("GetItemQty", this);
var i = 0;
if(sProdId != null || sProdId != "") {
for(i = 0; i < aProdArr.length; i++) {
if(aProdArr[i] == sProdId) {
break;
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(i);
}
return i;
}

CMI Quote to Order
GetLineItemsInfo
function GetLineItemsInfo(sQuoteNum)
{
/*CMI DBU:JQ487:15/Apr/2011: The Below function is used to Query on Part Tracker BC to valdate that Picked Qty on
Part Tracker Record is Less than sum of Quoted Qty and Qty request on current revision. */
try {
TheApplication().Utility.logStack("GetLineItemsInfo", this);
var iCount = 0;
var IsActivityRec;
var IsPartTrackRec;
var oBO = TheApplication().GetBusObject("Action");
var oBCAction = oBO.GetBusComp("Action");
var oBCPartTracker = oBO.GetBusComp("FS Activity Parts Movement");
with(oBCAction) {
ActivateField("CMI Quote Number");
ActivateField("Type");
ActivateField("CMI Status");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Quote Number",sQuoteNum);
SetSearchSpec("Type", TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Parts Tracker"));
ExecuteQuery(ForwardOnly);
IsActivityRec = FirstRecord();
TheApplication().Utility.logVars("Activity Found?", IsActivityRec);
if(IsActivityRec) {
currentStatus = GetFieldValue("CMI Status");
with(oBCPartTracker) {
SetViewMode(AllView);
ActivateField("Product Name");
ActivateField("Product Id");
ActivateField("CMI Parts Allocated");
ActivateField("CMI Quoted Quantity");
ClearToQuery();
ExecuteQuery(ForwardOnly);
var sPCNextRecord = FirstRecord();
while(sPCNextRecord) {
//Implementing the array logic for performance tuning.By jq486.
aProdArr[iCount] = GetFieldValue("Product Id");
aQuotedQtyArr[iCount] = GetFieldValue("CMI Quoted Quantity");
aAllocQtyArr[iCount] = GetFieldValue("CMI Parts Allocated");
TheApplication().Utility.logVars(iCount+" - Product Id", aProdArr[iCount]);
iCount++;
sPCNextRecord = NextRecord();
}
}
}//End of while(IsActivityRec)
}//End of with(oBCAction)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCPartTracker = null;
oBCAction = null;
oBO = null;
TheApplication().Utility.logUnstack(currentStatus);
}
return(currentStatus);
}

CMI Quote to Order
(declarations)
//global declaration
var sSRNum;
var sProdType;
var sRevFlg;
var sReqGen;
var sRetCan;
var sProdId1;
var sPrdDesc;
var sProdName;
var sProdName1;
var sProdCategory;
var WriteError;
var sSerialized;//<jq487> added to accomodate defect 657
var sQuoteNum;//<jq487> added to accomodate defect 657
var sProdId;//<jq487> added to accomodate defect 657
var sPickQuan;//<jq487> added to accomodate defect 657
var sQuantQuoted;//<jq487> added to accomodate defect 657
//created arrays, performance tuning, By jq486.
var aProdArr = new Array;
var aQuotedQtyArr = new Array;
var aAllocQtyArr = new Array;
var currentStatus = "";

CMI RedirectView
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
// Added By <ko981> for <try catch block code review> on <06/12/2011>
try
{
if (MethodName == "HandleRedirection")
{
//Script added by IW160 for defect # 1084 to hide HomePage view for a Distributor and show teh SR view whiel login
var sBO = TheApplication().GetBusObject("Service Request");
TheApplication().GotoView("CMI Distributor Service Request List View", sBO);
return (CancelOperation);
}
else
}//end of try
catch(e)
{
throw e;
}//end of catch
return (ContinueOperation);
}

CMI Remove Warranty From LI
RemoveWarranty
function RemoveWarranty()
{
try
{
var sBO = TheApplication().ActiveBusObject();
var sQuoteBC = sBO.GetBusComp("Quote");
var sQuoteItemBC = sBO.GetBusComp("Quote Item");
var sWarrBC = sBO.GetBusComp("CMI Quote Item Warranty");
var QuoteId = sQuoteBC.GetFieldValue("Id");
var SRWarrId = sWarrBC.GetFieldValue("CMI SR Warranty Id");
var isRec;
var isWarrRec;
with(sQuoteItemBC)
{
SetViewMode("AllView");
ClearToQuery();
ActivateField("Quote Id");
SetSearchSpec("Quote Id", QuoteId);
ExecuteQuery(ForwardOnly);
isRec = FirstRecord();
while(isRec)
{
with(sWarrBC)
{
SetViewMode("AllView");
ClearToQuery();
ActivateField("CMI Quote Id");
ActivateField("CMI SR Warranty Id");
SetSearchSpec("CMI Quote Id", QuoteId);
SetSearchSpec("CMI SR Warranty Id", SRWarrId);
ExecuteQuery(ForwardOnly);
isWarrRec = FirstRecord();
if(isWarrRec)
{
DeleteRecord();
}
}
isRec = NextRecord();
}
}
}
catch(e)
{
throw(e);
}
finally
{
sWarrBC = null;
sQuoteItemBC = null;
sQuoteBC = null;
sBO = null;
}
}

CMI Remove Warranty From LI
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//try catch added by shanmukh for code clean up 08/20/2011
try
{
if(MethodName == "RemoveAllWarranty")
{
RemoveWarranty();
return(CancelOperation);
}
} //end oftry
catch(e)
{
if(defined(e.errText))
{
TheApplication().RaiseErrorText("An exception occurred in the " + this.Name() + " object. " + "Error is: " + e.toString() + " " + e.errText);
}
else
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
}//end of catch
}

CMI Reset Warranty Prices
CMIResetItemWarrantyPrices
function CMIResetItemWarrantyPrices(Inputs,Outputs)
{
//Reset Warranty Prices
try
{
//Capture Inputs
var sEntType=Inputs.GetProperty("CMI Entity Type");
var sLineItemId=Inputs.GetProperty("CMI Line Item Id");
var sProdType=Inputs.GetProperty("CMI Product Type");
var oLIBO;
var oLIBC;
var oWarrBC;
var bWarrExists;
var sBS;
var sIP;
var sOP;
//Check if all the inputs are provided.
if (sEntType != "" && sEntType != null && sLineItemId != "" && sLineItemId != null && sLineItemId != "" && sLineItemId != null)
{
if (sEntType == "Quote" && (sProdType == "Part" || sProdType == "Labor" || sProdType == "Misc"))
{
//Create the LI and Warranty objects
oLIBO =TheApplication().GetBusObject("CMI Quote Item Warranty");
oLIBC =oLIBO.GetBusComp("Quote Item");
oWarrBC=oLIBO.GetBusComp("CMI Quote Item Warranty");
}
else if (sEntType == "Order" && (sProdType == "Part" || sProdType == "Labor" || sProdType == "Misc"))
{
//Create the LI and Warranty objects
oLIBO =TheApplication().GetBusObject("CMI Order Item Warranty");
oLIBC =oLIBO.GetBusComp("Order Entry - Line Items");
oWarrBC=oLIBO.GetBusComp("CMI Order Line Item Warranty");
}
else
{
return(CancelOperation);
}
with (oLIBC)
{
//Query the Line Item
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sLineItemId);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
//Query the warranties and blank out the Prices
with (oWarrBC)
{
ActivateField("CMI Warranty Price");
ClearToQuery();
ExecuteQuery(ForwardOnly);
bWarrExists=FirstRecord();
while (bWarrExists)
{
SetFieldValue("CMI Warranty Price","");
WriteRecord();
bWarrExists=NextRecord();
}
// Outputs.SetProperty("CMI Error Message","");
}
//to Refresh the Quote Item Applet - jw918 14.04.11
sBS = TheApplication().GetService("SIS OM PMT Service");
sIP = TheApplication().NewPropertySet();
sOP = TheApplication().NewPropertySet();
sIP.SetProperty("Business Object Name",oLIBO.Name());
sIP.SetProperty("Business Component Name",oLIBC.Name());
sBS.InvokeMethod("Refresh Business Component",sIP,sOP);
}//end if
}//end with(oLIBC)
}//end of if
}//end of try
catch (e)
{
// Outputs.SetProperty("CMI Error Message",e.toString());
throw e;
}
finally
{
sOP = null;
sIP = null;
sBS = null;
oLIBO=null;
oLIBC=null;
oWarrBC=null;
sEntType="";
sLineItemId="";
sProdType="";
}
}

CMI Reset Warranty Prices
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
//Reset Warranty BS Method
if(MethodName == "CMIResetWarrantyPrices")
{
//Reset Warranty prices for all warranties within the line item
CMIResetItemWarrantyPrices(Inputs,Outputs);
return (CancelOperation);
}
return (ContinueOperation);
}
catch (e)
{
throw e;
}
finally
{
}
}

CMI Rev Quote Update Part Activity
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : Rohit Anchi
Created On : 4th Oct 2011
Method Name: function (MethodName) == "UpdateActivity"
Functionality: This method will update Quote Id of Action BC when Quote (Revised) Status change to "Accepted"
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if(MethodName == "UpdateActivity") {
var oQuoteBO = TheApplication().GetBusObject("Quote");
var oQuoteBC = oQuoteBO.GetBusComp("Quote");
var oActionBO = TheApplication().GetBusObject("Action");
var oActionBC = oActionBO.GetBusComp("Action");
var statusLost:String = TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Lost");
var statusCancelled:String = TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Cancelled");
var statusAlternative:String = TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Alternative Quote Selected");
var sRevQId = TheApplication().GetProfileAttr("pfRevQId");
var sSRId = "";
var sQuoteId = "";
var sQNum = "";
var sAccountId = "";
if(sRevQId != "") {
with(oQuoteBC) {
ClearToQuery();
ActivateField("Account Id");
SetViewMode(AllView);
SetSearchSpec("Id", sRevQId);
ExecuteQuery(ForwardBackward);
var iRec1 = FirstRecord();
TheApplication().Utility.logVars("Revised Quote ("+sRevQId+") Found?", iRec1);
if(iRec1) {
sSRId = GetFieldValue("Service Request Id");
sQuoteId = GetFieldValue("Id");
sQNum = GetFieldValue("Quote Number");
sAccountId = GetFieldValue("Account Id");
}
}
//Reassociate all non cancelled activities for this quote (identified by having same Quote #) under this SR to the Accepted Quote
with(oActionBC) {
ClearToQuery();
SetViewMode(AllView);
ActivateField("CMI Quote Status");
ActivateField("Status");
SetSearchSpec("Activity SR Id", sSRId);
SetSearchSpec("CMI Quote Number", sQNum);
SetSearchSpec("Status", "<> "+TheApplication().InvokeMethod("LookupValue","EVENT_STATUS","Cancelled"))
//SetSearchSpec("Type", "Parts Tracker");//CMI <Release# 1DBU>,C&I# 4467Enhancement# S124<Configuration>: <commented search spec as all activities needs to be associated to quote> By JQ487 On 11/04/11
ExecuteQuery(ForwardBackward);
var iRec2 = FirstRecord();
while(iRec2) {
var sQid = GetFieldValue("Quote Id");
var sQuoteSta = GetFieldValue("CMI Quote Status");
TheApplication().Utility.logStep("Process Activity ("+GetFieldValue("Id")+") - Quote ("+sQid+") Status: "+sQuoteSta);
if((sQuoteSta != statusLost) && (sQuoteSta != statusCancelled) && (sQuoteSta != statusAlternative)) {
if(sQid != sQuoteId) {
SetFieldValue("Quote Id", sQuoteId);
//If the Account on the new revision has changed since the previous revision, the account on the service activities
//should be updated as well
if (sAccountId != GetFieldValue("Account Id")) {
TheApplication().Utility.logVars("Old / New Account Id", sAccountId+" / " + GetFieldValue("Account Id"));
SetFieldValue("Account Id", sAccountId);
}
WriteRecord();
}
}
iRec2 = NextRecord();
}
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sQNum = null;
sQid = null;
sSRId = null;
sRevQId = null;
oActionBC = null;
oActionBO = null;
oQuoteBC = null;
oQuoteBO = null;
TheApplication().SetProfileAttr("pfRevQId",null);
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI SR Add Quote Template to Quote
ValidateWarranty
function ValidateWarranty(sFieldName) {
/*Created By : KS988, Purnima Aashri
Created On : 03-JAN-20112
Method Name: ValidateWarranty
Defect Number: DBUNG00001037
Functionality: This functions hard stops the user to enter the warranties whose sum is more than 100.
*/
try {
TheApplication().Utility.logStack("ValidateWarranty", this);
var sTemp;
var oBO:BusObject = TheApplication().ActiveBusObject();
TheApplication().Utility.logVars("Active BO", oBO.Name());
if(oBO.Name() =="Service Request") {
var oBCSRWar:BusComp = oBO.GetBusComp("CMI Service Request Warranty");
var sObjId:String = oBCSRWar.GetFieldValue("Id");
var sWarPercent = ToNumber(oBCSRWar.GetFieldValue(sFieldName));
var sWarSRId:String = oBCSRWar.GetFieldValue("CMI Parent SR Id");
var oSRBusobject:BusObject = TheApplication().GetBusObject("Service Request");
var oBCSRWarranty:BusComp = oSRBusobject.GetBusComp("CMI Service Request Warranty");
var sSearchExpr:String = "[CMI Parent SR Id] = '" + sWarSRId + "' AND [Id] <> '" + sObjId + "'";
var iWarSum = ToNumber(sWarPercent);
var iDefPercent = 0;
var hasRecord;
with(oBCSRWarranty) {
SetViewMode(AllView);
ActivateField(sFieldName);
ClearToQuery();
SetSearchExpr(sSearchExpr);
ExecuteQuery(ForwardOnly);
hasRecord = FirstRecord();
while(hasRecord) {
iDefPercent = ToNumber(GetFieldValue(sFieldName));
iWarSum = iWarSum + iDefPercent;
hasRecord = NextRecord();
}
}
TheApplication().Utility.logVars("Warranty Sum", iWarSum);
if(iWarSum > 100) {
if(sFieldName == "CMI Default Labor Percentage") {
TheApplication().RaiseErrorText("Sum of Labor Warranty % should not be greater than 100");
} else if(sFieldName == "CMI Default Part Percentage") {
TheApplication().RaiseErrorText("Sum of Part Warranty % should not be greater than 100");
} else if(sFieldName == "CMI Default Misc Percentage") {
TheApplication().RaiseErrorText("Sum of Misc Warranty % should not be greater than 100");
}
}//If closes here
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
sFieldName=null;
oBCSRWar=null;
sWarPercent=null;
sWarSRId=null;
oSRBusobject=null;
oBCSRWarranty=null;
sSearchExpr=null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI SR Add Quote Template to Quote
CascadeWarranty
function CascadeWarranty()
{
try {
TheApplication().Utility.logStack("CascadeWarranty", this);
var oBO = TheApplication().ActiveBusObject();// SR in this case
var oBCQuote = oBO.GetBusComp("Quote");
var SRId = oBCQuote .GetFieldValue("Service Request Id");
var OBCQuoteItem = oBO.GetBusComp("Quote Item");
var oBCSRWarranty = oBO.GetBusComp("CMI Service Request Warranty");
var IsSRWarrantyRec;
var sProductType;
var DefPartPercent;
var DefLaborPercent;
var DefMiscPercent;
var quoteRecord = oBCQuote.FirstSelected();
while(quoteRecord) {
var QuoteId = oBCQuote.GetFieldValue("Id");
TheApplication().Utility.logStep("Apply default warranty to quote ("+QuoteId+")");
with(oBCSRWarranty) {
SetViewMode(AllView);
ActivateField("CMI Default Part Percentage");
ActivateField("CMI Default Labor Percentage");
ActivateField("CMI Default Misc Percentage");
ActivateField("CMI Warranty Price");
ActivateField("CMI Labor Rate");
ClearToQuery();
SetSearchSpec("CMI Parent SR Id", SRId);
ExecuteQuery(ForwardBackward);
IsSRWarrantyRec = FirstRecord();
TheApplication().Utility.logVars("Warranty Found?", IsSRWarrantyRec);
while(IsSRWarrantyRec) {
var WarrantyId = GetFieldValue("Id");
DefPartPercent = GetFieldValue("CMI Default Part Percentage");
DefLaborPercent = GetFieldValue("CMI Default Labor Percentage");
DefMiscPercent = GetFieldValue("CMI Default Misc Percentage");
TheApplication().Utility.logVars("Default Labor/Part/Misc %", DefLaborPercent+" / "+DefPartPercent+" / "+DefMiscPercent);
if(DefLaborPercent != "" && DefLaborPercent != null)
if (ToNumber(DefLaborPercent) > 0 ){
sProductType = "Labor";
AssociateWarantyToLI(oBCSRWarranty , OBCQuoteItem ,QuoteId, WarrantyId, sProductType);
}
if((DefPartPercent != "") && (DefPartPercent != null))
if (ToNumber(DefPartPercent) > 0){
sProductType = "Part";//this is set back to null in finally for the function called below
AssociateWarantyToLI(oBCSRWarranty , OBCQuoteItem ,QuoteId, WarrantyId, sProductType);
}
if(DefMiscPercent != "" && DefMiscPercent != null)
if(ToNumber(DefMiscPercent) > 0) {
sProductType = "Misc";
AssociateWarantyToLI(oBCSRWarranty , OBCQuoteItem ,QuoteId, WarrantyId, sProductType);
}
IsSRWarrantyRec = NextRecord();
}//End of while
ClearToQuery();
ExecuteQuery();
}//End of with
quoteRecord = oBCQuote.NextSelected();
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
oBCSRWarranty = null;
OBCQuoteItem = null;
oBCQuote = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}//end of function

CMI SR Add Quote Template to Quote
RemoveSelectedWarranty
function RemoveSelectedWarranty(quoteItemId, warrantyId)
{
try {
TheApplication().Utility.logStack("RemoveSelectedWarranty", this, false);
var oBO = TheApplication().ActiveBusObject();// SR in this case
var oBCQIW = oBO.GetBusComp("CMI Quote Item Warranty");
with(oBCQIW) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Parent Id", quoteItemId);
SetSearchSpec("CMI SR Warranty Id", warrantyId);//Added by jj953 on Jun 30 2011
ExecuteQuery(ForwardBackward);
var deleteWarranty = FirstRecord();
if(deleteWarranty) {
TheApplication().Utility.logStep("RemoveSelectedWarranty.Id: "+GetFieldValue("Id"));
DeleteRecord();
}
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
oBCQIW = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI SR Add Quote Template to Quote
CreateFailureCode
//pankaj - function to failure code assosciated to the template if it is already not associated to SR
function CreateFailureCode(sFailCdId, sSRID) {
try {
TheApplication().Utility.logStack("CreateFailureCode", this);
var sFailBO = TheApplication().GetBusObject("CMI SR Failure Code BO");
var sFailBC = sFailBO.GetBusComp("CMI SR Failure Code");
var isRec;
var sFailPickBC;
var isPickBCRec;
with(sFailBC) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Parent SR Id", sSRID);
SetSearchSpec("CMI Failure Id", sFailCdId);
ExecuteQuery(ForwardOnly);
isRec = FirstRecord();
TheApplication().Utility.logVars("Failure Code Found?", isRec);
if(!isRec) {
NewRecord(NewAfter);
//sFailPickBC = sFailBC.GetPicklistBusComp("CMI Name");
sFailPickBC = sFailBC.GetPicklistBusComp("CMI Failure Description");//<JQ487> <Changed PickListBusComp to Failure Description>
with(sFailPickBC) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sFailCdId);
ExecuteQuery(ForwardOnly);
isPickBCRec = FirstRecord();
if(isPickBCRec) {
Pick();
}
}
SetFieldValue("CMI Parent SR Id", sSRID);
WriteRecord();
}
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
sFailPickBC = null;
sFailBC = null;
sFailBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI SR Add Quote Template to Quote
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs) {
/*********************************************************
AUTHOR: Anand Shanmugam - Oracle Corporation
DESCRIPTION: The Business Service adds the line item from Quote template to the Quote Selected by the User
OUTPUTS: None
DATE CREATED: 3/3/2010
*********************************************************/
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retValue = CancelOperation;
var bcQuoteItem:BusComp;
var bcOrderItem:BusComp;
switch(MethodName) {
case "AddQuoteTemplate":
AddQuoteTemplate(Inputs, Outputs);
break;
case "RemoveAllWarranty":
RemoveWarranty();
break;
case "ValidateWarranty":
var context:String = Inputs.GetProperty("Context");
ValidateWarranty(context);
break;
case "UpdateQIFields":
bcQuoteItem = TheApplication().ActiveBusObject().GetBusComp("CMI Quote Item Warranty").ParentBusComp();
if (bcQuoteItem != null && defined(bcQuoteItem)) {
UpdateQIFields(bcQuoteItem);
}
break;
//Added to apply warranty in Order Line Item level, CR# CRQ000000112386
case "UpdateOIFields":
bcOrderItem = TheApplication().ActiveBusObject().GetBusComp("CMI Order Line Item Warranty").ParentBusComp();
if (bcOrderItem != null && defined(bcOrderItem))
{
UpdateOIFields(bcOrderItem);
}
break;
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
bcQuoteItem = null;
TheApplication().Utility.logUnstack(retValue);
}
return (retValue);
}

CMI SR Add Quote Template to Quote
UpdateOIFields
function UpdateOIFields(currentOrderItem)//Added Method to apply warranty on Order Line Item Level CR# CRQ000000112386
{
try
{
TheApplication().Utility.logStack("UpdateOIFields", this, false);
var boOrder = TheApplication().GetBusObject("Order Entry - Orders");
var bcOrderItem = boOrder.GetBusComp("Order Entry - Line Items");
if (currentOrderItem != null)
{
var orderItemId = currentOrderItem.GetFieldValue("Id");
//Requery for the line so the calculated sum fields will get the current values after the child is committed
with (bcOrderItem)
{
ActivateField("CMI Warranty Discount - Calc");
ActivateField("CMI Total Extended Price - Calc");
ActivateField("CMI Non Internal Warranty Percentage - Calc");
ClearToQuery();
SetSearchSpec("Id", orderItemId);
ExecuteQuery(ForwardBackward);
var found = FirstRecord();
if (found)
{
var sumDiscount = GetFieldValue("CMI Warranty Discount - Calc");
var sumExtPrice = GetFieldValue("CMI Total Extended Price - Calc");
var sumVendorDiscount = GetFieldValue("CMI Non Internal Warranty Percentage - Calc");
//Set fields on Active instantiation with Parent active to trigger OM Pricing Signal
currentOrderItem.SetFieldValue("CMI Warranty Discount", sumDiscount);
currentOrderItem.SetFieldValue("CMI Total Extended Price", sumExtPrice);
currentOrderItem.SetFieldValue("CMI Non Internal Warranty Percentage", sumVendorDiscount);
currentOrderItem.WriteRecord();
}
}
}
}
catch (e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
bcOrderItem = null;
boOrder = null;
TheApplication().Utility.logUnstack();
}
}

CMI SR Add Quote Template to Quote
UpdateQIFields
function UpdateQIFields(currentQuoteItem)
{
try {
TheApplication().Utility.logStack("UpdateQIFields", this, false);
var boQuote = TheApplication().GetBusObject("Quote");
var bcQuoteItem = boQuote.GetBusComp("Quote Item");
if(currentQuoteItem != null) {
var quoteItemId = currentQuoteItem.GetFieldValue("Id");
//Requery for the line so the calculated sum fields will get the current values after the child is committed
with (bcQuoteItem) {
ActivateField("CMI Warranty Discount - Calc");
ActivateField("CMI Total Extended Price - Calc");
ActivateField("CMI Non Internal Warranty Percentage - Calc");
ClearToQuery();
SetSearchSpec("Id", quoteItemId);
ExecuteQuery(ForwardBackward);
var found = FirstRecord();
if (found) {
var sumDiscount = GetFieldValue("CMI Warranty Discount - Calc");
var sumExtPrice = GetFieldValue("CMI Total Extended Price - Calc");
var sumVendorDiscount = GetFieldValue("CMI Non Internal Warranty Percentage - Calc");
//Set fields on Active instantiation with Parent active to trigger OM Pricing Signal
currentQuoteItem.SetFieldValue("CMI Warranty Discount", sumDiscount);
currentQuoteItem.SetFieldValue("CMI Total Extended Price", sumExtPrice);
currentQuoteItem.SetFieldValue("CMI Non Internal Warranty Percentage", sumVendorDiscount);
currentQuoteItem.WriteRecord();
}
}
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
bcQuoteItem = null;
boQuote = null;
TheApplication().Utility.logUnstack();
}
}

CMI SR Add Quote Template to Quote
UpdateQuantity
//Added by JX050 for defect 353 - function to update quantity or SRT Quantity if Line Item Already exist in Quote.
function UpdateQuantity(QuoteIdReq,Prodid,Quantityhv,ProdType,SRTQuantity,SRTId, FKName, FKId)
{
try {
TheApplication().Utility.logStack("UpdateQuantity", this);
var oBO = TheApplication().ActiveBusObject();
var oBC = oBO.GetBusComp("Quote Item (Simple)");
var Qty;
var NQty;
var prodTypeProduct = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Product");
var prodTypePart = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Part");
var prodTypeLabor = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
var prodTypeMisc = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Misc");
with(oBC) {
SetViewMode(AllView);
ActivateField("Product Type");
ActivateField("Quantity Requested");
ActivateField("CMI SRT Quantity");
ActivateField("Quantity Requested Cal");
ActivateField("CMI SRT Hours");
ActivateField("CMI SRT Id");
ActivateField("CMI Markup Multiplier");//CMI <Release# 3DBU>,C&I# 4466Enhancement#S148 <Configuration>:<activated field for CMI Markup Multiplier> By <ko874> On <10/10/2011>
ActivateField("Covered Quote Item Id");
ClearToQuery();
SetSearchSpec("Quote Id",QuoteIdReq);
SetSearchSpec("Product Id",Prodid);
//Since recon clean/dirty cores have the same product id, differentiate the records using the FKs
if (FKName != "") SetSearchSpec(FKName, FKId);
ExecuteQuery(ForwardBackward)
var isRec = FirstRecord();
while(isRec) {
var txnProdType = GetFieldValue("Product Type");
var coveredItemId = GetFieldValue("Covered Quote Item Id");
var parentItemId = GetFieldValue("Parent Quote Item Id");
TheApplication().Utility.logStep(txnProdType+" - Parent/Covered Line: "+parentItemId+"/"+coveredItemId);
//Preexisting parts just need their quantity updated by adding the template quantity
if((txnProdType == prodTypeProduct)||(txnProdType == prodTypePart)||(txnProdType == prodTypeMisc)) {
Qty = GetFieldValue("Quantity Requested");
NQty = ToNumber(Quantityhv) + ToNumber(Qty);
SetFieldValue("Quantity Requested",NQty);
WriteRecord();
lineQtyUpdated = true;
//Labor lines need their SRT fields incremented as well
} else if (txnProdType == prodTypeLabor) {
var SRTId1 = GetFieldValue("CMI SRT Id");
Qty = GetFieldValue("CMI SRT Quantity");
var SRTHr = GetFieldValue("CMI SRT Hours");
var sMarkMul = GetFieldValue("CMI Markup Multiplier"); //CMI <Release# 3DBU>,C&I# 4466Enhancement#S148 <Configuration>:<getting field value for CMI Markup Multiplier> By <ko874> On <10/10/2011>
if((SRTId1 != "NULL") && (SRTId1 != "")) {
if(SRTId1 == SRTId) {
NQty = ToNumber(SRTQuantity) + ToNumber(Qty);
SetFieldValue("CMI SRT Quantity",NQty);
//var QtyReq1 = GetFieldValue("Quantity Requested Cal");
var QtyReq1 = NQty * ToNumber(SRTHr);
var sQuanReq:Number = ((QtyReq1)*(1+(ToNumber(sMarkMul)/100))); //CMI <Release# 3DBU>,C&I# 4466Enhancement#S148 <Configuration>:<added new conditon for CMI Markup Multiplier> By <ko874> On <10/10/2011>
SetFieldValue("Quantity Requested", QtyReq1);
WriteRecord();
lineQtyUpdated = true;
}
}
}
isRec = NextRecord();
}
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
oBC = null;
oBO = null;
TheApplication().Utility.logUnstack(lineQtyUpdated);
}
}

CMI SR Add Quote Template to Quote
AssociateWarantyToLI
function AssociateWarantyToLI(oBCSRWarranty,OBCQuoteItem,QuoteId,WarrantyId,sProductType)
{
try {
TheApplication().Utility.logStack("AssociateWarantyToLI", this);
var sType = sProductType;
var sSrchExpr;
var sParentExpr;
var sType1;
var IsQLIRec;
var IsWarrRec;
var oBO = TheApplication().ActiveBusObject(); // Defect 4574: .GetBusObject("Quote");
var bcQIWarranty = oBO.GetBusComp("CMI Quote Item Warranty");
//<Fix DBUNG00001097, SR warranty allocation under Quote Parts view should be "Product Type <> "Labor" AND Product Type <> "Misc"". Add by JR419 on 21-Jul-2011.>
var sProdLabor = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
var sProdMisc = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Misc");
var sReconType = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Line type");
var sReconReturnType = TheApplication().InvokeMethod("LookupValue","CMI_LINE_TYPE","Recon Return Line type");
if (sType == "Part") {
sSrchExpr = "[Quote Id] = '" + QuoteId + "' AND ([Product Type] <> '" + sProdLabor + "' AND [Product Type] <> '" + sProdMisc + "')";
} else {
sSrchExpr = "[Quote Id] = '" + QuoteId + "' AND [Product Type] = '" + sType + "' ";//<JQ486: Added code>
}
// Release # 2 : PRCR:DBUNG00003977 : Added by jw920 as 'Customer down/Economy' Product are not able to find by this searchspec in BO:'Service Request' & BC:'Quote Item' on 12/12/2011
var deleteWarranty = false;
with(OBCQuoteItem) {
SetViewMode(AllView);
ActivateField("Product Type");
ActivateField("CMI Line Type");
ActivateField("Currency Code");//<JQ487><Added code as per GL Interface Currency conversion FS.>
ActivateField("Exchange Date");//<JQ487><Added code as per GL Interface Currency conversion FS.>
ActivateField("CMI Net Price Calc Flag");//Added by jq486 on 27 May 2011 to trigger the net price discounting calculation post warranty update.
ClearToQuery();
SetSearchExpr(sSrchExpr);//<JQ486:Added Code>
ExecuteQuery(ForwardBackward);
IsQLIRec = FirstRecord();//<IY795><29-Jul-2011><Added semicolon for this statement>
TheApplication().Utility.logVars("First Line Found?", IsQLIRec);
while(IsQLIRec) {
var sLineType = GetFieldValue("CMI Line Type");
var QLIId = GetFieldValue("Id");
var lineNumber = GetFieldValue("Line Number");
sType1 = GetFieldValue("Product Type");
var sCur = GetFieldValue("Currency Code");//<JQ487><Added code as per GL Interface Currency conversion FS.>
var sExDate = GetFieldValue("Exchange Date");//<JQ487><Added code as per GL Interface Currency conversion FS.>
//Profile Attr set by Km326 on 19-01-2012 by KM326 to fix bug 4763
TheApplication().SetProfileAttr("isDefaultWarranty", "Y");
TheApplication().Utility.logStep("Process "+sType+" "+lineNumber+" ("+QLIId+") Line Type/Part Type: "+sLineType+" / "+sType1);
if(sLineType == "" || (sLineType != sReconType && sLineType != sReconReturnType)) {
//Remove the warranty if it already exists
RemoveSelectedWarranty(QLIId, WarrantyId)
bcQIWarranty.NewRecord(NewAfter);
bcQIWarranty.SetFieldValue("Parent Id", QLIId);
bcQIWarranty.SetFieldValue("CMI Currency Code", sCur);//<JQ487><Added code as per GL Interface Currency conversion FS.>
bcQIWarranty.SetFieldValue("CMI Exchange Date", sExDate);//<JQ487><Added code as per GL Interface Currency conversion FS.>
if(sType == "Labor") {
bcQIWarranty.SetFieldValue ("CMI Percent Covered", oBCSRWarranty.GetFieldValue("CMI Default Labor Percentage"));
bcQIWarranty.SetFieldValue ("CMI SR Warranty Id", WarrantyId);
} else if(sType == "Misc") {
bcQIWarranty.SetFieldValue ("CMI Percent Covered", oBCSRWarranty.GetFieldValue("CMI Default Misc Percentage"));
bcQIWarranty.SetFieldValue ("CMI SR Warranty Id", WarrantyId);
} else {
bcQIWarranty.SetFieldValue ("CMI Percent Covered", oBCSRWarranty.GetFieldValue("CMI Default Part Percentage"));
bcQIWarranty.SetFieldValue ("CMI SR Warranty Id", WarrantyId);
}
bcQIWarranty.WriteRecord();
UpdateQIFields(OBCQuoteItem);
}
IsQLIRec = NextRecord();
}//End of While
}//End of With
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().SetProfileAttr("isDefaultWarranty", "");
sProductType = null;
bcQIWarranty = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}//End of function

CMI SR Add Quote Template to Quote
AddQuoteTemplate
function AddQuoteTemplate(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("AddQuoteTemplate", this);
var strSearchOLI;
var newParent = "";
var FKName = "";
//Use profile attribute instead of Application method name as part of the Code Clean Up Activity
var ActiveViewName = TheApplication().GetProfileAttr("ActiveViewName");
var iMaxLineNumber = 0;
var newQuote = (TheApplication().GetProfileAttr("QuoteTemplateName") == "" ? false : true);
var templateName = TheApplication().GetProfileAttr("QuoteTemplateName");
var sQuoteTemplateId = "";
var validateSRT = false;
TheApplication().Utility.logVars("Active View", ActiveViewName);
if(ActiveViewName == "CMI Service Request Warranty View") {
ValidateSRWarranty();//Fix <DBUNG00001037>, added by <JR419> on <03-Aug-2011>
CascadeWarranty();
} else if (templateName == "^") {
//If it is a new quote but the Job Type is blank, this variable is set to skip the routine
//Do Nothing
} else {
var boActive = TheApplication().ActiveBusObject();
var bcQuote = boActive.GetBusComp("Quote");
var sValid;
var prodTypeProduct = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Product");//Added by JX050 for defect 353
var prodTypePart = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Part"); //Added by JX050 for defect 353
var prodTypeLabor = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");//Added by JX050 for defect 353
var prodTypeMisc = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Misc");//Added by JX050 for defect 353
TheApplication().Utility.logVars("New Quote/Template", newQuote+" / "+templateName);
if (newQuote == false) {
var bcActiveTemplate:BusComp;
//Get the id of the selected template record
if (TheApplication().ActiveViewName() == "CMI SR Failure Code Quote Template View") {
bcActiveTemplate = boActive.GetBusComp("Quote Template");
} else {
bcActiveTemplate = boActive.GetBusComp("CMI Quote Template");
}
sQuoteTemplateId = bcActiveTemplate.GetFieldValue ("Id");
var sFailCdId = bcActiveTemplate.GetFieldValue("CMI Failure Id");
}
//Get the values of Quote Header fields that will need to be cascaded to child records after being copied from the template
//These fields are all Force Active or Link Specs
var sPickQuoteId = bcQuote.GetFieldValue("Id");
var sDueDate = bcQuote.GetFieldValue("Requested Ship Date");
var sLocId = bcQuote.GetFieldValue("Source Inventory Location Id");
var sCurcyCd = bcQuote.GetFieldValue("Currency Code");
var sQuoteAccCd = bcQuote.GetFieldValue("CMI Asset Access Code");
var sShipAcId = bcQuote.GetFieldValue("Ship To Account Id");
var sShipAddrId = bcQuote.GetFieldValue("CMI Ship To Address Id");
var sShipProfId = bcQuote.GetFieldValue("CMI Ship To Profile Id");
var sCarCode = bcQuote.GetFieldValue("Carrier Code");
var sCarPri = bcQuote.GetFieldValue("Carrier Priority");
var sPriceList = TheApplication().GetProfileAttr("Price List");
TheApplication().Utility.logId("Quote", sPickQuoteId);
TheApplication().Utility.logVars("Quote Id", sPickQuoteId);
//Instantiate the SR either from the active object or by querying for it to retrieve SR attributes that will be needed later
var sSRsubtype:String = "";
var sSRProdLine:String = "";
var sSRAccessCode:String = "";
var sSerReqId:String = "";
var boSR:BusObject = TheApplication().GetBusObject("Service Request");
var bcSR:BusComp;
if (boActive.Name() == "Service Request") {
bcSR = boActive.GetBusComp("Service Request");
with (bcSR) {
try {
sSerReqId = GetFieldValue("Id");
sSRsubtype = GetFieldValue("Sub Type");
sSRProdLine = GetFieldValue("CMI Product Line Name");
sSRAccessCode = GetFieldValue("CMI SR Access Code");
TheApplication().Utility.logVars("Active SR Id", sSerReqId);
} catch(e) {
//If no record is in focus an error would occur.
}
}
}
if (sSerReqId == "") {
bcSR = boSR.GetBusComp("Service Request");
sSerReqId = bcQuote.GetFieldValue("Service Request Id");
with (bcSR) {
SetViewMode(AllView);
ActivateField("CMI SR Access Code");
ClearToQuery();
SetSearchSpec("Id",sSerReqId);
ExecuteQuery(ForwardOnly);
var isRec = FirstRecord();
TheApplication().Utility.logVars("SR ("+sSerReqId+") found?", isRec);
if (isRec) {
sSRsubtype = GetFieldValue("Sub Type");
sSRProdLine = GetFieldValue("CMI Product Line Name");
sSRAccessCode = GetFieldValue("CMI SR Access Code");
}//end if
}//end with(oBCSR)
}
//For New Quotes, only continue if not a Respec
TheApplication().Utility.logVars("SR Sub Type", sSRsubtype);
if (sSRsubtype != "Respec" || newQuote == false) {
//If Quote status is not In Progress, revise it to make it editable and use the revision instead
var sStatus = bcQuote.GetFieldValue("Status");
TheApplication().Utility.logVars("Quote Status", sStatus);
if(sStatus != TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "In Progress")) {
bcQuote.InvokeMethod("ReviseCopyQuote");
sPickQuoteId = bcQuote.GetFieldValue("Id");
}
//If not for a new quote, get the maximum line number so new lines will have next highest number
if (newQuote == false) {
var bcQuoteItem = boActive.GetBusComp("Quote Item");
with (bcQuoteItem) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Quote Id",sPickQuoteId);
SetSortSpec("Line Number(DESCENDING)");
ExecuteQuery(ForwardOnly);
var isRecordPickQuoteItem = FirstRecord();
TheApplication().Utility.logVars("Item for Quote ("+sPickQuoteId+") Found?", isRecordPickQuoteItem);
if (isRecordPickQuoteItem) {
iMaxLineNumber = ToNumber(GetFieldValue("Line Number"));
if (iMaxLineNumber == 0 ) {
iMaxLineNumber = CountRecords();
}
}
}
}
//Query for the Quote Template, loop through each line, copy the line, then reassociate the copied line to the target quote
//Update and cascaded fields from the target quote header
var boQuoteTemplate = TheApplication().GetBusObject("CMI Quote");
var bcQuoteTemplate = boQuoteTemplate.GetBusComp("CMI Quote Simple");
var bcQuoteTemplateItem = boQuoteTemplate.GetBusComp("CMI Quote Item Lite");
var iProcessed = 0;
with (bcQuoteTemplate) {
SetViewMode(AllView);
ClearToQuery();
//If a new quote, search by template name otherwise by the id of the template record in focus
if (templateName == "") SetSearchSpec("Id",sQuoteTemplateId);
else {
SetSearchSpec("Name",templateName);
SetSearchSpec("CMI Template Flag", "Y");
}
ExecuteQuery(ForwardOnly);
var isRecord = FirstRecord();
}
TheApplication().Utility.logVars("Template Id/Name/Found?", sQuoteTemplateId+" / "+templateName+" / "+isRecord);
if (isRecord) {
with (bcQuoteTemplateItem) {
SetViewMode(AllView);
ActivateField("CMI Unit of Measure");
ActivateField("Unit of Measure");
ActivateField("Product Id");//Added by JX050 for defect 353
ActivateField("Quantity Requested");//Added by JX050 for defect 353
ActivateField("CMI SRT Quantity");//Added by JX050 for defect 353
ActivateField("Product Type");//Added by JX050 for defect 353
ActivateField("CMI Serialized Flag");//Added by JX050 for defect 353
ActivateField("CMI SRT Id");//Added by JX050 for defect 353
ActivateField("Line Number");
ActivateField("Requested Delivery Date");
ActivateField("Source Inventory Location Id");
ActivateField("Quote Id");
ActivateField("CMI Work Sequence");
ActivateField("Currency Code");
ActivateField("Ship To Account Id");
ActivateField("Ship To Address Id");
ActivateField("CMI Ship To Profile Id");
ActivateField("Revised Line Item Id");
ActivateField("Carrier Code");
ActivateField("Shipping Method");
ActivateField("Covered Quote Item Id");
ActivateField("CMI Prior Qty"); //By JQ487 Added for fixnig defect 5459 on 02/08/2012
ActivateField("CMI Today");
SetSearchSpec("Quote Id",sQuoteTemplateId);
SetSortSpec("Line Number(DESCENDING)");
ClearToQuery();
ExecuteQuery(ForwardBackward);
var isRecord1 = FirstRecord();
TheApplication().Utility.logVars("Template Items Found?", isRecord1);
while (isRecord1) {
var Prodid = GetFieldValue("Product Id");//Added by JX050 for defect 353
var Quantityhv = GetFieldValue("Quantity Requested");//Added by JX050 for defect 353
var serialized = (GetFieldValue("CMI Serialized Flag") == "Y" ? "Y" : "N");//Added by JX050 for defect 353
var ProdType = GetFieldValue("Product Type");//Added by JX050 for defect 353
var SRTQuantity = GetFieldValue("CMI SRT Quantity");//Added by JX050 for defect 353
var SRTId = GetFieldValue("CMI SRT Id");//Added by JX050 for defect 353
var coveredItemId = GetFieldValue("Covered Quote Item Id");
var parentItemId = GetFieldValue("Parent Quote Item Id");
//Added by JX050 for defect 353 to call function "UpdateQuantity"
TheApplication().Utility.logStep(ProdType+" ("+Prodid+") - Serialized: "+serialized+" - Parent/Covered Line: "+parentItemId+"/"+coveredItemId);
if (parentItemId != "" || coveredItemId != "") {
var oBS = TheApplication().GetService("CMI Add Core Product");
var psIO = TheApplication().NewPropertySet();
var psOP = TheApplication().NewPropertySet();
psIO.SetProperty("Quote Id", sPickQuoteId);
psIO.SetProperty("Covered Quote Item Id", coveredItemId);
psIO.SetProperty("Parent Quote Item Id", parentItemId);
oBS.InvokeMethod("FixTemplateFKs",psIO,psOP);
newParent = psOP.GetProperty("Parent Quote Item Id");
FKName = (parentItemId != "" ? "Parent Quote Item Id" : "Covered Quote Item Id");
}
//If non serialized and not a new quote (since there will not be any lines), check to see if the product exists
//first and if so add to the quantity
if((serialized != "Y") &&
(ProdType == prodTypeProduct || ProdType == prodTypePart || ProdType == prodTypeLabor || ProdType == prodTypeMisc) &&
(newQuote == false)) {
UpdateQuantity(sPickQuoteId,Prodid,Quantityhv,ProdType,SRTQuantity,SRTId,FKName, newParent);
}
//If serialized, a new quote, or if the non serialized product was not found, then a new line must be created
if(serialized == "Y" || lineQtyUpdated == false || newQuote) {
var currentTime = bcQuoteTemplateItem.GetFieldValue("CMI Today");//Add by peter for set Due Date Today
var sUOM = bcQuoteTemplateItem.GetFieldValue("Unit of Measure");
iMaxLineNumber = ToNumber(iMaxLineNumber) + 1;
NewRecord(NewAfterCopy);
SetFieldValue("Quote Id",sPickQuoteId);
SetFieldValue("Line Number", iMaxLineNumber);
//Certain fields are only set when not using the InShop/Mobile Templates
if (!(newQuote)) {
SetFieldValue("CMI SRT Access Code", sQuoteAccCd);
SetFieldValue("Revised Line Item Id", GetFieldValue("Id"));
SetFieldValue("Carrier Code", sCarCode);
SetFieldValue("CMI Prior Qty", 0);//By JQ487 Added for fixnig defect 5459 on 02/08/2012
SetFieldValue("Requested Delivery Date",sDueDate);
} else {
SetFieldValue("Requested Delivery Date", currentTime);
}
SetFieldValue("Source Inventory Location Id",sLocId);
SetFieldValue("CMI Work Sequence", iMaxLineNumber);
SetFieldValue("Currency Code", sCurcyCd);
SetFieldValue("Ship To Account Id", sShipAcId);
SetFieldValue("Ship To Address Id", sShipAdd