0% found this document useful (0 votes)
49 views

Script From Infosys

This document contains code for updating and deleting discounts on quote items in a CMI system. It summarizes warranty percentages for a quote item, then updates the discount percentage field on the quote item with the total warranty percentage. When deleting a discount, it similarly calculates the total warranty percentage and updates the discount field.

Uploaded by

PRATYUSH KUNDU
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Script From Infosys

This document contains code for updating and deleting discounts on quote items in a CMI system. It summarizes warranty percentages for a quote item, then updates the discount percentage field on the quote item with the total warranty percentage. When deleting a discount, it similarly calculates the total warranty percentage and updates the discount field.

Uploaded by

PRATYUSH KUNDU
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 63

CMI UPDATE DISCOUNT PERCENT

function Service_PreInvokeMethod (MethodName, Inputs, Outputs)


{
try
{//try
var boQuote = TheApplication().ActiveBusObject();
var bcQuoteItem = boQuote.GetBusComp("Quote Item");
var bcQuoteItemWarranty = 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");
if(MethodName == "UpdateDiscount")
{
with(bcQuoteItemWarranty)
{
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();
}
}
if(ProAttQId != "")
{
var obo = TheApplication().GetBusObject("Quote");
var obc = obo.GetBusComp("Quote Item");
with(obc)
{
SetViewMode(AllView);
ActivateField("Discount Percent");
ActivateField("Id");
ClearToQuery();
SetSearchSpec("Id",iLineItem);
ExecuteQuery();
while(FirstRecord())
{
SetFieldValue("Discount Percent", sTWPct);
1
WriteRecord();
}
}
}
else
bcQuoteItem.ActivateField("Discount Percent");
bcQuoteItem.SetFieldValue("Discount Percent", sTWPct);
bcQuoteItem.WriteRecord();
return (CancelOperation);
}
if (MethodName == "DeleteDiscount")
{
iLineItem = bcQuoteItem.GetFieldValue("Id");
var iLineItem1 = TheApplication().GetProfileAttr("CMIParentItemId");
// bcQuoteItem.ActivateField("Discount Percent");
// bcQuoteItem.SetFieldValue("Discount Percent", sTWPct);
// bcQuoteItem.WriteRecord();
var oBO = TheApplication().GetBusObject("Quote");
var oBC = oBO.GetBusComp("CMI Quote Item Warranty");
with (oBC)
{
SetViewMode(AllView);
ActivateField("CMI Percent Covered");
ActivateField("Parent Id");
ClearToQuery();
SetSearchSpec("Parent Id", iLineItem);
ExecuteQuery();
isRecord = FirstRecord();
// var cntRec = CountRecords();
while (isRecord)
{
sWPct = ToNumber(GetFieldValue("CMI Percent Covered"));
sTWPct = sTWPct + sWPct;
isRecord = NextRecord();
}
}
var oBCQI = oBO.GetBusComp("Quote Item");
with(oBCQI)
{
SetViewMode(AllView);
ActivateField("Discount Percent");
ClearToQuery();
SetSearchSpec("Id", iLineItem);
ExecuteQuery();
if(FirstRecord())
{
SetFieldValue("Discount Percent", sTWPct);
WriteRecord();
}

}
2
/*bcQuoteItem.ActivateField("Discount Percent");
var test = bcQuoteItem.GetFieldValue("Id");
bcQuoteItem.SetFieldValue("Discount Percent", sTWPct);
bcQuoteItem.WriteRecord();*/
var sBS = TheApplication().GetService("SIS OM PMT Service");
var sIP = TheApplication().NewPropertySet();
var sOP = TheApplication().NewPropertySet();
sIP.SetProperty("Business Object Name","Quote");
sIP.SetProperty("Business Component Name","Quote Item");
sBS.InvokeMethod("Refresh Business Component",sIP,sOP);
return (CancelOperation);
}
return (ContinueOperation);
}//try

CMI SR ADD QUOTE TEMPLATE TO QUOTE


function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if (MethodName == "AddQuoteTemplate")
{
var ActiveViewName = TheApplication().ActiveViewName();
if(ActiveViewName == "CMI Service Request Warranty View")
{
RemoveWarranty();
CascadeWarranty();
}
else
{
var oBO = TheApplication().ActiveBusObject();
var oBCQuoteTemplate = null;
var oBCPickQuote = oBO.GetBusComp("Quote");
var sValid;
var sProdVal1 = TheApplication().InvokeMethod("LookupValue",
"PRODUCT_TYPE", "Product");// defect 353
var sProdVal2 = TheApplication().InvokeMethod("LookupValue",
"PRODUCT_TYPE", "Part"); // defect 353
var sProdVal3 = TheApplication().InvokeMethod("LookupValue",
"PRODUCT_TYPE", "Labor");// defect 353
var sProdVal4 = TheApplication().InvokeMethod("LookupValue",
"PRODUCT_TYPE", "Misc");// defect 353

if (TheApplication().ActiveViewName() == "CMI SR Failure Code Quote Template View")


{
oBCQuoteTemplate = oBO.GetBusComp("Quote Template");
}
else
{

3
oBCQuoteTemplate = oBO.GetBusComp("CMI Quote Template");
}
var sQuoteTemplateId = oBCQuoteTemplate.GetFieldValue ("Id");
var sPickQuoteId = oBCPickQuote.GetFieldValue("Id");
//added by jacky
oBCPickQuote.ActivateField("Requested Ship Date");
var sDueDate = oBCPickQuote.GetFieldValue("Requested Ship Date");
oBCPickQuote.ActivateField("Source Inventory Location Id");
var sLocId = oBCPickQuote.GetFieldValue("Source Inventory Location Id");
oBCPickQuote.ActivateField("Currency Code");
var sCurcyCd = oBCPickQuote.GetFieldValue("Currency Code");
var sQuoteAccCd = oBCPickQuote.GetFieldValue("CMI Asset Access Code");
oBCPickQuote.ActivateField("Ship To Account Id");
oBCPickQuote.ActivateField("Ship To Address Id");
oBCPickQuote.ActivateField("CMI Ship To Profile Id");
oBCPickQuote.ActivateField("Carrier Priority");
oBCPickQuote.ActivateField("Carrier Code");
var sShipAcId = oBCPickQuote.GetFieldValue("Ship To Account Id");
var sShipAddrId = oBCPickQuote.GetFieldValue("Ship To Address Id");
var sShipProfId = oBCPickQuote.GetFieldValue("CMI Ship To Profile Id");
var sCarCode = oBCPickQuote.GetFieldValue("Carrier Code");
var sCarPri = oBCPickQuote.GetFieldValue("Carrier Priority");
//Code added by IY795 for revision from quote if status is not In Progress
var sStatus = oBCPickQuote.GetFieldValue("Status");
if(sStatus != TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "In Progress"))
{
oBCPickQuote.InvokeMethod("ReviseCopyQuote");
var sNewQuoteId = oBCPickQuote.GetFieldValue("Id");
sPickQuoteId = sNewQuoteId;
}
var QuoteIdReq = sPickQuoteId;// defect 353
var oBCPickQuoteItem = oBO.GetBusComp("Quote Item");
with (oBCPickQuoteItem)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Quote Id",sPickQuoteId);
SetSortSpec("Line Number(DESCENDING)");
ExecuteQuery(ForwardOnly);
var isRecordPickQuoteItem = FirstRecord();
}
var iMaxLineNumber = 0;
var iPickQuoteItemCount = 0;
if (isRecordPickQuoteItem)
{
iMaxLineNumber = ToNumber(oBCPickQuoteItem.GetFieldValue("Line Number"));
iPickQuoteItemCount = oBCPickQuoteItem.CountRecords();
if (iMaxLineNumber == 0 )
{
iMaxLineNumber = iPickQuoteItemCount;
}
4
}
var oBOQ = TheApplication().GetBusObject("CMI Quote");
var oBCQuote = oBOQ.GetBusComp("CMI Quote Simple");
var oBCQuoteItem = oBOQ.GetBusComp("CMI Quote Item Lite");
var iProcessed = 0;
with (oBCQuote)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sQuoteTemplateId);
ExecuteQuery(ForwardOnly);
var icount = oBCQuoteItem.CountRecords();
var isRecord = FirstRecord();
if (isRecord)
{
with (oBCQuoteItem)
{
SetViewMode(AllView);
ActivateField("Product Id");// defect 353
ActivateField("Quantity Requested");// defect 353
ActivateField("CMI SRT Quantity");// defect 353
ActivateField("Product Type");// defect 353
ActivateField("CMI Serialized Flag");// defect 353
ActivateField("CMI SRT Id");// 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");
SetSearchSpec("Quote Id",sQuoteTemplateId);
SetSortSpec("Line Number(DESCENDING)");
ClearToQuery();
ExecuteQuery();
var icount1 = oBCQuoteItem.CountRecords();
var isRecord1 = FirstRecord();
while ( iProcessed < icount1 && isRecord1)
{
var Prodid = GetFieldValue("Product Id");// defect 353
var Quantityhv = GetFieldValue("Quantity Requested");// defect 353
var SFlag = GetFieldValue("CMI Serialized Flag");// defect 353
var ProdType = GetFieldValue("Product Type");// defect 353
var SRTQuantity = GetFieldValue("CMI SRT Quantity");// defect 353
var SRTId = GetFieldValue("CMI SRT Id");// defect 353

5
if((SFlag != "Y") && ((ProdType == sProdVal1)||(ProdType == sProdVal2)||(ProdType ==
sProdVal3)||(ProdType == sProdVal4)))
{
UpdateQuantity(QuoteIdReq,Prodid,Quantityhv,ProdType,SRTQuantity,SRTId);
}
if((SFlag == "Y")||(TheApplication().GetProfileAttr("ChangeDone")!="Y"))
{
var iTQIRowId = GetFieldValue("Id");
var iLineNumber = GetFieldValue("Line Number");
NewRecord(NewAfterCopy);
SetFieldValue("Quote Id",sPickQuoteId);
SetFieldValue("Source Inventory Location Id",sLocId);
SetFieldValue("Requested Delivery Date",sDueDate);
var iLineNumberNew = GetFieldValue("Line Number");
iMaxLineNumber = ToNumber(iMaxLineNumber) + 1;
// SetFieldValue("Line Number",GetFieldValue("Line Number")+icount1);
SetFieldValue("Line Number", iMaxLineNumber);
SetFieldValue("CMI Work Sequence", iMaxLineNumber);
SetFieldValue("Currency Code", sCurcyCd);
SetFieldValue("Ship To Account Id", sShipAcId);
SetFieldValue("Ship To Address Id", sShipAddrId);
SetFieldValue("CMI Ship To Profile Id", sShipProfId);
var sQuoteItemId = GetFieldValue("Id");
SetFieldValue("Revised Line Item Id", sQuoteItemId);
SetFieldValue("Carrier Code", sCarCode);
SetFieldValue("Shipping Method", sCarPri);
WriteRecord();
}

TheApplication().SetProfileAttr("ChangeDone","");// defect 353: to reset profAtrib set in function


"UpdateQuantity"
var iNewCurrRowId = GetFieldValue("Id");
isRecord1 = NextRecord();
iProcessed = ToNumber(iProcessed) + 1;
var iNextRecordId = GetFieldValue("Id");
while ( iProcessed < icount1 && iNextRecordId == iTQIRowId )
{
isRecord1 = NextRecord();
iNextRecordId = GetFieldValue("Id");
}
// }
}
}
}
}
sValid = CheckSRTValidity(oBCQuote, oBCQuoteItem, sPickQuoteId, sQuoteAccCd);
if ( TheApplication().ActiveViewName() == "CMI Service Request Quote Template List View")
{
var sFailCdId = oBCQuoteTemplate.GetFieldValue("CMI Failure Id");
var sSRID = oBCPickQuote.GetFieldValue("Service Request Id");
CreateFailureCode(sFailCdId, sSRID);
6
}
/*var oBOQuoteGo2View = TheApplication().GetBusObject("Quote");
var oBCQuoteGo2View = oBOQuoteGo2View.GetBusComp("Quote");
with (oBCQuoteGo2View)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sPickQuoteId);
ExecuteQuery(ForwardOnly);
TheApplication().GotoView("CMI Labor Quote Line Item View",oBOQuoteGo2View);
}*/
return (CancelOperation);
} //End of 1st else
/*if(sValid == "N")
{
TheApplication().RaiseErrorText("Some of the line items are not have the SRT Hours set. Please verify.");
}*/
return(CancelOperation);
}
if(MethodName == "RemoveAllWarranty")
{
RemoveWarranty();
return(CancelOperation);
}
}//end of try
}
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if (MethodName == "AddQuoteTemplate")
{
var ActiveViewName = TheApplication().ActiveViewName();
if(ActiveViewName == "CMI Service Request Warranty View")
{
RemoveWarranty();
CascadeWarranty();
}
else
{

var oBO = TheApplication().ActiveBusObject();


var oBCQuoteTemplate = null;
var oBCPickQuote = oBO.GetBusComp("Quote");
var sValid;

var sProdVal1 = TheApplication().InvokeMethod("LookupValue",


"PRODUCT_TYPE", "Product");// defect 353
var sProdVal2 = TheApplication().InvokeMethod("LookupValue",
"PRODUCT_TYPE", "Part"); // defect 353

7
var sProdVal3 = TheApplication().InvokeMethod("LookupValue",
"PRODUCT_TYPE", "Labor");// defect 353
var sProdVal4 = TheApplication().InvokeMethod("LookupValue",
"PRODUCT_TYPE", "Misc");// defect 353
if (TheApplication().ActiveViewName() == "CMI SR Failure Code Quote Template View")
{
oBCQuoteTemplate = oBO.GetBusComp("Quote Template");
}
else
{
oBCQuoteTemplate = oBO.GetBusComp("CMI Quote Template");
}
var sQuoteTemplateId = oBCQuoteTemplate.GetFieldValue ("Id");
var sPickQuoteId = oBCPickQuote.GetFieldValue("Id");
//added by jacky
oBCPickQuote.ActivateField("Requested Ship Date");
var sDueDate = oBCPickQuote.GetFieldValue("Requested Ship Date");
oBCPickQuote.ActivateField("Source Inventory Location Id");
var sLocId = oBCPickQuote.GetFieldValue("Source Inventory Location Id");
oBCPickQuote.ActivateField("Currency Code");
var sCurcyCd = oBCPickQuote.GetFieldValue("Currency Code");
var sQuoteAccCd = oBCPickQuote.GetFieldValue("CMI Asset Access Code");
oBCPickQuote.ActivateField("Ship To Account Id");
oBCPickQuote.ActivateField("Ship To Address Id");
oBCPickQuote.ActivateField("CMI Ship To Profile Id");
oBCPickQuote.ActivateField("Carrier Priority");
oBCPickQuote.ActivateField("Carrier Code");
var sShipAcId = oBCPickQuote.GetFieldValue("Ship To Account Id");
var sShipAddrId = oBCPickQuote.GetFieldValue("Ship To Address Id");
var sShipProfId = oBCPickQuote.GetFieldValue("CMI Ship To Profile Id");
var sCarCode = oBCPickQuote.GetFieldValue("Carrier Code");
var sCarPri = oBCPickQuote.GetFieldValue("Carrier Priority");
//Code added by IY795 for revision from quote if status is not In Progress
var sStatus = oBCPickQuote.GetFieldValue("Status");
if(sStatus != TheApplication().InvokeMethod("LookupValue",
"QUOTE_STATUS", "In Progress"))
{
oBCPickQuote.InvokeMethod("ReviseCopyQuote");
var sNewQuoteId = oBCPickQuote.GetFieldValue("Id");
sPickQuoteId = sNewQuoteId;
}
var QuoteIdReq = sPickQuoteId;// defect 353
var oBCPickQuoteItem = oBO.GetBusComp("Quote Item");
with (oBCPickQuoteItem)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Quote Id",sPickQuoteId);
SetSortSpec("Line Number(DESCENDING)");
ExecuteQuery(ForwardOnly);
var isRecordPickQuoteItem = FirstRecord();
8
}
var iMaxLineNumber = 0;
var iPickQuoteItemCount = 0;
if (isRecordPickQuoteItem)
{
iMaxLineNumber =
ToNumber(oBCPickQuoteItem.GetFieldValue("Line Number"));
iPickQuoteItemCount = oBCPickQuoteItem.CountRecords();
if (iMaxLineNumber == 0 )
{
iMaxLineNumber = iPickQuoteItemCount;
}
}
var oBOQ = TheApplication().GetBusObject("CMI Quote");
var oBCQuote = oBOQ.GetBusComp("CMI Quote Simple");
var oBCQuoteItem = oBOQ.GetBusComp("CMI Quote Item Lite");
var iProcessed = 0;
with (oBCQuote)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sQuoteTemplateId);
ExecuteQuery(ForwardOnly);
var icount = oBCQuoteItem.CountRecords();
var isRecord = FirstRecord();
if (isRecord)
{
with (oBCQuoteItem)
{
SetViewMode(AllView);
ActivateField("Product Id");//
ActivateField("Quantity Requested");//
ActivateField("CMI SRT Quantity");//
ActivateField("Product Type");//
ActivateField("CMI Serialized Flag");//
ActivateField("CMI SRT Id");//
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");
SetSearchSpec("Quote Id",sQuoteTemplateId);
SetSortSpec("Line Number(DESCENDING)");
ClearToQuery();
9
ExecuteQuery();
var icount1 = oBCQuoteItem.CountRecords();
var isRecord1 = FirstRecord();
while ( iProcessed < icount1 && isRecord1)
{
var Prodid = GetFieldValue("Product Id");// defect 353
var Quantityhv = GetFieldValue("Quantity Requested");// defect 353
var SFlag = GetFieldValue("CMI Serialized Flag");// defect 353
var ProdType = GetFieldValue("Product Type");// defect 353
var SRTQuantity = GetFieldValue("CMI SRT Quantity");// defect 353
var SRTId = GetFieldValue("CMI SRT Id");// defect 353
if((SFlag != "Y") && ((ProdType == sProdVal1)||(ProdType == sProdVal2)||(ProdType ==
sProdVal3)||(ProdType == sProdVal4)))
{
UpdateQuantity(QuoteIdReq,Prodid,Quantityhv,ProdType,SRTQuantity,SRTId);
}
if((SFlag == "Y")||(TheApplication().GetProfileAttr("ChangeDone")!="Y"))
{
var iTQIRowId = GetFieldValue("Id");
var iLineNumber = GetFieldValue("Line Number");
NewRecord(NewAfterCopy);
SetFieldValue("Quote Id",sPickQuoteId);
setFieldValue("Source Inventory Location Id",sLocId);
//added by jacky
SetFieldValue("Requested Delivery Date",sDueDate);
var iLineNumberNew = GetFieldValue("Line Number");
iMaxLineNumber = ToNumber(iMaxLineNumber) + 1;
// etFieldValue("Line Number",GetFieldValue("Line Number")+icount1);
SetFieldValue("Line Number", iMaxLineNumber);
SetFieldValue("CMI Work Sequence", iMaxLineNumber);
SetFieldValue("Currency Code", sCurcyCd);
SetFieldValue("Ship To Account Id", sShipAcId);
SetFieldValue("Ship To Address Id", sShipAddrId);
SetFieldValue("CMI Ship To Profile Id", sShipProfId);
var sQuoteItemId = GetFieldValue("Id");
SetFieldValue("Revised Line Item Id", sQuoteItemId);
SetFieldValue("Carrier Code", sCarCode);
SetFieldValue("Shipping Method", sCarPri);
WriteRecord();
}
TheApplication().SetProfileAttr("ChangeDone
var iNewCurrRowId = GetFieldValue("Id");
isRecord1 = NextRecord();
iProcessed = ToNumber(iProcessed) + 1;
var iNextRecordId = GetFieldValue("Id");
while ( iProcessed < icount1 && iNextRecordId == iTQIRowId )
{
isRecord1 = NextRecord();
iNextRecordId = GetFieldValue("Id");
}
// }
10
}
}
}
}
sValid = CheckSRTValidity(oBCQuote, oBCQuoteItem, sPickQuoteId, sQuoteAccCd);
// Go to 'CreateFailureCode' Function
if ( TheApplication().ActiveViewName() == "CMI Service Request Quote Template List View")
{
var sFailCdId = oBCQuoteTemplate.GetFieldValue("CMI Failure Id");
var sSRID = oBCPickQuote.GetFieldValue("Service Request Id");
CreateFailureCode(sFailCdId, sSRID);
}

/*var oBOQuoteGo2View = TheApplication().GetBusObject("Quote");


var oBCQuoteGo2View = oBOQuoteGo2View.GetBusComp("Quote");
with (oBCQuoteGo2View)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sPickQuoteId);
ExecuteQuery(ForwardOnly);
TheApplication().GotoView("CMI Labor Quote Line Item View",oBOQuoteGo2View);
}*/
return (CancelOperation);
} //End of 1st else
/*if(sValid == "N")
{
TheApplication().RaiseErrorText("Some of the line items are not have the SRT Hours set. Please verify.");
}*/
return(CancelOperation);
}
if(MethodName == "RemoveAllWarranty")
{
RemoveWarranty();
return(CancelOperation);
}
}//end of try
}
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if (MethodName == "AddQuoteTemplate")
{
var ActiveViewName = TheApplication().ActiveViewName();
if(ActiveViewName == "CMI Service Request Warranty View")
{
RemoveWarranty();
CascadeWarranty();
}
else
11
{

var oBO = TheApplication().ActiveBusObject();


var oBCQuoteTemplate = null;
var oBCPickQuote = oBO.GetBusComp("Quote");
var sValid;

var sProdVal1 = TheApplication().InvokeMethod("LookupValue",


"PRODUCT_TYPE", "Product");// defect 353
var sProdVal2 = TheApplication().InvokeMethod("LookupValue",
"PRODUCT_TYPE", "Part"); // defect 353
var sProdVal3 = TheApplication().InvokeMethod("LookupValue",
"PRODUCT_TYPE", "Labor");// defect 353
var sProdVal4 = TheApplication().InvokeMethod("LookupValue",
"PRODUCT_TYPE", "Misc");// defect 353

if (TheApplication().ActiveViewName() == "CMI SR Failure Code Quote Template View")


{
oBCQuoteTemplate = oBO.GetBusComp("Quote Template");
}
else
{
oBCQuoteTemplate = oBO.GetBusComp("CMI Quote Template");
}
var sQuoteTemplateId = oBCQuoteTemplate.GetFieldValue ("Id");
var sPickQuoteId = oBCPickQuote.GetFieldValue("Id");
//added by jacky
oBCPickQuote.ActivateField("Requested Ship Date");
var sDueDate = oBCPickQuote.GetFieldValue("Requested Ship Date");
oBCPickQuote.ActivateField("Source Inventory Location Id");
var sLocId = oBCPickQuote.GetFieldValue("Source Inventory Location Id");
oBCPickQuote.ActivateField("Currency Code");
var sCurcyCd = oBCPickQuote.GetFieldValue("Currency Code");
var sQuoteAccCd = oBCPickQuote.GetFieldValue("CMI Asset Access Code");
oBCPickQuote.ActivateField("Ship To Account Id");
oBCPickQuote.ActivateField("Ship To Address Id");
oBCPickQuote.ActivateField("CMI Ship To Profile Id");
oBCPickQuote.ActivateField("Carrier Priority");
oBCPickQuote.ActivateField("Carrier Code");
var sShipAcId = oBCPickQuote.GetFieldValue("Ship To Account Id");
var sShipAddrId = oBCPickQuote.GetFieldValue("Ship To Address Id");
var sShipProfId = oBCPickQuote.GetFieldValue("CMI Ship To Profile Id");
var sCarCode = oBCPickQuote.GetFieldValue("Carrier Code");
var sCarPri = oBCPickQuote.GetFieldValue("Carrier Priority");
//Code added by IY795 for revision from quote if status is not In Progress
var sStatus = oBCPickQuote.GetFieldValue("Status");
if(sStatus != TheApplication().InvokeMethod("LookupValue",
"QUOTE_STATUS", "In Progress"))
{
oBCPickQuote.InvokeMethod("ReviseCopyQuote");
var sNewQuoteId = oBCPickQuote.GetFieldValue("Id");
12
sPickQuoteId = sNewQuoteId;
}
var QuoteIdReq = sPickQuoteId;// defect 353
var oBCPickQuoteItem = oBO.GetBusComp("Quote Item");
with (oBCPickQuoteItem)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Quote Id",sPickQuoteId);
SetSortSpec("Line Number(DESCENDING)");
ExecuteQuery(ForwardOnly);
var isRecordPickQuoteItem = FirstRecord();

}
var iMaxLineNumber = 0;
var iPickQuoteItemCount = 0;
if (isRecordPickQuoteItem)
{
iMaxLineNumber = ToNumber(oBCPickQuoteItem.GetFieldValue("Line Number"));
iPickQuoteItemCount = oBCPickQuoteItem.CountRecords();
if (iMaxLineNumber == 0 )
{
iMaxLineNumber = iPickQuoteItemCount;
}
}
var oBOQ = TheApplication().GetBusObject("CMI Quote");
var oBCQuote = oBOQ.GetBusComp("CMI Quote Simple");
var oBCQuoteItem = oBOQ.GetBusComp("CMI Quote Item Lite");
var iProcessed = 0;
with (oBCQuote)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sQuoteTemplateId);
ExecuteQuery(ForwardOnly);
var icount = oBCQuoteItem.CountRecords();
var isRecord = FirstRecord();
if (isRecord)
{
with (oBCQuoteItem)
{
SetViewMode(AllView);
ActivateField("Product Id");// defect 353
ActivateField("Quantity Requested");// defect 353
ActivateField("CMI SRT Quantity");// defect 353
ActivateField("Product Type");// defect 353
ActivateField("CMI Serialized Flag");// defect 353
ActivateField("CMI SRT Id");// defect 353
ActivateField("Line Number");
ActivateField("Requested Delivery Date");
ActivateField("Source Inventory Location Id");
13
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");
SetSearchSpec("Quote Id",sQuoteTemplateId);
SetSortSpec("Line Number(DESCENDING)");
ClearToQuery();
ExecuteQuery();
var icount1 = oBCQuoteItem.CountRecords();
var isRecord1 = FirstRecord();
while ( iProcessed < icount1 && isRecord1)
{
var Prodid = GetFieldValue("Product Id");// defect 353
var Quantityhv = GetFieldValue("Quantity Requested");// defect 353
var SFlag = GetFieldValue("CMI Serialized Flag");// defect 353
var ProdType = GetFieldValue("Product Type");// defect 353
var SRTQuantity = GetFieldValue("CMI SRT Quantity");// defect 353
var SRTId = GetFieldValue("CMI SRT Id");// defect 353
// defect 353 to call function "UpdateQuantity"
if((SFlag != "Y") && ((ProdType == sProdVal1)||(ProdType == sProdVal2)||(ProdType == sProdVal3)||
(ProdType == sProdVal4)))
{
UpdateQuantity(QuoteIdReq,Prodid,Quantityhv,ProdType,SRTQuantity,SRTId);
}
if((SFlag == "Y")||(TheApplication().GetProfileAttr("ChangeDone")!="Y"))
{
var iTQIRowId = GetFieldValue("Id");
var iLineNumber = GetFieldValue("Line Number");
NewRecord(NewAfterCopy);
SetFieldValue("Quote Id",sPickQuoteId);
SetFieldValue("Source Inventory Location Id",sLocId);
SetFieldValue("Requested Delivery Date",sDueDate);
var iLineNumberNew = GetFieldValue("Line Number");
iMaxLineNumber = ToNumber(iMaxLineNumber) + 1;
/SetFieldValue("Line Number",GetFieldValue("Line Number")+icount1);
SetFieldValue("Line Number", iMaxLineNumber);
SetFieldValue("CMI Work Sequence", iMaxLineNumber);
SetFieldValue("Currency Code", sCurcyCd);
SetFieldValue("Ship To Account Id", sShipAcId);
SetFieldValue("Ship To Address Id", sShipAddrId);
SetFieldValue("CMI Ship To Profile Id", sShipProfId);
var sQuoteItemId = GetFieldValue("Id");
SetFieldValue("Revised Line Item Id", sQuoteItemId);
SetFieldValue("Carrier Code", sCarCode);
SetFieldValue("Shipping Method", sCarPri);
WriteRecord();
14
}

TheApplication().SetProfileAttr("ChangeDone","");// defect 353: to reset profAtrib set in function


"UpdateQuantity"
var iNewCurrRowId = GetFieldValue("Id");
isRecord1 = NextRecord();
iProcessed = ToNumber(iProcessed) + 1;
var iNextRecordId = GetFieldValue("Id");
while ( iProcessed < icount1 && iNextRecordId == iTQIRowId )
{
isRecord1 = NextRecord();
iNextRecordId = GetFieldValue("Id");
}
// }
}
}
}
}
sValid = CheckSRTValidity(oBCQuote, oBCQuoteItem, sPickQuoteId, sQuoteAccCd);
// Go to 'CreateFailureCode' Function
if ( TheApplication().ActiveViewName() == "CMI Service Request Quote Template List View")
{
var sFailCdId = oBCQuoteTemplate.GetFieldValue("CMI Failure Id");
var sSRID = oBCPickQuote.GetFieldValue("Service Request Id");
CreateFailureCode(sFailCdId, sSRID);
}
/*var oBOQuoteGo2View = TheApplication().GetBusObject("Quote");
var oBCQuoteGo2View = oBOQuoteGo2View.GetBusComp("Quote");
with (oBCQuoteGo2View)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sPickQuoteId);
ExecuteQuery(ForwardOnly);
TheApplication().GotoView("CMI Labor Quote Line Item View",oBOQuoteGo2View);
}*
return (CancelOperation);
} //End of 1st else
/*if(sValid == "N")
{
TheApplication().RaiseErrorText("Some of the line items are not have the SRT Hours set. Please verify.");
}*/
return(CancelOperation);
}
if(MethodName == "RemoveAllWarranty")
{
RemoveWarranty();
return(CancelOperation);
}

}//end of try
15
}
function CheckSRTValidity(oBCQuote, BCQuoteItem, sNewQuoteId, sQuoteAccCd)
{
try
{
var isItemRec; var sSRTId; var sAccCd; var sSRTBC;
var sStepBC; var sSRTValidFlg = "N"; var sSRTStepValidFlg = "N";
var sSRTCount = 0; var sSRTStpCount = 0; var sValid = "Y";
with(oBCQuote)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sNewQuoteId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
with(BCQuoteItem)
{
SetViewMode(AllView);
ActivateField("CMI SRT Id");
ActivateField("CMI SRT Step Id");
ActivateField("CMI SRT Access Code");
ActivateField("Quote Id");
ActivateField("CMI SRT Description");
ActivateField("CMI SRT Step Num");
ClearToQuery();
SetSearchSpec("Quote Id", sNewQuoteId);
SetSearchSpec("Product Type",
TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor"));
ExecuteQuery();
isItemRec = FirstRecord();
while(isItemRec)
{
sSRTId = GetFieldValue("CMI SRT Id");
sStepId = GetFieldValue("CMI SRT Step Id");
sAccCd = GetFieldValue("CMI SRT Access Code");
//if(sAccCd == "" || sAccCd == null)
//{
if(sSRTId != null || sSRTId != "")
{
if(sAccCd != "")
{
SetFieldValue("CMI SRT Access Code", sAccCd);
WriteRecord();
}
else
{
etFieldValue("CMI SRT Access Code", sQuoteAccCd);
WriteRecord();
}
}
16
if(sSRTId != null && sSRTId != "")
{
sSRTBC = BCQuoteItem.GetPicklistBusComp("CMI SRT Description");
with(sSRTBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sSRTId);
ExecuteQuery();
if(FirstRecord())
{
Pick();
}
else
{
sSRTValidFlg = "Y";
if(sSRTValidFlg == "Y")
{
sSRTCount = sSRTCount + 1;
sSRTValidFlg = "N";
}
}
}
}//end of if(SRTId)

if(sStepId != null && sStepId != "")


{
sStepBC = BCQuoteItem.GetPicklistBusComp("CMI SRT Step Num");
with(sStepBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sStepId);
ExecuteQuery();
if(FirstRecord())
{
Pick();
}
else
{
sSRTStepValidFlg = "Y";
if(sSRTStepValidFlg == "Y")
{
sSRTStpCount = sSRTStpCount + 1;
sSRTStepValidFlg = "N";
}
}
}
}//end of if(SRTStepId
//}//end of if(AccCd)
isItemRec = NextRecord();
17
}//end of isItemRec
}//end of BCQuoteItem
}//end of if(FirstRecord)
}//End of oBCQuote
if(sSRTCount > 0 || sSRTStpCount > 0)
{
sValid = "N";
}
}//end of try
return(sValid);
}
function CheckSRTValidity(oBCQuote, BCQuoteItem, sNewQuoteId, sQuoteAccCd)
{
try
{
var isItemRec; var sSRTId; var sStepId; var sAccCd;
var sSRTBC; var sStepBC; var sSRTValidFlg = "N";
var sSRTStepValidFlg = "N"; var sSRTCount = 0; var sSRTStpCount = 0;
var sValid = "Y";
with(oBCQuote)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sNewQuoteId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
with(BCQuoteItem)
{
SetViewMode(AllView);
ActivateField("CMI SRT Id");
ActivateField("CMI SRT Step Id");
ActivateField("CMI SRT Access Code");
ActivateField("Quote Id");
ActivateField("CMI SRT Description");
ActivateField("CMI SRT Step Num");
ClearToQuery();
SetSearchSpec("Quote Id", sNewQuoteId);
SetSearchSpec("Product Type",
TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor"));
ExecuteQuery();
isItemRec = FirstRecord();
while(isItemRec)
{
sSRTId = GetFieldValue("CMI SRT Id");
sStepId = GetFieldValue("CMI SRT Step Id");
sAccCd = GetFieldValue("CMI SRT Access Code");
//if(sAccCd == "" || sAccCd == null)
//{
if(sSRTId != null || sSRTId != "")
{
18
if(sAccCd != "")
{
SetFieldValue("CMI SRT Access Code", sAccCd);
WriteRecord();
}
else
{
SetFieldValue("CMI SRT Access Code", sQuoteAccCd);
WriteRecord();
}
}
if(sSRTId != null && sSRTId != "")
{
sSRTBC = BCQuoteItem.GetPicklistBusComp("CMI SRT Description");
with(sSRTBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sSRTId);
ExecuteQuery();
if(FirstRecord())
{
Pick();
}
else
{
sSRTValidFlg = "Y";
if(sSRTValidFlg == "Y")
{
sSRTCount = sSRTCount + 1;
sSRTValidFlg = "N";
}
}
}
}//end of if(SRTId)

if(sStepId != null && sStepId != "")


{
sStepBC = BCQuoteItem.GetPicklistBusComp("CMI SRT Step Num");
with(sStepBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sStepId);
ExecuteQuery();
if(FirstRecord())
{
Pick();
}
else
{
19
sSRTStepValidFlg = "Y";
if(sSRTStepValidFlg == "Y")
{
sSRTStpCount = sSRTStpCount + 1;
sSRTStepValidFlg = "N";
}
}
}
}//end of if(SRTStepId)

//}//end of if(AccCd)
isItemRec = NextRecord()
}//end of isItemRec
}//end of BCQuoteItem
}//end of if(FirstRecord)
}//End of oBCQuote
if(sSRTCount > 0 || sSRTStpCount > 0)
{
sValid = "N";
}

}//end of try

return(sValid);
}
function RemoveWarranty()
{
try
{
var oBO = TheApplication().ActiveBusObject();// SR in this case
var oBCQuote = oBO.GetBusComp("Quote");
var QuoteId = oBCQuote.GetFieldValue("Id");
var SRId = oBCQuote .GetFieldValue("Service Request Id");
var OBCQuoteItem = oBO.GetBusComp("Quote Item");
var oBCSRWarranty = oBO.GetBusComp("CMI Service Request Warranty");
var oBCQIW = oBO.GetBusComp("CMI Quote Item Warranty");

with(OBCQuoteItem)
{
ActivateField("CMI SR Id");
ActivateField("Quote Id")
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI SR Id", SRId);
SetSearchSpec("Quote Id", QuoteId);
ExecuteQuery();
var IsQuoteItemRec = FirstRecord();
while(IsQuoteItemRec)
{
20
var QuoteItemID = GetFieldValue("Id");
with(oBCQIW)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Parent Id", QuoteItemID);
ExecuteQuery();
var IsWarrantyRec = FirstRecord();
while(IsWarrantyRec)
{
DeleteRecord();
IsWarrantyRec = FirstRecord();
}
}
IsQuoteItemRec = NextRecord();
}
}
}//end of try

}
function UpdateQuantity(QuoteIdReq,Prodid,Quantityhv,ProdType,SRTQuantity,SRTId)
{
try
{
var oBO = TheApplication().ActiveBusObject();
var oBC = oBO.GetBusComp("Quote Item");
var Qty;
var NQty;

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");

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");
ClearToQuery();
SetSearchSpec("Quote Id",QuoteIdReq);
ExecuteQuery()
// var R1 = CountRecords();
var isRec = FirstRecord();
while(isRec)
{
var Prodid1 = GetFieldValue("Product Id");
21
var ProdType1 = GetFieldValue("Product Type");
if(Prodid1 == Prodid)
{
if((ProdType1 == sProdVal1)||(ProdType1 == sProdVal2)||(ProdType1 == sProdVal4))
{
Qty = GetFieldValue("Quantity Requested");
NQty = ToNumber(Quantityhv) + ToNumber(Qty);
SetFieldValue("Quantity Requested",NQty);
WriteRecord();
TheApplication().SetProfileAttr("ChangeDone","Y");
}
if(ProdType1 == sProdVal3)
{
//var QtyReq1 = GetFieldValue("Quantity Requested");
var SRTId1 = GetFieldValue("CMI SRT Id");
Qty = GetFieldValue("CMI SRT Quantity");
var SRTHr = GetFieldValue("CMI SRT Hours");
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)
SetFieldValue("Quantity Requested", QtyReq1);
WriteRecord();
TheApplication().SetProfileAttr("ChangeDone","Y");
}
}
}
}
isRec = NextRecord();
}
}
}//end of try
}
CMI QUOTE TO ORDER
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if (MethodName == "QuoteToOrder")
{
var oBO = TheApplication().ActiveBusObject();
var oBCQuote = oBO.GetBusComp("Quote");
var sQuoteId = TheApplication().GetProfileAttr("Quote Id");
//perf check
var s1; var e1; var s2;
var e2; var s3; var e3;

22
//perf check
with (oBCQuote)
{
InvokeMethod("SetAdminMode","TRUE");
//SetViewMode(AllView);//Inactivated Script it doesn't invoke on certain logins-09 Feb 2011-Di
//Commented the Quote Querying as it's not required and for performance tuning,<JQ486>
/*ActivateField("Status");
ActivateField("Service Request Id");
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardOnly);*/
var sStatus = GetFieldValue("Status");
var sStaSet = TheApplication().InvokeMethod("LookupValue",
"QUOTE_STATUS", "Accepted")
sSRNum = GetFieldValue("Service Request Id");
sQuoteNum = GetFieldValue("Quote Number");//added new field as per defect 657
if (sStatus == TheApplication().InvokeMethod("LookupValue",
"QUOTE_STATUS", "Ready to Schedule"))
{
s1 = Clib.asctime(Clib.gmtime(Clib.time())); //perf check

//Added Code for Performance Tuning: <By JQ486>


QuoteValidation(sQuoteId);
if(sRetCan == "Allow")
{
//Commented Code for Performance Tuning: <By JQ486>
SetFieldValue("Status", sStaSet); //JQ487 :inactivated code for defect 657
WriteRecord();//JQ487 :inactivated code for defect 657
return(CancelOperation);
}
SetFieldValue("Status", sStaSet); //moved code for defect 657
WriteRecord(); //moved code for defect 657
e1 = Clib.asctime(Clib.gmtime(Clib.time()));//perf check
s2 = Clib.asctime(Clib.gmtime(Clib.time()));//perf check
InvokeMethod("AutoOrderPartsRequestQuote");
e2 = Clib.asctime(Clib.gmtime(Clib.time()));//perf chec
//Commented Code for Performance Tuning: <By JQ486>
/*s3 = Clib.asctime(Clib.gmtime(Clib.time()));//perf check
QuoteToOrder(sQuoteId);
e3 = Clib.asctime(Clib.gmtime(Clib.time()));//perf check*/
}
// Commented by JQ487 as now signal is changed so no need to manually set the status
//SetFieldValue("Status", sStaSet);
//WriteRecord();
var flag = TheApplication().InvokeMethod("LookupValue",
"CMI_PERF_CHECK", "Y");//perf check
var strmsg;//perf check
if(flag == "Y")//perf check
{

strmsg = "Quote Validation Start Time: " + s1 + " End Time: " + e1 + "\n";//perf check
23
strmsg = strmsg + "\n" + "Signal Invoke Start Time: " + s2 + " End Time: " + e2 + "\n";//perf check
strmsg = strmsg + "\n" + "Quote to Order Start Time: " + s3 + " End Time: " + e3;//perf check
}
else//perf check
{
strmsg = "";//perf check
}
}
//Commented Code for Performance Tuning: <By JQ486>
/*if(sReqGen == "Execute");
{
if(WriteError == "Display") //JQ487: added new condition as per defect 572 on 08/03/11
{
TheApplication().RaiseErrorText("Parts Request created, Write in
Product cannot be replaced."); //JQ487: added new condition as per defect 572 on 08/03/11
}
else
{*/
TheApplication().RaiseErrorText("Parts Request created. Review & submit." + "\n" + strmsg);//perf check
/*}
}*/
return(CancelOperation);
}
}
catch(e)
{
//TheApplication().Trace("Error Message : " + e.toString() + e.errCode);
//TheApplication().TraceOff(); throw(e);
}

return(ContinueOperation);
}
var aAllocQtyArr = new Array;
function GetItemQty(sProdId)
{
try
{
if(sProdId != null || sProdId != "")
{
for(var i = 0; i < aProdArr.length; i++)
{
if(aProdArr[i] == sProdId)
{
return i;
}
}
}
}

24
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
{
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");
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();
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");
iCount++;
sPCNextRecord = NextRecord();
}
}
}//End of while(IsActivityRec)
}//End of with(oBCAction)

25
}//End of try
}
function ProductCheck(sPrdDesc)
{
try
{
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().Trace("Error Message : " + e.toString() + e.errCode);
//TheApplication().TraceOff();
throw(e);
}

}
function QuoteToOrder(sQuoteId)
{
try
{

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");

26
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");
27
var sQtyCalc = GetFieldValue("CMI Quantity Difference");
SetFieldValue("CMI Sub Inventory", sSubInv);
SetFieldValue("CMI Line Type", sLineType);
SetFieldValue("CMI Source Type", sSourceType);
WriteRecord();
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();
}
// 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();

28
}
}
else
{
isRec = NextRecord();
}
// }
/*else
{
if((sProdType != sProdVal1) && (sProdType != sProdVal2))
{
DeleteRecord();
}

if((sProdType == sProdVal1) || (sProdType == sProdVal2))


{
isRec = NextRecord();
}
else
{
isRec = FirstRecord();
}
}*/
}
sReqGen = "Execute";
}
}// end try
catch(e)
{
//TheApplication().Trace("Error Message : " + e.toString() + e.errCode);
//TheApplication().TraceOff(); throw(e);
}

}
function QuoteValidation(sQuoteId)
{
try
{

//var oBO = TheApplication().ActiveBusObject();//Inactivated Script as Order Creation was


not happening-31 Jan 2011-Dinesh
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 sProdVal1 = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE",
"Product"); //<jq487> commented to accomodate enhancement to check Labor and misc
//var sProdVal2 = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE",
"Part"); //<jq487> commented to accomodate enhancement to check Labor and misc
var sProdVal1 = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor");
var sProdVal2 = TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Misc");
29
var sProdVal3 = "Write-In Product";
//var sProdCat = TheApplication().InvokeMethod("LookupValue",
"PRODUCT_CATEGORY", "Core");//<jq487> added new condition as per Engine Swing FS
var counter = 0;
//var iCount = 0;
//JQ486: Commented the above line and scripted below line to avoid this var getting set to 0,
this ensure the parts order signal will be called.
var iCount;
var sUpdQty = 0;
var sQtyDiff = 0;
var iQtyIdx;//Declaring Variable to capture the Qty Index
GetLineItemsInfo(sQuoteNum);//Calling fn to get the array values for each line item,<by jq486>
var sRev;//added by <JQ487> for defect 657
var sFlg;//added by <JQ487> for defect 657
var sFlg1;//added by <JQ487> for defect 657
var sFlg2 = 0;//added by <JQ487> for defect 657
with (oBCQuote)
{
SetViewMode(AllView);
ActivateField("Revision");//added by <JQ487> for defect 657
ClearToQuery();
SetSearchSpec("Id", sQuoteId);
ExecuteQuery(ForwardOnly);
//var iCount = CountRecords();
var isRec1 = FirstRecord();
sRev = GetFieldValue("Revision");//added by <JQ487> for defect 657
if(sRev > 1)//added by <JQ487> for defect 657
{
sFlg = "Y";//added by <JQ487> for defect 657
}
if(isRec1)
{
with (oBCQuoteItem)
{
SetViewMode(AllView);
ActivateField("Quote Id");
ActivateField("Action Code");
ActivateField("Product Type");
ActivateField("Product");
ActivateField("CMI Revise Flag");
ActivateField("Quantity Requested");
ActivateField("CMI Quantity Requested");
ActivateField("CMI Quantity Difference");
ActivateField("Product Id");
ActivateField("Product");
ActivateField("CMI Write-In Status Code");
ActivateField("CMI Serialized Flag");
ActivateField("CMI Parts Check");
ClearToQuery();
//SetSearchSpec("Quote Id",sQuoteId);

30
//SetSearchExpr("[CMI ATP Requested Quantity] > 0");
ExecuteQuery(ForwardBackward);
//var iCount1 = CountRecords();
var isRec = FirstRecord();
while(isRec)
{
sProdType = GetFieldValue("Product Type");
sProdId = GetFieldValue("Product Id");
sRevFlg = GetFieldValue("CMI Revise Flag");
var sQty = GetFieldValue("Quantity Requested");
var sQtyCal = GetFieldValue("CMI Quantity Requested");
sProdName = GetFieldValue("Product");
sSerialized = GetFieldValue("CMI Serialized Flag");
if (sRevFlg == "Y")
{
//if((sProdType == sProdVal1) || (sProdType == sProdVal2))
if((sProdType != sProdVal1) && (sProdType != sProdVal2))
{
/*if (sSerialized != "Y") //<jq487>
{
//SerialCheck(sProdId);//<jq487> added to accomodate defect 657

iQtyIdx = GetItemQty(sProdId);
sQuantQuoted = aQuotedQtyArr[iQtyIdx];
sPickQuan = aAllocQtyArr[iQtyIdx];
sQtyDiff = ToNumber(sQuantQuoted) + ToNumber(sQty
if (sQtyDiff <= ToNumber(sPickQuan))//<jq487> added to accomodate defect 657
{
iCount = 0;//<jq487> added to accomodate defect 657
}
else
{
iCount = 1;//<jq487> added to accomodate defect 657
}
}*/ //commented by <JQ487> as function not needed here but in else block
if (sQty != sQtyCal)
{
//Commented Code for Performance Tuning: <By JQ486>
//sUpdQty = ToNumber(sQty) - ToNumber(sQtyCal);
sUpdQty = GetFieldValue("CMI ATP Requested Quantity");
if (sUpdQty > '0')
{
//Commented Code for Performance Tuning: <By JQ486>
//SetFieldValue("CMI Quantity Difference", sUpdQty);
//WriteRecord();
counter = 1;
}
else
{
counter = 0;
31
}
}
}
}//end if
else
{
//if((sProdType == sProdVal1) || (sProdType == sProdVal2))
//iCount = 1;//<jq487> added to accomodate defect 657
if((sProdType != sProdVal1) && (sProdType != sProdVal2))
{
if(sFlg == "Y")//added by <JQ487> for defect 657
{
f (sSerialized != "Y") //<jq487>
{
//SerialCheck(sProdId
iQtyIdx = GetItemQty(sProdId);
sQuantQuoted = aQuotedQtyArr[iQtyIdx];
sPickQuan = aAllocQtyArr[iQtyIdx];
sQtyDiff = ToNumber(sQuantQuoted) + ToNumber(sQty
if (sQtyDiff <= ToNumber(sPickQuan))//<jq487>
{
sFlg1 = 0;//<jq487> added to accomodate defect 657
SetFieldValue("CMI Parts Check", "Y");//<jq487> added to accomodate defect 657
}
else
{
sFlg2 = 1;//<jq487> added to accomodate defect 657
SetFieldValue("CMI Parts Check", "N
SetFieldValue("CMI Quantity Requested", sPickQuan
}
}
else//added by <JQ487> for defect 657
{
iCount = 1;//added by <JQ487> for defect 657
}
}
else//added by <JQ487> for defect 657
{
iCount = 1;//added by <JQ487> for defect 657
}
/* if(sProdName == sProdVal3)
{
var sProdSta = GetFieldValue("CMI Write-In Status Code");
var sStaCod = TheApplication().InvokeMethod("LookupValue",
"CMI_ONEOFF_STATUS", "SUCCESS");
if(sProdSta == sStaCod)
{
counter = 1;
}
}
else
32
{*/
counter = 1;
}
}
WriteRecord();
}
isRec = NextRecord();
}//end while
//if ((counter == 0)||(iCount == 0))//<
if ((counter == 0)||((sFlg1 == 0) && (sFlg2 == 0 {
//TheApplication().RaiseErrorText("Parts Request cannot be generated as there are no
parts associated to Quote");
sRetCan = "Allow";

}
}//end with
}//end if
}//end With
}// end try
catch(e)
{
//TheApplication().Trace("Error Message : " + e.toString() + e.errCode);
//TheApplication().TraceOff(); throw(e);
}

}
function SerialCheck(sProdId)
{
try
{
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);
33
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)
}//End of try
}//end of function
CMI QUOTE CREATION BS
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if (MethodName == "CreateActivityPlan")
{
sQuoteId = TheApplication().GetProfileAttr("QuoteId");
sTemplateName = Inputs.GetProperty("Context");
var bothis = TheApplication().ActiveBusObject();
switch(bothis.Name())
{
case "Service Request" :
CreateActivityPlan(sTemplateName,sQuoteId);
break;
case "Quote" :
CreateActivityPlanQuote(sTemplateName,sQuoteId);
break;
default:
break;
}
return(CancelOperation);
}
if (MethodName == "UpdateActivityPlanField")
{
sQuoteId = TheApplication().GetProfileAttr("QuoteId");
sTemplateName = Inputs.GetProperty("Context");
UpdateActivityPlanField(sTemplateName,sQuoteId);
return(CancelOperation);
}
return (ContinueOperation);
}
var sTemplateName;
var sQuoteId;

34
function CreateActivityPlan(sTemplateName,sQuoteId)
{
try
{
var oBO = TheApplication().ActiveBusObject();
//var oBCSR = oBO.GetBusComp("Service Request");//Commented:James
//var SRId = oBCSR.GetFieldValue("Id");//Commented:James
var oBCActivityPlan = oBO.GetBusComp("Activity Plan");
var oBCActivityPlanAction = oBO.GetBusComp("Activity Plan Action");
var oBCAction = oBO.GetBusComp("Action");
var oBCQuote = oBO.GetBusComp("Quote");
oBCQuote.ActivateField("Revision");
//var sQuoteId = oBCQuote.GetFieldValue("Id");//Commented:JQ486
//TheApplication().SetProfileAttr("QuoteId",sQuoteId);
//var sQuoteNum = oBCQuote.GetFieldValue("Quote Number");//Commented:JQ486
var sTemplatePickBC;
var isPickBCRec;
var sQuoteId_Temp = TheApplication().GetProfileAttr("CMIRevisionNum");
if(sQuoteId_Temp == "1")
{
DefaultSourceLoc(sQuoteId);
}
/* with(oBCSR)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",SRId);
ExecuteQuery(ForwardBackward);
if(FirstRecord())
{*/
with(oBCActivityPlan)
{
NewRecord(NewAfter);
sTemplatePickBC = oBCActivityPlan.GetPicklistBusComp("Template");
with(sTemplatePickBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Name",sTemplateName);
ExecuteQuery(ForwardBackward);
isPickBCRec = FirstRecord();
if(isPickBCRec)
{
Pick();
}
}
WriteRecord();
oBCActivityPlan.ActivateField("Activity UID");
var sActivityId = oBCActivityPlan.GetFieldValue("Activity UID");
TheApplication().SetProfileAttr("CMIActivityAttribute",sActivityId);
}
35
//}
//}
}// end try
catch(e)
{
TheApplication().Trace("Error Message : " + e.toString() + e.errCode);
TheApplication().TraceOff(); throw(e);
}

}
function CreateActivityPlanQuote(sTemplateName,sQuoteId)
{
var bothis = TheApplication().ActiveBusObject();
//var sRateListId = TheApplication().GetProfileAttr("CMI Rate List Id");//add by woody for GL
var sRateListId;//added by woody
var sCurrencyCode//added by woody
var oBCQuote = bothis.GetBusComp("Quote");
var oBCDivision = bothis.GetBusComp("Internal Division");//added by woody
oBCQuote.ActivateField("CMI Primary Division Id");
var sQuoteId_Temp = TheApplication().GetProfileAttr("CMIRevisionNum");
var sSRId = oBCQuote.GetFieldValue("Service Request Id");//because this field is link specfication no
need to active
var sDivisionId = oBCQuote.GetFieldValue("CMI Primary Division Id");//added by woody
if(sQuoteId_Temp == "1")
{
DefaultSourceLoc(sQuoteId);
}
var boSR = TheApplication().GetBusObject("Service Request");
var bcSR = boSR.GetBusComp("Service Request");
var oBCActivityPlan = boSR.GetBusComp("Activity Plan");
var oBCActivityPlanAction = boSR.GetBusComp("Activity Plan Action");
var isRecord;
var isQuoteRec;//added by woody
var isDivisionRec;//added by woody
with(oBCQuote)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardBackward);
isQuoteRec = FirstRecord()
if(isQuoteRec)
{
with(oBCDivision)
{
SetViewMode(AllView);
ActivateField("CMI Rate List Id");
ActivateField("Currency Code");
ClearToQuery();
SetSearchSpec("Id",sDivisionId);
ExecuteQuery(ForwardBackward);
36
isDivisionRec = FirstRecord()
if(isDivisionRec)
{
sRateListId = GetFieldValue("CMI Rate List Id");
sCurrencyCode = GetFieldValue("Currency Code");
}
}
}
}
with(bcSR)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sSRId);
ExecuteQuery(ForwardBackward);
if(FirstRecord())
{
with(oBCActivityPlan)
{
NewRecord(NewAfter);
var sTemplatePickBC =
oBCActivityPlan.GetPicklistBusComp("Template");
with(sTemplatePickBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Name",sTemplateName);
ExecuteQuery(ForwardBackward);
if(FirstRecord())
{
Pick();
}
}
WriteRecord();
oBCActivityPlan.ActivateField("Activity UID");
var sActivityId = oBCActivityPlan.GetFieldValue("Activity UID");
TheApplication().SetProfileAttr("CMIActivityAttribute",sActivityId);

}// end with(oBCActivityPlan)


with(oBCActivityPlanAction)
{
SetViewMode(AllView);
ActivateField("Parent Activity Id");
ActivateField("CMI Quote Id");
ActivateField("CMI Rate List Id");
ActivateField("Currency Code");
ClearToQuery();
SetSearchSpec("Parent Activity Id",sActivityId);
ExecuteQuery(ForwardBackward);
isRecord = FirstRecord();
if(isRecord)
37
{
SetFieldValue("CMI Quote Id", sQuoteId);
SetFieldValue("CMI Rate List Id", sRateListId);//add by woody for GL
SetFieldValue("Currency Code", sCurrencyCode);//add by woody for GL
WriteRecord()
}
}
}// end if(FirstRecord())
}// end with(oBCSR)
}
function DefaultSourceLoc(sQuoteId)
{
try
{
var ActiveDiv = TheApplication().GetProfileAttr("Primary Division Id");
var sBO = TheApplication().ActiveBusObject();
var sBC = sBO.GetBusComp("Quote");
var NewQuoteId = sQuoteId;
//var sQuoteId = sBC.GetFieldValue("Id");
var sSourceInvLoc = "";
var sSrcLocBC = "";
var sCurrentViewName = TheApplication().ActiveViewName();
if(sCurrentViewName != "CMI Service Request Quote Template List View" &&
sCurrentViewName != "CMI SR Failure Code Quote Template View")
{
with(sBC)
{
/* //revomed by james 22Dec-2010
SetViewMode(AllView);
ActivateField("Source Inventory Location Id");//Added:JQ486
ActivateField("Source Inventory Location");//Added:JQ486
ClearToQuery();
SetSearchSpec("Id", NewQuoteId);
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");
38
}
}
if(sSourceInvLoc != null && sSourceInvLoc != "")
{
sSrcLocBC = sBC.GetPicklistBusComp("Source Inventory Location");
with(sSrcLocBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sSourceInvLoc);
ExecuteQuery(ForwardBackward);
if(FirstRecord())
{
Pick();
}
}
}
//SetFieldValue("Source Inventory Location Id", sSourceInvLoc);//
WriteRecord();
}
}
// remove by james 22Dec-2010}
}

}
function UpdateActivityPlanField(sTemplateName,sQuoteId)
{
try
{
var oBO = TheApplication().ActiveBusObject();
//var sRateListId = TheApplication().GetProfileAttr("CMI Rate List Id");//add by woody for GL
var sRateListId;
var oBCActivityPlan = oBO.GetBusComp("Activity Plan");
var sActivityId = TheApplication().GetProfileAttr("CMIActivityAttribute");
var oBCActivityPlanAction = oBO.GetBusComp("Activity Plan Action");
var oBCAction = oBO.GetBusComp("Action");
var oBCQuote = oBO.GetBusComp("Quote");
var oBCDivision = oBO.GetBusComp("Internal Division");//added by woody
oBCQuote.ActivateField("CMI Primary Division Id");
//var sDivisionId = oBCQuote.GetFieldValue("CMI Primary Division Id");//added by woody //
commented by jx050(pravin)
//var sQuoteId = oBCQuote.GetFieldValue("Id");//Commented:JQ486
//var sQuoteNum = oBCQuote.GetFieldValue("Quote Number");//Commented:JQ486
var sTemplatePickBC;
var isPickBCRec;
var isRecord;
var sCurrActivityId;
var isQuoteRec;//added by woody
var isDivisionRec;//added by woody
var sCurrencyCode//added by woody
with(oBCQuote)
39
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardOnly);
isQuoteRec = FirstRecord();
if(isQuoteRec)
{
var sDivisionId = oBCQuote.GetFieldValue("CMI Primary Division Id");//added by jx050(Pravin)
with(oBCDivision)
{
SetViewMode(AllView);
ActivateField("CMI Rate List Id");
ActivateField("Currency Code");
ClearToQuery();
SetSearchSpec("Id",sDivisionId);
ExecuteQuery(ForwardOnly);
isDivisionRec = FirstRecord();
if(isDivisionRec)
{
sRateListId = GetFieldValue("CMI Rate List Id");
sCurrencyCode = GetFieldValue("Currency Code");
}
}
}
}
if(sTemplateName == "Part Tracker Template")
{
with(oBCActivityPlanAction)
{

SetViewMode(AllView);
ActivateField("CMI Quote Id");
ActivateField("Parent Activity Id");
ClearToQuery();
SetSearchSpec("Parent Activity Id",sActivityId);
ExecuteQuery(ForwardBackward);
isRecord = FirstRecord();
if(isRecord)
{
SetFieldValue("CMI Quote Id", sQuoteId);
WriteRecord();
}

}
}
if(sTemplateName == "Time Tracker Template")
{
with(oBCActivityPlanAction)
{
SetViewMode(AllView);
40
ActivateField("Parent Activity Id");
ActivateField("CMI Quote Id");
ActivateField("CMI Rate List Id");
ActivateField("Currency Code");
ClearToQuery();
SetSearchSpec("Parent Activity Id",sActivityId);
ExecuteQuery(ForwardBackward);
isRecord = FirstRecord();
if(isRecord)
{
SetFieldValue("CMI Quote Id", sQuoteId);
SetFieldValue("CMI Rate List Id", sRateListId);//add by woody for GL
SetFieldValue("Currency Code", sCurrencyCode);//add by woody for GL
WriteRecord();
}
}// end Activity plan action BC
}
}// end try

}
CMI CHECK DISCOUNT PERCENT
//JX050
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if (MethodName == "Check Discount Percent")
{
var oBO;
var oBCQIW;
var PercentAll;
var Percent;
var TotPercent=0;

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"))
{

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","");

41
}
else
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"))
{
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);
}
return (ContinueOperation);
}
CMI ADD CORE PRODUCT
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if (MethodName == "AddCore")
{

//AddCore(sCoreProdId,sQuoteId,sQId,sSeq);
AddCore(Inputs,Outputs);
return(CancelOperation);
}
return (ContinueOperation);
}
function AddCore(Inputs,Outputs)//asCoreProdId,asQuoteId,sQId,sSeq)
{
try
{
var asCoreProdId = Inputs.GetProperty("CMI Recon Pro Id");
var asQuoteId = Inputs.GetProperty("Quote Item Id");
var sQId = Inputs.GetProperty("Quote Id");
var sSeq = Inputs.GetProperty("Sequence No");
var sPriceList = Inputs.GetProperty("Price List");
var sUOM = Inputs.GetProperty("UOM");
var sType = Inputs.GetProperty("Type");
var oProBO = TheApplication().GetBusObject("Admin ISS Product Definition");
var oProBC = oProBO.GetBusComp("Product Recommendation");
with(oProBC)
{
ActivateField("Recommended Product ID");

42
ActivateField("Parent Product ID");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Parent Product ID", asCoreProdId);
SetSearchSpec("UMS Type", 'Core');
ExecuteQuery(ForwardOnly);
var sRecord = FirstRecord();
var lsSequence = ToNumber(sSeq) + 1;
while(sRecord)
{
var sCoreId = GetFieldValue("Recommended Product ID");
var oQuoteO = TheApplication().GetBusObject("Quote");
var oQuoteBC = oQuoteO.GetBusComp("Quote Item");
with(oQuoteBC)
{
NewRecord(NewAfter)
SetFieldValue("Line Number", lsSequence);
SetFieldValue("Quote Id",sQId);
SetFieldValue("Product Id",sCoreId);
SetFieldValue("Parent Quote Item Id", asQuoteId);
SetFieldValue("Root Quote Item Id", asQuoteId);
SetFieldValue("CMI Line Type", TheApplication().InvokeMethod("LookupValue",
"CMI_LINE_TYPE", "Recon Line type"));
SetFieldValue("Item Price List Id", sPriceList);
SetFieldValue("CMI Unit of Measure", sUOM);
WriteRecord();
if(sType == TheApplication().InvokeMethod("LookupValue", "QUOTE_TYPE", "Service Quote"))
{
NewRecord(NewAfter)
lsSequence = lsSequence + 1;
SetFieldValue("Line Number", lsSequence);
SetFieldValue("Quote Id",sQId);
SetFieldValue("Product Id",sCoreId);
SetFieldValue("Parent Quote Item Id", asQuoteId);
SetFieldValue("Root Quote Item Id", asQuoteId);
//SetFieldValue("CMI Line Type", 'Recon Return Line type');
-commented and used LookupValue as per TS review - JW919 17/5/2011
SetFieldValue("CMI Line Type",
TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Recon Return Line type"));
SetFieldValue("Item Price List Id", sPriceList);
SetFieldValue("CMI Unit of Measure", sUOM);
WriteRecord();
}
}
lsSequence = lsSequence + 1;
sRecord = NextRecord();
}
}
var oBS = TheApplication().GetService("SIS OM PMT Service");
var psIO = TheApplication().NewPropertySet();
var psOP = TheApplication().NewPropertySet();
43
psIO.SetProperty("Business Object Name", "Quote");
psIO.SetProperty("Business Component Name", "Quote Item");
oBS.InvokeMethod("Refresh Business Component",psIO,psOP);

}// end try

CMI ACTION COMMON BS


function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if(MethodName == "ConcatTechName")
{
ConcatTechName(Inputs, Outputs);
return CancelOperation;

}
return (ContinueOperation);
}
function ConcatTechName(Inputs, Outputs)
{
try
{
var sName = "";
var sSRId = Inputs.GetProperty("SRId");
Outputs.SetProperty("CatName","");
if(sSRId == "") return;

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)

44
{
var sTempName = GetFieldValue("CMI Owner FullName");
if(sTempName != "")
{
if(sName == "")
sName = sTempName
else
sName = sName +"; "+ sTempName;
}
bHasRecord = NextRecord();
}
Outputs.SetProperty("CatName", sName);
}
}

CMI ACTIVITY CREATION SALES BS

function Service_PreInvokeMethod (MethodName, Inputs, Outputs)


{

if (MethodName == "CreateQuote")
{
sQuoteId = TheApplication().GetProfileAttr("Quote Id");
CreateActivity(sQuoteId);
return(CancelOperation);
}
if(MethodName == "MailToOwner")
{
MailToOwner(Inputs, Outputs);
return CancelOperation;
}

if(MethodName == "SearchFolloUpActivity")
{
SearchFolloUpActivity(Inputs, Outputs);
return CancelOperation;
}

if(MethodName == "UpdateFollowUpActivity")// JW918 07.04.2011.Defect# 490


{
UpdateFollowUpActivity();
return(CancelOperation);
}

return (ContinueOperation);
}
var sQuoteId;
function CreateActivity(sQuoteId)
45
{
try
{
var oBO = TheApplication().GetBusObject("Quote");
var oBCAction = oBO.GetBusComp("Action (Quote Order)");//JQ486:Added Correct BC
var oBCQuote = oBO.GetBusComp("Quote");
var sQType1 = TheApplication().InvokeMethod("LookupValue", "QUOTE_TYPE", "Wholegoods Quote");
var sQtype2 = TheApplication().InvokeMethod("LookupValue", "QUOTE_TYPE", "Parts Quote");
var sQuoteType = TheApplication().InvokeMethod("LookupValue", "QUOTE_TYPE", "Service Quote");
var sActType = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Quote Follow-up");
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;
with(oBCQuote)
{
SetViewMode(AllView);
ActivateField("CMI Status As Of Date Calc");
ActivateField("Quote Display Type");
ActivateField("Sales Team");
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardBackward);
var iCount = CountRecords();
var sType = 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.
if(FirstRecord())
{
// if((sType == sQType1) || (sType == sQtype2))
// {
with(oBCAction)
{
ActivateField("Type");
ActivateField("Planned");
ActivateField("Primary Owner Id");//JQ486:05Jan2011, Added Script.
ActivateField("CMI Owner FullName");
ActivateField("Due");
//jw918 07.04.11 Defect 490.To check for existing followup act
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Quote Id", sQuoteId);
SetSearchSpec("Type", "Quote Follow-up");
ExecuteQuery();
if(FirstRecord())
{
if(sType == sQuoteType) //jw918 07.04.11 Defect 490.
{
ldCurrDate = GetNewDate();
ldCurrDate.setDate(ldCurrDate.getDate()+2);
46
lsCurrDate = DateToString(ldCurrDate);
SetFieldValue("Due",lsCurrDate);
}
else
{
ldCurrDate = GetNewDate();
ldCurrDate.setDate(ldCurrDate.getDate()+7);
lsCurrDate = DateToString(ldCurrDate);
SetFieldValue("Due",lsCurrDate);
}
WriteRecord();
}
else
{
NewRecord(NewAfter);
SetFieldValue("Type",sActType);//JQ486:Setting Type Value
SetFieldValue("Planned",sCalcVar);//JQ486:Setting Started
ValuesTemplatePickBC = oBCActivityPlan.GetPicklistBusComp("Template");
if(sType == sQuoteType) //jw918 07.04.11 Defect 490.
{
ldCurrDate = GetNewDate();
ldCurrDate.setDate(ldCurrDate.getDate()+2);
lsCurrDate = DateToString(ldCurrDate);
SetFieldValue("Due",lsCurrDate);
}
else
{
ldCurrDate = GetNewDate();
ldCurrDate.setDate(ldCurrDate.getDate()+7);
lsCurrDate = DateToString(ldCurrDate);
SetFieldValue("Due",lsCurrDate);
}
SalesRepPickBC = oBCAction.GetPicklistBusComp("CMI Owner FullName");
with(sSalesRepPickBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Login Name",OwnerName);
ExecuteQuery(ForwardBackward);
var isPickBCRec = FirstRecord();
if(isPickBCRec)
{
Pick();
}
}
WriteRecord();
}
var sBS = TheApplication().GetService("SIS OM PMT Service");
var sIP = TheApplication().NewPropertySet();
var sOP = TheApplication().NewPropertySet();
sIP.SetProperty("Business Object Name","Quote");
47
sIP.SetProperty("Business Component Name","Quote");
sBS.InvokeMethod("Refresh Business Component",sIP,sOP);
TheApplication().SetProfileAttr("CMIFollowupActionId", GetFieldValue("Id"));
}//end of with
// }
}
}
}// end try

}
function DateToString(adDate)
{
// fetching day, month, year, hour min and sec and constructing the date string
var lsMonth = ToString(adDate.getMonth() + 1);
var lsDay = ToString(adDate.getDate());
var lsHours = ToString(adDate.getHours());
var lsMinutes = ToString(adDate.getMinutes());
var lsSeconds = ToString(adDate.getSeconds());

if (lsMonth.length == 1)
{
lsMonth = "0" + lsMonth;
}
if (lsDay.length == 1)
{
lsDay = "0" + lsDay;
}
if (lsHours.length == 1)
{
lsHours = "0" + lsHours;
}
if (lsMinutes.length == 1)
{
lsMinutes = "0" + lsMinutes;
}
if (lsSeconds.length == 1)
{
lsSeconds = "0" + lsSeconds;
}
if (lsHours == "00" && lsMinutes == "00" && lsSeconds == "00")
return (lsMonth +"/"+ lsDay +"/" + adDate.getFullYear())
else
return (lsMonth +"/"+ lsDay +"/" + adDate.getFullYear() +" "+lsHours+":"+lsMinutes+":"+lsSeconds);
}
function GetNewDate()
{
try
{
var ldcurrtm = Clib.localtime(Clib.time());
var lsmonth = ldcurrtm.tm_mon + 1;

48
var lsyear = ldcurrtm.tm_year + 1900;
var lsday = ldcurrtm.tm_mday;
var lshour = ldcurrtm.tm_hour;
var lsmin = ldcurrtm.tm_min;
var lssec = ldcurrtm.tm_sec;
var lsfulldate = lsmonth + '/' + lsday + '/' + lsyear + ' ' + lshour + ':' + lsmin + ':' + lssec;
var lsnewdate = new Date(lsfulldate);
// return(lsnewdate);

}
return(lsnewdate);
}
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);
}

}
function SearchFolloUpActivity()
{
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;

49
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 lsCount = CountRecords();
var lsRecord = FirstRecord();

while(lsRecord)
{
var lsDueDate = GetFieldValue("Due");
var lsId = GetFieldValue("Id");
MailToOwner(lsId);
SetFieldValue("Time Sheet Related Flag","Y");
lsRecord = NextRecord();
}
}
}

}
function UpdateFollowUpActivity()
{
try
{
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);
if(FirstRecord())
{
SetFieldValue("Status",lsStatus);
}
WriteRecord();
}
50
var sBS = TheApplication().GetService("SIS OM PMT Service");
var sIP = TheApplication().NewPropertySet();
var sOP = TheApplication().NewPropertySet();
sIP.SetProperty("Business Object Name","Quote");
sIP.SetProperty("Business Component Name","Quote");
sBS.InvokeMethod("Refresh Business Component",sIP,sOP);
TheApplication().SetProfileAttr("CMI AccQuote Id","");
}

}
CMI ADD ORDER ID TO TRACKER ACTIVITY
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if (MethodName == "AddOrderId")
{
var sQuoteNumber = Inputs.GetProperty("QuoteNumber");
var sOrderId = Inputs.GetProperty("OrderId");
AddOrderId(sQuoteNumber, sOrderId);
return (CancelOperation);
}
return (ContinueOperation);
}
function AddOrderId(sQuoteNumber, sOrderId)
{
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)
}
CMI BATCH PAYMENT PROCESS BS
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
51
{
if (MethodName == "BatchCloseProcess")
{
BatchCloseProcess();
return(CancelOperation);
}
if (MethodName == "PaymentVarianceCheck")
{
PaymentVarianceCheck();
return(CancelOperation);
}
if (MethodName == "BatchPaymentCheck")
{
BatchPaymentCheck();
return(CancelOperation);
}
/*if (MethodName == "RefileCheck")
{
RefileCheck();
return(CancelOperation);
}*/
return (ContinueOperation);
}
function BatchCloseProcess()
{
try
{
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 iPayVariance = 0;
var iVarToLevel;
with(oBCBatchPaymemt)
{
InvokeMethod("SetAdminMode", "TRUE");
SetViewMode(AllView);
ActivateField("Payment Status");
ActivateField("Claim #");
ClearToQuery();
SetSearchSpec("Deposit Id", sBatchId);
SetSearchSpec("Payment Status",
TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Pending"));
ExecuteQuery(ForwardOnly);
var HasRecord = FirstRecord();
52
while (HasRecord)
{
sClaimId = GetFieldValue("Claim Id");
with(oBCClaim)
{
InvokeMethod("SetAdminMode", "TRUE");
SetViewMode(AllView);
ActivateField("CMI Payment Variance Sum");
ActivateField("CMI Variance Tolerance Level");
ActivateField("Status Code");
ClearToQuery();
SetSearchSpec("Id", sClaimId);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
iPayVariance = GetFieldValue("CMI Payment Variance Sum");
iVarToLevel = GetFieldValue("CMI Variance Tolerance Level");
if (ToNumber(iVarToLevel) < ToNumber(iPayVariance))
{
SetFieldValue("Status Code",
TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Payment Received"));
WriteRecord();
}
else if (ToNumber(iVarToLevel) >= ToNumber(iPayVariance) && Math.abs(ToNumber(iPayVariance))> 0)
{
with(oBCPayment)
{
NewRecord(1);
ActivateField("Payment Amount");
ActivateField("Payment Type Code");
ActivateField("Payment Status");
//ActivateField("CMI Payment Credit Type
SetFieldValue("Payment Amount", iPayVariance);
SetFieldValue("Payment Type Code",
TheApplication().InvokeMethod("LookupValue","CMI_PAYMENT_TYPE","Variance"));
SetFieldValue("CMI Payment Credit Type",
TheApplication().InvokeMethod("LookupValue","CMI_PAY_CDT_TYPE","Consolidate"));
SetFieldValue("Payment Status",
TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Verified"));
WriteRecord();
}
SetFieldValue("Status Code",
TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Closed"));
WriteRecord();

}
else if (ToNumber(iPayVariance) == 0)
{
SetFieldValue("Status Code",
TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Closed"));
WriteRecord();
53
}
}
}
SetFieldValue("Payment Status",
TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Verified"));
WriteRecord();
HasRecord = NextRecord();

}
oBC.InvokeMethod("RefreshBusComp");
}

}
function BatchPaymentCheck()
{
try
{
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 iClaimNumber;
var iClaimId;
var sPayVariance = 0;
var sVarToLevel;
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");
with(oBCClaim)
{
InvokeMethod("SetAdminMode", "TRUE");
SetViewMode(AllView);
ActivateField("CMI Payment Variance Sum");
ActivateField("CMI Variance Tolerance Level");
ActivateField("Status Code");
54
ClearToQuery();
SetSearchSpec("Id", iClaimId);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
sPayVariance = GetFieldValue("CMI Payment Variance Sum");
sVarToLevel = GetFieldValue("CMI Variance Tolerance Level");
if (ToNumber(sVarToLevel) < ToNumber(sPayVariance))
{
SetFieldValue("Status Code",
TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Payment Received"));
WriteRecord();
}
else if (ToNumber(sVarToLevel) >= ToNumber(sPayVariance) && ToNumber(sPayVariance) > 0)
{
with(oBCClaimPayment)
{
ActivateField("Payment Amount");
ActivateField("Payment Type Code");
ActivateField("Payment Status");
ActivateField("CMI Payment Credit Type");
NewRecord(1);
SetFieldValue("Payment Amount", sPayVariance);
SetFieldValue("Payment Type Code",
TheApplication().InvokeMethod("LookupValue","CMI_PAYMENT_TYPE","Variance"));
SetFieldValue("Payment Status",
TheApplication().InvokeMethod("LookupValue","FUNDRQ_STATUS","Verified"));
SetFieldValue("CMI Payment Credit Type",
TheApplication().InvokeMethod("LookupValue","CMI_PAY_CDT_TYPE","Consolidate"));
WriteRecord();
}
SetFieldValue("Status Code",
TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Closed"));
WriteRecord();
}
else if (ToNumber(sPayVariance) == 0)
{
SetFieldValue("Status Code",
TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Closed"));
WriteRecord();
}
}
}
WriteRecord();
HasRecord = NextRecord();
}
}
oBCBatch.InvokeMethod("RefreshBusComp");
}

}
55
function PaymentVarianceCheck()
{
try
{
var oBO = TheApplication().ActiveBusObject();
var oBC = oBO.GetBusComp("INS Claims");
var oBCPayment = oBO.GetBusComp("INS Claims Payments");
var iClaimTotal;
var iPayVariance;
var iVarToLevel;
var iPaymentType;
iPaymentType = oBCPayment.GetFieldValue("Payment Type Code");
with(oBC)
{
iPayVariance = GetFieldValue("CMI Payment Variance Sum");
iVarToLevel = GetFieldValue("CMI Variance Tolerance Level");
if (ToNumber(iPayVariance)!= 0)
{
if(iPaymentType=='Variance'){
SetFieldValue("Status Code",
TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Variance Created"));
}
WriteRecord();
}
else if (ToNumber(iPayVariance) == 0)
{
SetFieldValue("Status Code",
TheApplication().InvokeMethod("LookupValue","INS_CLAIM_STATUS","Closed"));
WriteRecord();
}
}
}
}

CMI CTI
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if (MethodName == "Transfer")
{
//For transfer
var sActivityID; var boAction; var bcAction; var sFullName;
sActivityID = Inputs.GetProperty("ActivityID");
boAction = TheApplication().GetBusObject("Action");
bcAction = boAction.GetBusComp("Action");
with (bcAction)
{
//Query by Activity ID
SetViewMode(AllView);

56
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());
}
}
return (ContinueOperation);
}
CMI CATCH PROPERTYSET INTEGRATION
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{ var psTemp;
try
{
if(MethodName == "StorePS")
{
{
psTemp = Inputs.Copy();
}
return (CancelOperation);
}
if(MethodName == "RecallPS")
{
Outputs.AddChild(psTemp.Copy());
return (CancelOperation);
}

if(MethodName == "ClearPS")

57
{
psTemp = null;
return (CancelOperation);
}
}
return (ContinueOperation);
}
CMI CALCULATE PRICE BS
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if(MethodName == "CalculatePrice")
{
var sId = Inputs.GetProperty("RowId");
CalculatePrice(sId);
return(CancelOperation);
}
if(MethodName == "WholegoodsItemPrice") //added by Elen Yu
{
WholegoodsItemPrice(Inputs, Outputs);
return(CancelOperation);
}
if(MethodName == "OptionPricing")
{
OptionPricing(Inputs, Outputs);
return(CancelOperation);
}
return (ContinueOperation);
}

}
function CalculatePrice(sId)
{
try
{
var sBO = TheApplication().ActiveBusObject();
var sBC = sBO.GetBusComp("Quote");
var sItemBC = sBO.GetBusComp("Quote Item");
var isRecord; var isItemRecord; var sInputMargin="";
var sCost; var sProdType; var sDisAmt ;
var sRetainListPrice; var sListPrice; var sCostCalc;
var sSSAField; var sEBSPrice;
with(sBC)
{
SetViewMode(AllView);
ActivateField("CMI Input Margin");
ClearToQuery();
SetSearchSpec("Id", sId);
ExecuteQuery(ForwardOnly);

58
isRecord = FirstRecord();
if(isRecord)
{
sInputMargin = GetFieldValue("CMI Input Margin");
}
with(sItemBC)
{
SetViewMode(AllView);
ActivateField("Cost");
ActivateField("CMI Retain List Price Flag");
ActivateField("Unit Price");
ActivateField("Adjusted List Price");
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");
sListPrice = GetFieldValue("Adjusted List Price");
sCostCalc = GetFieldValue("Write-In Product Flag");
sSSAField = GetFieldValue("CMI SSA Amount");
sEBSPrice = GetFieldValue("CMI EBS Net Price");
if(sRetainListPrice == "N" || sRetainListPrice == "" || sRetainListPrice == null)
{
sDisAmt = SetLIPrice(sInputMargin,sCost,sSSAField);
SetFieldValue("Unit Price",sDisAmt);
if(sCostCalc == "Y")
{
SetFieldValue("Cost",sCost);
}
WriteRecord();
}
else
{
/* SetFieldValue("Unit Price", sListPrice); */
SetFieldValue("Unit Price", sEBSPrice); //Added Mar03
if(sCostCalc == "Y")
{
SetFieldValue("Cost",sCost);
}
WriteRecord();
}
isItemRecord = NextRecord();
}//end of isItemRecord
}//end of Quote Item BC query
sBC.InvokeMethod("RefreshBusComp");
59
}//end of Quote BC query
return(CancelOperation);
}//end of try
}
function OptionPricing(Inputs, Outputs)
{
try
{
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");/
SetSearchSpec("Quote Id", sQuoteId);
ExecuteQuery(ForwardOnly);
var iCount = CountRecords();
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");
60
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);
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)
{
SetFieldValue("CMI Quote Total", sOptionPriceTotal);
SetFieldValue("CMI Total Cost", sOptionCostTotal);
SetFieldValue("CMI SSA Amount Option Total", sOptionSSAAmountTotal);
WriteRecord();
}
HasRecord = NextRecord();
}
}
}

}
function SetLIPrice(sInputMargin,sCost,sSSAField)
{
try
{ 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;
61
}
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
sManualPriceOveride = (sItemCost - sSSA)/temp2;
}
return(sManualPriceOveride);

}
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");
var oBOQuote = TheApplication().ActiveBusObject();
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;
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)
62
{
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");
if(sRetainListPrice == "N" || sRetainListPrice == "" || sRetainListPrice == null)
{
sDisAmt = SetLIPrice(sInputMargin,sCost,sSSAField);
SetFieldValue("Unit Price",sDisAmt);
WriteRecord();
}
if (ParentQuoteItemId == "" || ParentQuoteItemId == null)
{
if (sTotalCost != "" && sTotalCost != null)
{
sQuoteTotal = SetLIPrice(sInputMargin, sTotalCost,sSSAField);
SetFieldValue("CMI Quote Total", sQuoteTotal);
WriteRecord();
}
}
isItemRecord = NextRecord();
}//end of isItemRecord
}
}
with(oBCQuoteItem)
{
SetViewMode(AllView);
ClearToQuery()
SetSearchSpec("Quote Id", sQuoteId);
ExecuteQuery(ForwardBackward);
}
}// end try
}

63

You might also like