Thursday, November 20, 2014

On Siebel Tools Wizards

 

The other day I was debugging a business component configuration to identify the cause of wrong data appearing in the UI, as well as a degradation in performance. After spooling the SQL, I found the reason was that some Multi-Value-Fields were configured incorrectly. I showed the developer an easier and more accurate way of doing configuring MVFs, turns out he or no-one in the team knew about Siebel Tool's many wizards.

 

To add an MVF to , say the Service Request BC:

1: Lock the BusComp, and right click.

 FADV Go Live Test 032

2: Choose the "New MVG" option from the menu:

FADV Go Live Test 033

3: Now you just need to follow the Wizard. Enter the Detail Business Component name and name for the MVL:

FADV Go Live Test 035

4: The link has to be configured ahead and should be available in the next screen. Here I am adding a BusComp for BIP reporting purpose. There is a small bug in this Wizard, it shows the caption of Link's SearchSpec and SortSpec are swapped. so that Sortspec is actually the link searchspec.

FADV Go Live Test 037

If there is no direct link between the entities, the Wizard will allow you to use indirect links, where you have to specify the Source field from the Master Business Component

image

 

5: The next screen is the most important, it allows setting of Primary options in the MVL:

FADV Go Live Test 038

6: Further configuration in the link, since this is a reporting link, I have made it read only by setting NoInsert,NoUpdate and NoDelete to true.

FADV Go Live Test 039

7: Now the MVL is configured, you can start configuring which all fields from the Detail Business Component should appear in the Master Business Component, in this case, Service Request:

FADV Go Live Test 040

8: That's it !

FADV Go Live Test 041

9: On Clicking Finish, Tools will start another Wizard to help you configure the MVG applets. After the first screen , the rest is similar to the Applet Wizard.

image

 

 

 

 

When I need to find in which applets a certain field is exposed, I use the similar PickList Wizard to find that out quickly.

1: For instance, to see all applets where the "Abstract" field of Service Request BC is exposed, simply right click on the field and choose "Add Picklist"

image

 

2:  The first screen of the Wizard shows all the applets where this field is exposed:

image

3: Nope, the list cannot be exposed from the wizard, you can only see the applet names. But if there are too many applets, I use Sys Exporter (that's a bad name for useful software) to export out the list into CSV:

image

 

There are rumours that in future releases, Oracle might remove Siebel Tools completely, I just hope they retain all those wizards to speedup development.

Friday, November 7, 2014

BIP: If , then ,else

 

Looks like whole of the Siebel community has moved onto Open UI, but I am spending more and more time into Siebel-BI Publisher reports and their Integration. I had to setup a really, really complex report template for our Order Management module. The final report has 65 for loops and 162 if conditions , and 85 set_variables ! Though BIP’s function set is nicely documented, there are times, I felt, when a requirement could not be implemented as easily as it seemed. Specially when it comes to condition checks. Here are a few pointers if you get lost.

1: If condition: The function is

<?if:[condition]?>
[statements]
<?end if?>

The actual condition has to be provided after the colon (:) after the if statement. The statements to be executed are to be provided before the <?end if?> tag. For some reason, BIP inserts a new line in the report whenever it sees an if tag.

2: If Inlines:

<?if@inlines:[condition]?>
[statements]
<?end if?>

Same as the if condition above, but @inlines statement prevents BIP from inserting a new line in the output report.

3: If @row  and @column. 

<?if@row:[condition]?>
[statements]
<?end if?>

<?if@column:[condition]?>
[statements]
<?end if?>

 

These are to be used in grid layouts/tables to ensure the output of the condition is printed in the same row or column. Otherwise the output gets wrapped into next rows/columns.

4: If @ context.

<?if@incontext:[condition]?>
[statements]
<?end if?>

The '@incontext' is a useful addition to the 5.6.3 release shortening code requirements further to update attributes, when dealing with text output.

As long as the condition checks are straight, these functions prove enough. But things start getting tricky when you need the else clauses , or to build else-if ladders.

5: if-else. Syntax

<?xdoxslt:ifelse([condition],[true statements],[false statements])?>

A simple if-else check, this function is in the xdoxslt namespace. the [true statements] are executed if the condition is evaluated to true, and [false statements] are executed if not. New lines are not inserted for this function.

6:  else if ladder. Syntax

<?xdofx:if [condition 1] then [true 1] else if [condition 2] then [true 2] end if?>

This xdofx function is used when complex else-if ladders need to be built. It can also be used as simple if else condition, so the second if [condition 2] is not required. New lines are not inserted for this function.

 

The @inlines, @incontext, @row, @column statements can only be used with for-each loops, to avoid the newlines inserted automatically by BIP

eg:  <?for-each@inlines:

 

tmp9B00

Hope this is useful, Happy BIP !

Wednesday, October 15, 2014

Siebel public facing applications SSL SHA1 – SHA 2 encryption message changes

 

Microsoft and Google announced SHA-1 deprecation plans that may affect websites with SHA-1 certificates expiring as early as after December 31, 2015.

As per oracle there is no plan to support SHA-2 before 2016 that is Innovation pack 2015.

According to Google’s blog on “Gradually Sunsetting SHA-1”, Chrome version 39 and later will display visual security indicators on sites with SHA-1 SSL certificates with validity beyond January 1, 2016. The production release of Chrome 39 is expected to be in November, 2014. The sites will be treated with one of the following indicators: “secure, but with minor errors” (lock with yellow triangle), “neutral, lacking security” (blank page icon) and “affirmative insecure” (lock with a red X). In order to prevent online users on Chrome version 39 and later from experiencing these indicators, SHA-1 SSL certificates expiring after December 31, 2015 must be replaced with SHA-256 (SHA-2) certificates.

Microsoft’s SHA-1 deprecation plan differs in the activation time and browser behavior. Microsoft’s security advisory on “Deprecation of SHA-1 Hashing Algorithm for Microsoft Root Certificate Program” informed us that Windows will cease accepting SHA-1 SSL certificates on January 1, 2017. To continue to work with Microsoft platforms, all SHA-1 SSL certificates issued before or after this announcement must be replaced with a SHA-2 equivalent by January 1, 2017.

 

https://www.symantec.com/page.jsp?id=sha2-transition

http://blog.chromium.org/2014/09/gradually-sunsetting-sha-1.html

https://technet.microsoft.com/library/security/2880823

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", sShipAddrId);
SetFieldValue("CMI Ship To Profile Id", sShipProfId);
SetFieldValue("Item Price List Id", sPriceList);
SetFieldValue("CMI Unit of Measure", sUOM);
if (newParent != "") {
if (coveredItemId != "") SetFieldValue("Covered Quote Item Id", newParent);
if (parentItemId != "") SetFieldValue("Parent Quote Item Id", newParent);
}
WriteRecord();
}
lineQtyUpdated = false;
var iNewCurrRowId = GetFieldValue("Id");
isRecord1 = NextRecord();
iProcessed += 1
newParent = "";
FKName = "";
validateSRT = true;
}
}
}//end of if
}//end if not respec
//If any lines are successfully added/updated, Execute SRT Validation against all lines last so that any
//validation messages can be thrown to the user after the quote template lines are already added (DBUNG00000289)
if (validateSRT) {
var sSRTValidaitonService = TheApplication().GetService("CMI SRT Validation Service");
var psInput = TheApplication().NewPropertySet();
var psOutput = TheApplication().NewPropertySet();
psInput.SetProperty("Quote Id", sPickQuoteId);
psInput.SetProperty("SR Product Line", sSRProdLine);
psInput.SetProperty("SR Access Code", sSRAccessCode);
sSRTValidaitonService.InvokeMethod("SRT Validation",psInput,psOutput);
var sSRTFailCount = psOutput.GetProperty("SRT Fail Count");
}
//DBUNG00002972 added validation to stop Failure code creation for null Fail Code by ki795 on 16-Nov-2011
if ( TheApplication().ActiveViewName() == "CMI Service Request Quote Template List View") {
if (sFailCdId != "" && sFailCdId != null)
CreateFailureCode(sFailCdId, sSerReqId);
}
TheApplication().Utility.logVars("SRT Fail Count", sSRTFailCount);
if(sSRTFailCount > 0) {
TheApplication().RaiseError("CMI SRT Error Notification", sSRTFailCount);
}
//Nag - Start; 3/6/2012; Fix for Refresh Issue after the Quote is created. CQ# 5277
/*if(sStatus != TheApplication().InvokeMethod("LookupValue", "QUOTE_STATUS", "In Progress"))
{
TheApplication().ActiveBusObject().GetBusComp("Quote").ClearToQuery();
TheApplication().ActiveBusObject().GetBusComp("Quote").ExecuteQuery(ForwardOnly);
}
//Nag - End; 3/6/2012; Fix for Refresh Issue after the Quote is created. CQ# 5277*/
} //End of 1st else
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
sSRTValidaitonService = null;
boSR = null;
bcSR = null;
bcQuoteItem = null;
bcQuote = null;
bcQuoteTemplateItem = null;
bcQuoteTemplate = null;
bcActiveTemplate = null;
boActive = null;
boQuoteTemplate = null;
psInput = null;
psOutput = null;
psIO = null;
psOP = null;
oBS = null;
TheApplication().SetProfileAttr("QuoteTemplateName", "")
TheApplication().Utility.logUnstack();
}
}

CMI SR Add Quote Template to Quote
(declarations)
var lineQtyUpdated = false;

CMI SR Add Quote Template to Quote
RemoveWarranty
//JX050 - function to remove all the warranties associated to the quote
function RemoveWarranty(mode)
{
try {
TheApplication().Utility.logStack("RemoveWarranty", 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 oBCQIW = oBO.GetBusComp("CMI Quote Item Warranty");
var sWarrantyId;//Added by jj953 on Jun 30 2011
var selected = false;
var quoteRecord = oBCQuote.FirstSelected();
//This prevents the RT Event from firing to recalculate the Line level denormalized fields after each delete
TheApplication().SetProfileAttr("isDefaultWarranty", "Y");
while(quoteRecord) {
var QuoteId = oBCQuote.GetFieldValue("Id");
TheApplication().Utility.logStep("Remove warranty from quote ("+QuoteId+")");
with(OBCQuoteItem) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI SR Id", SRId);
SetSearchSpec("Quote Id", QuoteId);
ExecuteQuery(ForwardBackward);
var IsQuoteItemRec = FirstRecord();
TheApplication().Utility.logVars("1st Quote Item Found?", IsQuoteItemRec);
while(IsQuoteItemRec) {
var QuoteItemID = GetFieldValue("Id");
selected = oBCSRWarranty.FirstSelected();
while (selected) {
sWarrantyId = oBCSRWarranty.GetFieldValue("Id")
with(oBCQIW) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Parent Id", QuoteItemID);
if (mode == "SELECTED") SetSearchSpec("CMI SR Warranty Id", sWarrantyId);//Added by jj953 on Jun 30 2011
ExecuteQuery(ForwardBackward);
var IsWarrantyRec = FirstRecord();
while(IsWarrantyRec) {
TheApplication().Utility.logVars("Remove Warranty Id", GetFieldValue("Id"));
DeleteRecord();
IsWarrantyRec = FirstRecord();
}
}
if (mode == "SELECTED") selected = oBCSRWarranty.NextSelected();
else selected = false;
}
//To avoid setting the field twice on Apply Default Warranty
UpdateQIFields(OBCQuoteItem);
IsQuoteItemRec = NextRecord();
}
}
quoteRecord = oBCQuote.NextSelected();
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
oBCQIW = null;
OBCQuoteItem = null;
oBCQuote = null;
oBCSRWarranty = null;
oBO = null;
TheApplication().SetProfileAttr("isDefaultWarranty", "");
TheApplication().Utility.logUnstack();
}
}

CMI SR Add Quote Template to Quote
ValidateSRWarranty
/*Created By : JR419
Created On : 03-Aug-2011
Method Name: ValidateSRWarranty
Defect Number: DBUNG00001037
Functionality: There will have a error message showing while total warranty amount in Labour, Parts, Misc is greater than 100%.
*/
function ValidateSRWarranty() {
try {
TheApplication().Utility.logStack("ValidateSRWarranty", this);
var oBO = TheApplication().ActiveBusObject();
TheApplication().Utility.logVars("Active BO", oBO.Name());
if(oBO.Name()=="Service Request") {
var oBCSR = oBO.GetBusComp("Service Request");
var oBCSRWarranty = oBO.GetBusComp("CMI Service Request Warranty");
var iSRId = oBCSR.GetFieldValue("Id");
var iSumLabour = 0;
var iSumMisc = 0;
var iSumParts = 0;
var iDefPartPercent = 0;
var iDefLaborPercent = 0;
var iDefMiscPercent = 0;
var hasRecord;
with(oBCSRWarranty) {
SetViewMode(AllView);
ActivateField("CMI Default Part Percentage");
ActivateField("CMI Default Labor Percentage");
ActivateField("CMI Default Misc Percentage");
ClearToQuery();
SetSearchSpec("CMI Parent SR Id", iSRId);
ExecuteQuery(ForwardOnly);
hasRecord = FirstRecord();
while(hasRecord) {
iDefPartPercent = GetFieldValue("CMI Default Part Percentage");
iDefLaborPercent = GetFieldValue("CMI Default Labor Percentage");
iDefMiscPercent = GetFieldValue("CMI Default Misc Percentage");
iSumLabour = ToNumber(iSumLabour) + ToNumber(iDefLaborPercent);
iSumMisc = ToNumber(iSumMisc) + ToNumber(iDefMiscPercent);
iSumParts = ToNumber(iSumParts) + ToNumber(iDefPartPercent);
hasRecord = NextRecord();
}
ClearToQuery();
ExecuteQuery();
}
TheApplication().Utility.logVars("Parts / Labor / Misc", iSumParts+" / "+iSumLabour+" / "+iSumMisc);
if(ToNumber(iSumParts)>100) {
TheApplication().RaiseErrorText("Sum of Parts Warranty % should not be greater than 100");
}
if(ToNumber(iSumLabour)>100) {
TheApplication().RaiseErrorText("Sum of Labour Warranty % should not be greater than 100");
}
if(ToNumber(iSumMisc)>100) {
TheApplication().RaiseErrorText("Sum of Misc Warranty % should not be greater than 100");
}
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
oBCSRWarranty = null;
oBCSR = null;
oBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI SR Create Quote From Template BS
CreateFailureCode
//pankaj - function to failure code assosciated to the template if it is already not associated to SR
function CreateFailureCode(sFailCdId, sSRID, sFailMode, sFailModeId)
{
try
{
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);
ActivateField("CMI Mode");
ActivateField("CMI Mode Code Id");//<Bug # DBUNG00000285><Configration> Added script to populate Mode Id instead of Mode<By>JQ487<On>8-Aug-2011
ClearToQuery();
SetSearchSpec("CMI Parent SR Id", sSRID);
SetSearchSpec("CMI Failure Id", sFailCdId);
ExecuteQuery(ForwardOnly);
isRec = FirstRecord();
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);
//SetFieldValue("CMI Mode", sFailMode);
SetFieldValue("CMI Mode Code Id", sFailModeId)//<Bug # DBUNG00000285><Configration> Added script to populate Mode Id instead of Mode<By>JQ487<On>8-Aug-2011
WriteRecord();
}
}
}
catch(e)
{
throw(e);
}
finally
{
sFailPickBC = null;
sFailBC = null;
sFailBO = null;
}
}

CMI SR Create Quote From Template BS
(declarations)
var sSRTCount = 0;

CMI SR Create Quote From Template BS
CopyQuoteTemplate
function CopyQuoteTemplate()
{
try {
TheApplication().Utility.logStack("CopyQuoteTemplate", this);
var strSearchOLI;
var oBO:BusObject = TheApplication().ActiveBusObject();
var oBCSR:BusComp = oBO.GetBusComp("Service Request");
var oBCQuoteTemplate:BusComp = null;
if (TheApplication().GetProfileAttr("ActiveViewName") == "CMI SR Failure Code Quote Template View") {//Use profile attribute instead of Application method name as part of the Code Clean Up Activity
oBCQuoteTemplate = oBO.GetBusComp("Quote Template");
} else if (TheApplication().GetProfileAttr("ActiveViewName") == "CMI Service Request Quote Template List View") {
oBCQuoteTemplate = oBO.GetBusComp("CMI Quote Template");
}
var sId = oBCQuoteTemplate.GetFieldValue ("Id");
var sSRID = oBCSR.GetFieldValue("Id");
var sSRAccessCode = oBCSR.GetFieldValue("CMI SR Access Code");
var sSRPL = oBCSR.GetFieldValue("CMI Product Line Name");//CMI <Release# 1DBU>,Defect #DBUNG000000289 <Configuration>: <added new getfieldvalue for gettign Product Line from SR> By JQ487 On 07/11/11
var sSiteId = oBCSR.GetFieldValue("CMI Ship To Profile Id"); //Added by Riju On 03/27/2011 for defaulting Ship to Site on Quote and Line item
var sSiteAddrId = oBCSR.GetFieldValue("CMI Service Location Address Id");
var oBOQ:BusObject = TheApplication().GetBusObject("CMI Quote");
var oBCQuote:BusComp = oBOQ.GetBusComp("CMI Quote Simple");
var oBCQuoteItem:BusComp = oBOQ.GetBusComp("CMI Quote Item Lite");
var sSRTValid;
var sNewQuoteId="";
var oPckBC:BusComp;
with (oBCQuote) {
SetViewMode(AllView);
ActivateField("Quote Display Type");
ActivateField("CMI Service Request Number");
ActivateField("CMI Template Flag");
ActivateField("CMI Failure Id");
ActivateField("CMI Ship To Profile Name");
ClearToQuery();
SetSearchSpec("Id",sId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Quote Template ("+sId+") found?", FirstRecord());
if (FirstRecord()) {
NewRecord(NewAfterCopy);
SetFieldValue("Quote Display Type", TheApplication().InvokeMethod("LookupValue", "QUOTE_TYPE", "Service Quote"));
SetFieldValue("CMI Template Flag", "N");
SetFieldValue("Service Request Id", sSRID);
SetFieldValue("CMI Failure Id","");
oPckBC = oBCQuote.GetPicklistBusComp("CMI Ship To Profile Name");
with (oPckBC) {
ClearToQuery();
SetSearchSpec("Id", sSiteId);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) {
Pick();
//MJB 8/9/12 Only set address if site pick was successful since it is visibility constrained
oBCQuote.SetFieldValue("CMI Ship To Address Id", sSiteAddrId);//Added by Riju On 03/27/2011 for defaulting Ship to Site on Quote and Line item
}
}
oPckBC = oBCQuote.GetPicklistBusComp("CMI Service Request Number");
with (oPckBC) {
ClearToQuery();
SetSearchSpec("Id", sSRID);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) Pick();
}
WriteRecord();
sNewQuoteId = GetFieldValue("Id");
var oSRBusObject:BusObject = TheApplication().GetBusObject("Quote"); // CMI<DBU> added for refresh issue by ki795 on 10-Oct-2011
var oBCQuoteLineItem = oSRBusObject.GetBusComp("Quote Item (Simple)");
TheApplication().Utility.logVars("New Quote Id", sNewQuoteId, "SR Product Line", sSRPL);
//CQ289: added loop for setting Product Line on Quote Item. Also sync recon products
with (oBCQuoteLineItem) {
SetViewMode(AllView);
ActivateField("Quote Id");
ActivateField("Parent Quote Item Id");
ActivateField("Covered Quote Item Id");
ActivateField("CMI Ship To Profile Name");
ActivateField("Ship To Address Id");
ClearToQuery();
SetSearchSpec("Quote Id",sNewQuoteId);
ExecuteQuery(ForwardBackward);
var isRec = FirstRecord();
while(isRec) {
if (sSRPL != null && sSRPL != "") {
SetFieldValue("CMI Product Line", sSRPL);
}
if (GetFieldValue("Parent Quote Item Id") != "" || GetFieldValue("Covered Quote Item Id") != "") {
var oBS = TheApplication().GetService("CMI Add Core Product");
var psIO = TheApplication().NewPropertySet();
var psOO = TheApplication().NewPropertySet();
psIO.SetProperty("Quote Id", sNewQuoteId);
psIO.SetProperty("Covered Quote Item Id", GetFieldValue("Covered Quote Item Id"));
psIO.SetProperty("Parent Quote Item Id", GetFieldValue("Parent Quote Item Id"));
oBS.InvokeMethod("FixTemplateFKs",psIO,psOO);
var newParent = psOO.GetProperty("Parent Quote Item Id");
TheApplication().Utility.logVars("Parent/Covered Line - Updated to", GetFieldValue("Parent Quote Item Id")+" / "+GetFieldValue("Covered Quote Item Id")+" - "+newParent);
if (newParent != "") {
if (GetFieldValue("Covered Quote Item Id") != "") SetFieldValue("Covered Quote Item Id", newParent);
if (GetFieldValue("Parent Quote Item Id") != "") SetFieldValue("Parent Quote Item Id", newParent);
}
}
var oBC = oBCQuoteLineItem.GetPicklistBusComp("CMI Ship To Profile Name");
with (oBC) {
ClearToQuery();
SetSearchSpec("Id", sSiteId);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) Pick();
}
WriteRecord();
isRec = NextRecord();
}
}
//DBUNG00002977 moved the SRT logic to a seperate BS due to memory issues by ki795 on 14-Nov-2011
var sSRTValidationService = TheApplication().GetService("CMI SRT Validation Service");
var psInput = TheApplication().NewPropertySet();
var psOutput = TheApplication().NewPropertySet();
psInput.SetProperty("Quote Id", sNewQuoteId);
psInput.SetProperty("SR Product Line", sSRPL);
psInput.SetProperty("SR Access Code", sSRAccessCode);
sSRTValidationService.InvokeMethod("SRT Validation",psInput,psOutput);
sSRTCount = psOutput.GetProperty("SRT Fail Count");
}
}
// Go to 'CreateFailureCode' Function
if ( TheApplication().GetProfileAttr("ActiveViewName") == "CMI Service Request Quote Template List View") {
var sFailCdId = oBCQuoteTemplate.GetFieldValue("CMI Failure Id");
if (sFailCdId != "" && sFailCdId != null) {//DBUNG00002972 added validation to stop Failure code creation for null Fail Code by ki795 on 16-Nov-2011
oBCQuoteTemplate.ActivateField("CMI Fail Mode");//CMI <Release# 1DBU>,Defect #DBUNG000000289 <Configuration>: <getting field value for fail mode> By JQ487 On 07/13/11
oBCQuoteTemplate.ActivateField("CMI Fail Mode Id");//<Bug # DBUNG00000285><Configration> Added script to populate Mode Id instead of Mode<By>JQ487<On>8-Aug-2011
var sFailMode = oBCQuoteTemplate.GetFieldValue("CMI Fail Mode");
var sFailModeId = oBCQuoteTemplate.GetFieldValue("CMI Fail Mode Id");//<Bug # DBUNG00000285><Configration> Added script to populate Mode Id instead of Mode<By>JQ487<On>8-Aug-2011
CreateFailureCode(sFailCdId, sSRID, sFailMode, sFailModeId);//<Bug # DBUNG00000285><Configration> Added script to populate Mode Id instead of Mode<By>JQ487<On>8-Aug-2011
}
}
if(sSRTCount > 0) {
TheApplication().RaiseError("CMI SRT Error Notification", sSRTCount);
}
//Nag; 3/6/2012; Fix for Refresh Issue after the Quote is created. CQ# 5277
TheApplication().ActiveBusObject().GetBusComp("Quote").InvokeMethod("RefreshBusComp");
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sSRTValidationService = null;
oBCQuoteLineItem = null;
oBCSR = null;
oBCQuoteTemplate = null;
oPckBC = null;
oBC = null;
oBO = null;
oBS = null;
psIO = null;
psOO = null;
psInput = null
psOutput = null
oSRBusObject = null;
oBCQuoteItem = null;
oBCQuote = null;
oBOQ = null;
TheApplication().Utility.logUnstack();
}
}

CMI SR Create Quote From Template BS
Service_PreCanInvokeMethod
function Service_PreCanInvokeMethod (MethodName, &CanInvoke)
{
try
{
if (MethodName == "CopyQuoteTemplate")
{
CanInvoke = "TRUE";
return (CancelOperation);
}
else if (MethodName == "SRT Validation")
{
CanInvoke = "TRUE";
return (CancelOperation);
}
}
catch(e)
{
throw(e);
}
return (ContinueOperation);
}

CMI SR Create Quote From Template BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if (MethodName == "CopyQuoteTemplate") {
CopyQuoteTemplate();
}/*MJB Inactivated as can find no reference to this call
else if (MethodName == "SRT Validation") {
var sSRTQuoteId = Inputs.GetProperty("Quote Id");
var sSRTProdLine = Inputs.GetProperty("SR Product Line");
var sSRTAccessCode = Inputs.GetProperty("SR Access Code");
CheckSRTValidity(sSRTQuoteId, sSRTProdLine, sSRTAccessCode);
Outputs.SetProperty("SRT Fail Count",sSRTCount);
}*/
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI SR Update Quote Order Service Location
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: JR419,CMI DBU, If service location is updated after the quote is created, the system should update Quote ShipTo site
DESCRIPTION: If service location is updated after the quote is created, the system should update Quote ShipTo site.
Valid for quotes that are in a status prior to Accepted status. Should be updating orders in pending status also.
DATE CREATED: 06-16-2011
UPDATES:
*********************************************************/
//try catch added as part of code cleanup activity by JW919 on 08/22/2011
try
{
if(MethodName == "UpdateServiceLocation")
{
UpdateServiceLocation2(Inputs, Outputs);
return CancelOperation;
}
return (ContinueOperation);
}
catch(e)
{
TheApplication().RaiseErrorText("Exception Raised in object: "+this.Name()+". Exception:"+e.toString());
}
}

CMI SR Update Quote Order Service Location
UpdateServiceLocation2
function UpdateServiceLocation2(Inputs, Outputs)
/*CMI DBU: create by JR419 on 06-16-2011.If service location is updated after the quote is created, the system should update Quote ShipTo site.
Valid for quotes that are in a status prior to Accepted status.Should be updating orders in pending status also.
updated to address CQ-8132, leaving orginial function in place a updating method to use this new one.
*/
{
try
{
var oActiveBO = TheApplication().ActiveBusObject();
if(oActiveBO.Name() != "Service Request")
{//1
return;
}//1
var oServiceRequest = oActiveBO.GetBusComp("Service Request");
var oQuoteBO = TheApplication().GetBusObject("Quote");
var oQuote = oQuoteBO.GetBusComp("Quote");
var oQuoteItem = oQuoteBO.GetBusComp("Quote Item");
var oOrderBO = TheApplication().GetBusObject("Order Entry");
var oOrder = oActiveBO.GetBusComp("Order Entry - Orders");
var oOrderItem = oActiveBO.GetBusComp("Order Entry - Line Items");
with(oServiceRequest)
{//2
// ActivateField("Id");
ActivateField("CMI Ship To Profile Id");
var sSRId = oServiceRequest.GetFieldValue("Id");
var sServiceLocation = oServiceRequest.GetFieldValue("CMI Ship To Profile Id");
}//2
//Quote records under the SR
with(oQuote)
{//5
ActivateField("Service Request Id");
//Valid for quotes that are in a status prior to Accepted status.
var sInProgress = TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","In Progress");
var sPriceAll = TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Price All");
//Only Quote(s) in valid status and latest revised order (Active Flag is Y) will be updated.
var searchst = "[Service Request Id] = '" + sSRId + "' AND [Active] = 'Y' AND ([Status] ='" + sInProgress + "' OR [Status] ='" + sPriceAll + "')";
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr(searchst);
ExecuteQuery(ForwardOnly);
var isQuoteRecord = FirstRecord();
while(isQuoteRecord)
{//4
// ActivateField("Id");
SetFieldValue("CMI Ship To Profile Id",sServiceLocation);
WriteRecord();
//Quote Item Records under the Quote
with(oQuoteItem)
{//3
ActivateField("Quote Id");
ActivateField("CMI Ship To Profile Id");
SetViewMode(AllView);
ClearToQuery();
ExecuteQuery(ForwardOnly);
var isQuoteItemRecord = FirstRecord();
var strCurrQuoteItemId = "";
var strPrevQuoteItemId = "";
while(isQuoteItemRecord)
{
strCurrQuoteItemId = GetFieldValue("Id");
if ( strCurrQuoteItemId != strPrevQuoteItemId)
{
SetFieldValue("CMI Ship To Profile Id",sServiceLocation);
WriteRecord();
}
strPrevQuoteItemId = strCurrQuoteItemId;
isQuoteItemRecord = NextRecord();
}
}//3
isQuoteRecord = NextRecord();
}//4
ClearToQuery(); //Added by JQ487 on 04/11/2011 for fixing CQ defect 2432
}//5
//Order records under the SR
with(oOrder)
{
ActivateField("Service Request Id");
//Should be updating orders in pending status also.
var sPending = TheApplication().InvokeMethod("LookupValue","FS_ORDER_STATUS","Pending");
//Only Order(s) in valid status and latest revised order (Active Flag is Y) will be updated.
var searchstr = "[Service Request Id] = '" + sSRId + "' AND [Active] = 'Y' AND [Status] = '" + sPending + "'";
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr(searchstr);
ExecuteQuery(ForwardOnly);
var isOrderRecord = FirstRecord();
while(isOrderRecord)
{
ActivateField("Id");
SetFieldValue("CMI Ship To Profile Id",sServiceLocation);
WriteRecord();
//Order Item Records under the Quote
with(oOrderItem)
{
ActivateField("Order Header Id");
ActivateField("CMI Ship To Profile Id");
SetViewMode(AllView);
ClearToQuery();
ExecuteQuery(ForwardOnly);
var isOrderItemRecord = FirstRecord();
while(isOrderItemRecord)
{
SetFieldValue("CMI Ship To Profile Id",sServiceLocation);
WriteRecord();
isOrderItemRecord = NextRecord();
}
}
isOrderRecord = NextRecord();
}
}
//}
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
finally
{
oOrderItem = null;
oOrder = null;
oQuoteItem = null;
oQuote = null;
oServiceRequest = null;
//added by shanmukh for code clean up 08/27/2011
oActiveBO = null;
}
}

CMI SR Update Quote Order Service Location
UpdateServiceLocation
function UpdateServiceLocation(Inputs, Outputs)
/*CMI DBU: create by JR419 on 06-16-2011.If service location is updated after the quote is created, the system should update Quote ShipTo site.
Valid for quotes that are in a status prior to Accepted status.Should be updating orders in pending status also.
*/
{
try
{
var oActiveBO = TheApplication().ActiveBusObject();
if(oActiveBO.Name() != "Service Request")
{
return;
}
var oServiceRequest = oActiveBO.GetBusComp("Service Request");
var oQuote = oActiveBO.GetBusComp("Quote");
var oQuoteItem = oActiveBO.GetBusComp("Quote Item");
var oOrder = oActiveBO.GetBusComp("Order Entry - Orders");
var oOrderItem = oActiveBO.GetBusComp("Order Entry - Line Items");
with(oServiceRequest)
{
ActivateField("Id");
ActivateField("CMI Ship To Profile Id");
var sSRId = oServiceRequest.GetFieldValue("Id");
var sServiceLocation = oServiceRequest.GetFieldValue("CMI Ship To Profile Id");
//Quote records under the SR
with(oQuote)
{
ActivateField("Service Request Id");
//Valid for quotes that are in a status prior to Accepted status.
var sInProgress = TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","In Progress");
var sPriceAll = TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Price All");
//Only Quote(s) in valid status and latest revised order (Active Flag is Y) will be updated.
var searchst = "[Service Request Id] = '" + sSRId + "' AND [Active] = 'Y' AND ([Status] ='" + sInProgress + "' OR [Status] ='" + sPriceAll + "')";
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr(searchst);
ExecuteQuery(ForwardOnly);
var isQuoteRecord = FirstRecord();
while(isQuoteRecord)
{
ActivateField("Id");
SetFieldValue("CMI Ship To Profile Id",sServiceLocation);
WriteRecord();
InvokeMethod("RefreshRecord"); //Added by lb966 for fixing CQ defect 8132
//Quote Item Records under the Quote
with(oQuoteItem)
{
ActivateField("Quote Id");
ActivateField("CMI Ship To Profile Id");
SetViewMode(AllView);
ClearToQuery();
ExecuteQuery(ForwardOnly);
var isQuoteItemRecord = FirstRecord();
while(isQuoteItemRecord)
{
SetFieldValue("CMI Ship To Profile Id",sServiceLocation);
WriteRecord();
//InvokeMethod("RefreshRecord"); //Added by lb966 for fixing CQ defect 8132
isQuoteItemRecord = NextRecord();
}
}
isQuoteRecord = NextRecord();
}
ClearToQuery(); //Added by JQ487 on 04/11/2011 for fixing CQ defect 2432
}
//Order records under the SR
with(oOrder)
{
ActivateField("Service Request Id");
//Should be updating orders in pending status also.
var sPending = TheApplication().InvokeMethod("LookupValue","FS_ORDER_STATUS","Pending");
//Only Order(s) in valid status and latest revised order (Active Flag is Y) will be updated.
var searchstr = "[Service Request Id] = '" + sSRId + "' AND [Active] = 'Y' AND [Status] = '" + sPending + "'";
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr(searchstr);
ExecuteQuery(ForwardOnly);
var isOrderRecord = FirstRecord();
while(isOrderRecord)
{
ActivateField("Id");
SetFieldValue("CMI Ship To Profile Id",sServiceLocation);
WriteRecord();
//InvokeMethod("RefreshRecord"); //Added by lb966 for fixing CQ defect 8132
//Order Item Records under the Quote
with(oOrderItem)
{
ActivateField("Order Header Id");
ActivateField("CMI Ship To Profile Id");
SetViewMode(AllView);
ClearToQuery();
ExecuteQuery(ForwardOnly);
var isOrderItemRecord = FirstRecord();
while(isOrderItemRecord)
{
SetFieldValue("CMI Ship To Profile Id",sServiceLocation);
WriteRecord();
//InvokeMethod("RefreshRecord"); //Added by lb966 for fixing CQ defect 8132
isOrderItemRecord = NextRecord();
}
}
isOrderRecord = NextRecord();
}
}
//oServiceRequest.InvokeMethod("RefreshRecord");
}
}
catch(e)
{
TheApplication().RaiseErrorText("An exception occurred in the " +this.Name() +"Error is: " + e.toString());
}
finally
{
oOrderItem = null;
oOrder = null;
oQuoteItem = null;
oQuote = null;
oServiceRequest = null;
//added by shanmukh for code clean up 08/27/2011
oActiveBO = null;
}
}

CMI SR Warranty Check
SRWarrantyValidation
/*Created By : Jw920
Created On : 24-Aug-2011
Method Name: SRWarrantyValidation
Defect Number: DBUNG00001037
Functionality: There will have a error message showing while total warranty amount in Labour, Parts, Misc is greater than 100%.
Input:
Output:
*/
function SRWarrantyValidation(inputs, outputs)
{
try
{
var oBO:BusObject = TheApplication().ActiveBusObject();
if(oBO.Name()!="Service Request")
{
return;
}
var oBCSRWarranty:BusComp = oBO.GetBusComp("CMI Service Request Warranty");
var sFieldName:String = TheApplication().GetProfileAttr("CMI Field Name");
var sWarSRId:String = oBCSRWarranty.GetFieldValue("CMI Parent SR Id");
var iWarSum:Number = 0;
var iDefPercent:Number = 0;
var hasRecord:bool = false;
with(oBCSRWarranty)
{
SetViewMode(AllView);
ActivateField(sFieldName);
ClearToQuery();
SetSearchSpec("CMI Parent SR Id",sWarSRId);
ExecuteQuery(ForwardOnly);
hasRecord = FirstRecord();
while(hasRecord)
{
iDefPercent = ToNumber(GetFieldValue(sFieldName));
iWarSum = iWarSum + iDefPercent;
hasRecord = NextRecord()
}
if(iWarSum > 100)
{
if(sFieldName == "CMI Default Labor Percentage")
{
TheApplication().RaiseError("CMI Default SR Warranty", "Labor");
}
else if(sFieldName == "CMI Default Part Percentage")
{
TheApplication().RaiseError("CMI Default SR Warranty", "Part");
}
else if(sFieldName == "CMI Default Misc Percentage")
{
TheApplication().RaiseError("CMI Default SR Warranty", "Misc");
}
else
{
return(ContinueOperation);
}
}
}
}// END OF TRY BLOCK
catch(e)
{
throw(e);
}
finally
{
oBO = null;
oBCSRWarranty = null;
}
return(ContinueOperation);
}// END OF FUNCTION

CMI SR Warranty Check
Service_PreInvokeMethod
/*Created By : Jw920
Created On : 24-Aug-2011
Method Name: SRWarrantyValidation
Defect Number: DBUNG00001037
Functionality: There will have a error message showing while total warranty amount in Labour, Parts, Misc is greater than 100%.
Input:
Output:
*/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if(MethodName == "SRWarrantyValidation")
{
SRWarrantyValidation(Inputs, Outputs);
return (CancelOperation);
}
}// End of try
catch(e)
{
throw(e);
}
return (ContinueOperation);
}

CMI SR Warranty Validation
Service_PreInvokeMethod
/*Created By : JR419
Created On : 29-Jul-2011
Method Name: ValidateSR Warranty
Defect Number: DBUNG00001037
Functionality: There will have a error message showing while total warranty amount in Labour, Parts, Misc is greater than 100%.
Input:
Output:
*/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if(MethodName == "ValidateSRWarranty")
{
ValidateSRWarranty(Inputs, Outputs);
return (CancelOperation);
}
return (ContinueOperation);
}

CMI SR Warranty Validation
ValidateSRWarranty
function ValidateSRWarranty(inputs, outputs)
{
try
{
var oBO = TheApplication().ActiveBusObject();
if(oBO.Name()!="Service Request")
{
return;
}
var oBCSR = oBO.GetBusComp("Service Request");
var oBCSRWarranty = oBO.GetBusComp("CMI Service Request Warranty");
var iSRId = oBCSR.GetFieldValue("Id");
var iSumLabour = 0;
var iSumMisc = 0;
var iSumParts = 0;
var iDefPartPercent = 0;
var iDefLaborPercent = 0;
var iDefMiscPercent = 0;
var hasRecord;
with(oBCSRWarranty)
{
SetViewMode(AllView);
ActivateField("CMI Default Part Percentage");
ActivateField("CMI Default Labor Percentage");
ActivateField("CMI Default Misc Percentage");
ClearToQuery();
SetSearchSpec("CMI Parent SR Id", iSRId);
ExecuteQuery(ForwardOnly);
hasRecord = FirstRecord();
while(hasRecord)
{
iDefPartPercent = GetFieldValue("CMI Default Part Percentage");
iDefLaborPercent = GetFieldValue("CMI Default Labor Percentage");
iDefMiscPercent = GetFieldValue("CMI Default Misc Percentage");
iSumLabour = ToNumber(iSumLabour) + ToNumber(iDefLaborPercent);
iSumMisc = ToNumber(iSumMisc) + ToNumber(iDefMiscPercent);
iSumParts = ToNumber(iSumParts) + ToNumber(iDefPartPercent);
hasRecord = NextRecord();
}
}
with(oBCSRWarranty)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Parent SR Id", iSRId);
ExecuteQuery(ForwardBackward);
}
if(ToNumber(iSumParts)>100)
{
TheApplication().RaiseErrorText("Total of Parts Warranty % should not greater than 100%");
}
if(ToNumber(iSumLabour)>100)
{
TheApplication().RaiseErrorText("Total of Labour Warranty % should not greater than 100%");
}
if(ToNumber(iSumMisc)>100)
{
TheApplication().RaiseErrorText("Total of Misc Warranty % should not greater than 100%");
}
}
catch(e)
{
throw(e);
}
finally
{
oBCSRWarranty = null;
oBCSR = null;
oBO = null;
}
}

CMI SRQT View Refresh BS
AddNoteRecord
function AddNoteRecord()
{
try
{
var oBO = TheApplication().ActiveBusObject();
var oBCFailCd = oBO.GetBusComp("CMI SR Failure Code");
//Pankaj k - commenting the next 4 lines as GetFieldValue function not working when this function is called in background.
//Hence explicitly setting ProfileAttr in RTE of WriteRecord of CMI SR Failure Code BC and using here.
//oBCFailCd.ActivateField("CMI Description");
//oBCFailCd.ActivateField("CMI Parent SR Id");
//var SRId = oBCFailCd.GetFieldValue("CMI Parent SR Id");
//var sFailCdDesc = oBCFailCd.GetFieldValue("CMI Description");
var sFailId = TheApplication().GetProfileAttr("CMIFailureCodeId");
with(oBCFailCd)
{
SetViewMode(AllView);
ActivateField("CMI Parent SR Id");
ActivateField("CMI Description");
ActivateField("CMI Failure Description");
ClearToQuery();
SetSearchSpec("Id", sFailId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
var SRId = GetFieldValue("CMI Parent SR Id");
// var sFailCdDesc = GetFieldValue("CMI Description");
var sFailCdDesc = GetFieldValue("CMI Failure Description"); //jq487- added new filed as per new Fail code design
}
}
var oBCSRNotes = oBO.GetBusComp("FIN Service Request Notes");
with(oBCSRNotes)
{
NewRecord(NewAfter);
// SetFieldValue("Note Type", TheApplication().LookupValue("FS_NOTE_TYPE","Cause"));
SetFieldValue("Note Type", TheApplication().InvokeMethod("LookupValue","FS_NOTE_TYPE","Cause"));
SetFieldValue("Note", sFailCdDesc);
SetFieldValue("Service Request Id", SRId);
WriteRecord();
}
}
catch(e)
{
// TheApplication().Trace("Error Message : " + e.toString() + e.errCode); //Commented by JW227 for Code Cleanup on 11/28/2011
// TheApplication().TraceOff();
throw(e);
}
finally
{
sFailId = null;
oBCSRNotes = null;
oBCFailCd = null;
oBO = null;
}
}

CMI SRQT View Refresh BS
RefreshBusComp
function RefreshBusComp(BusCompName)
{
//try catch added by shanmukh for code clean up 08/27/2011
try
{
//function RefreshBusComp(BusCompName)
var oBO = TheApplication().ActiveBusObject();
var oBCQuoteTemplate = oBO.GetBusComp(BusCompName);
with (oBCQuoteTemplate)
{
SetViewMode(AllView);
ClearToQuery();
ExecuteQuery(3);
}
}
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
{
oBCQuoteTemplate = null;
oBO = null;
}
}

CMI SRQT View Refresh BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: Anand Shanmugam - Oracle Corporation & Pankaj Kide
DESCRIPTION: The Business Service refreshes the SR Failure view and creates a note record when failure code is selected
OUTPUTS: None
DATE CREATED: 2/22/2010
UPDATES:
*********************************************************/
try
{
if (MethodName == "AddNoteRecord")
{
AddNoteRecord();
return (CancelOperation);
}
if (MethodName == "RefreshQuoteTemplate")
{
var BCName = Inputs.GetProperty("Context");
RefreshBusComp(BCName);
return (CancelOperation);
}
}
catch(e)
{
// TheApplication().Trace("Error Message : " + e.toString() + e.errCode); //Commented by JW227 for Code Cleanup on 11/28/2011
// TheApplication().TraceOff();
throw(e);
}
/* Finally Commented as part of Code Clean-up activity :: Finally block should not be empty and is not mandatory
if there are no objects to nullify. By JW919 on 08/22/2011
finally
{
}
*/
}

CMI SRT Load Service
(declarations)
//Header
var sSRTBO:BusObject;
var sIPBO:BusObject;
var sSRTBC:BusComp;
var sIPBC:BusComp;
var sMastBO:BusObject;
var sMastBC:BusComp;
//SRTDesc
var sSRTDescBC:BusComp;
//SRTStep
var sStepBC:BusComp;
//SRTStepDesc
var sStepDescBC:BusComp;
var sMastTransBC:BusComp;

CMI SRT Load Service
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retValue = CancelOperation;
if(MethodName == "SRTLoad")
{
fnLoadSRT(Inputs,Outputs);
}
}
catch(e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
TheApplication().Utility.logUnstack(retValue);
}
return (retValue);
}

CMI SRT Load Service
fnArchiveFile
function fnArchiveFile(sFilePath, sInpFileName)
{
try
{
TheApplication().Utility.logStack("fnArchiveFile", this);
var sArchFileName = fnGetArchFileName(sInpFileName);
var sOS;
var sCmd;
var sMoveCmd;
var sDoubleQuotes = "\"";
var sArchiveFolder;
try
{
sOS = Clib.getenv("OS");
sOS = sOS.substring(0, 7);
}
catch(e)
{
sOS = "Unix";
}
sCmd = TheApplication().InvokeMethod("LookupValue", "CMI_SRT_LOAD", sOS);
sArchiveFolder = (sOS == "Windows")? "Archive\\" : "Archive/";
var sCDCmd = "cd " + sFilePath;
Clib.system(sCDCmd);
var sRenameCmd = "ren " + sFilePath + sInpFileName + " " + sArchFileName;
Clib.system(sRenameCmd);
var sCopyCmd = "copy "+ sFilePath + sArchFileName + " " + sFilePath + sArchiveFolder;
Clib.system(sCopyCmd);
var sDeleteCmd = "delete " + sFilePath + sArchFileName;
Clib.system(sDeleteCmd);
}
catch(e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
TheApplication().Utility.logUnstack();
}
}

CMI SRT Load Service
fnGetArchFileName
function fnGetArchFileName(sInpFileName)
{
var sTimeBuf;
Clib.strftime(sTimeBuf,"%m%d%Y_%H%M%S",Clib.localtime(Clib.time()));
var sTempFileName = sInpFileName.substring(0,sInpFileName.length - 4);
sTempFileName += sTimeBuf + ".txt";
return(sTempFileName);
}

CMI SRT Load Service
fnInit
function fnInit()
{
try
{
TheApplication().Utility.logStack("fnInit");
//Header
sSRTBO = TheApplication().GetBusObject("CMI SRT");
sIPBO = TheApplication().GetBusObject("Admin Product Definition");
sSRTBC = sSRTBO.GetBusComp("CMI SRT");
sIPBC = sIPBO.GetBusComp("Admin Product Line");
sMastBO = TheApplication().GetBusObject("CMI Master Code");
sMastBC = sMastBO.GetBusComp("CMI Master Codes");
//sMastTransBC
sMastTransBC = sMastBO.GetBusComp("CMI Master Code Translation");
//SRTDesc
sSRTDescBC = sSRTBO.GetBusComp("CMI SRT Translation");
//SRTStep
sStepBC = sSRTBO.GetBusComp("CMI SRT Steps");
//SRTStepDesc
sStepDescBC = sSRTBO.GetBusComp("CMI SRT Steps Translation");
}
catch(e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
TheApplication().Utility.logUnstack();
}
}

CMI SRT Load Service
fnLoadSRT
function fnLoadSRT(Inputs,Outputs)
{
try
{
TheApplication().Utility.logStack("fnLoadSRT", this);
var sInpFileName;
//Instantiate
fnInit();
//0. SRTGroupCode
sInpFileName = "EBU_SRTGroupCode.txt";
fnSRTGroupCode(Inputs,Outputs,sInpFileName,"EBU");
sInpFileName = "PGBU_SRTGroupCode.txt";
fnSRTGroupCode(Inputs,Outputs,sInpFileName,"PGBU");
//1. SRTHeader
sInpFileName = "EBU_SRTHeader.txt";
fnSRTHeader(Inputs,Outputs,sInpFileName,"EBU");
sInpFileName = "PGBU_SRTHeader.txt";
fnSRTHeader(Inputs,Outputs,sInpFileName,"PGBU");
//2. SRTDescription
sInpFileName = "EBU_SRTDescription.txt";
fnSRTDescription(Inputs,Outputs,sInpFileName,"EBU");
sInpFileName = "PGBU_SRTDescription.txt";
fnSRTDescription(Inputs,Outputs,sInpFileName,"PGBU");
//3. SRTStep
sInpFileName = "EBU_SRTStep.txt";
fnSRTStep(Inputs,Outputs,sInpFileName,"EBU");
sInpFileName = "PGBU_SRTStep.txt";
fnSRTStep(Inputs,Outputs,sInpFileName,"PGBU");
//4. SRTStepDescription
sInpFileName = "EBU_SRTStepDescription.txt";
fnSRTStepDescription(Inputs,Outputs,sInpFileName,"EBU");
sInpFileName = "PGBU_SRTStepDescription.txt";
fnSRTStepDescription(Inputs,Outputs,sInpFileName,"PGBU");
//5. SRTAccessCode
sInpFileName = "EBU_SRTAccessCode.txt";
fnSRTAccessCode(Inputs,Outputs,sInpFileName,"EBU");
sInpFileName = "PGBU_SRTAccessCode.txt";
fnSRTAccessCode(Inputs,Outputs,sInpFileName,"PGBU");
Outputs.SetProperty("CMINewLine", "\r\n");
TheApplication().Utility.logPS(Outputs);
}
catch(e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
//Cleanup of all BC/BOs.
//Header
sSRTBC = null;
sIPBC = null;
sMastBC = null;
//SRTDesc
sSRTDescBC = null;
//SRTStep
sStepBC = null;
//SRTStepDesc
sStepDescBC = null;
sMastBO = null;
sIPBO = null;
sSRTBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI SRT Load Service
fnSRTAccessCode
function fnSRTAccessCode(Inputs,Outputs,sInpFileName,sBU)
{
try
{
TheApplication().Utility.logStack("fnSRTAccessCode", this);
var sFilePath;
var sFileName;
var sErrMsg;
var UpdCtr = 0;
var nErrCount = 0;
var sErrCountMsg;
var bNewRec = false;
sFilePath = Inputs.GetProperty("FilePath");
sFileName = sFilePath + sInpFileName;
TheApplication().Utility.logStep("sFileName: " + sFileName);
sStepBC.ActivateField("Header Id");
sStepBC.ActivateField("Step Num");
var rowArray;
var Ctr = 0;
var fp = Clib.fopen(sFileName,"r");
TheApplication().Utility.logStep("File pointer: "+ fp);
var fpRow = Clib.fgets (fp);
TheApplication().Utility.logStep("fpRow: "+ fpRow);
if ( fp != null )
{
while (fpRow!=null)
{
bNewRec = false;
rowArray = fpRow.split("|");
if ( sSRTBC != null )
{
try
{
var sSPF = rowArray[0];
var sSGC = sBU + rowArray[0]+rowArray[1]+"GC"
var sSPC = rowArray[2];
sIPBC.ClearToQuery();
sIPBC.SetSearchSpec("Name",sSPF);
sIPBC.ExecuteQuery(ForwardOnly);
var sSPFCount = sIPBC.CountRecords();
if(sIPBC.FirstRecord())
var PF = sIPBC.GetFieldValue("Id");
sMastBC.ClearToQuery();
sMastBC.SetSearchSpec("CMI Master Code Type",sSGC);
sMastBC.ExecuteQuery(ForwardOnly);
var sSGCCount = sMastBC.CountRecords();
if(sMastBC.FirstRecord())
var GC = sMastBC.GetFieldValue("Id");
if(sSPFCount == 1 && sSGCCount == 1)
{
sSRTBC.ClearToQuery();
sSRTBC.SetSearchSpec("CMI Prod Family Id",PF);
sSRTBC.SetSearchSpec("CMI Group Id",GC);
sSRTBC.SetSearchSpec("CMI Procedure Id",sSPC);
sSRTBC.ExecuteQuery(ForwardOnly);
var sSRTCT = sSRTBC.CountRecords();
if (sSRTBC.FirstRecord())
var sSRId = sSRTBC.GetFieldValue("Id");
if (sSRTCT == 1)
{
sStepBC.ClearToQuery();
sStepBC.SetSearchSpec ("Header Id",sSRId);
sStepBC.SetSearchSpec ("Step Num", rowArray[3]);
sStepBC.ExecuteQuery(ForwardOnly);
var sSTPCT = sStepBC.CountRecords();
if (sSTPCT == 1)
{
if (rowArray[4] == 'A')
{
var sTransAc='A-Easy Access';
}
else if (rowArray[4] == 'B')
{
sTransAc='B-Moderate Access';
}
else if (rowArray[4] == 'C')
{
sTransAc='C-Slight Difficulty';
}
else if (rowArray[4] == 'D')
{
sTransAc='D-Difficult Access';
}
else if (rowArray[4] == 'R')
{
sTransAc='R-Conditonal Access';
}
else if (rowArray[4] == 'S1')
{
sTransAc='S1-Special';
}
else if (rowArray[4] == 'S2')
{
sTransAc='S2-Special';
}
else if (rowArray[4] == 'S3')
{
sTransAc='S3-Special';
}
else if (rowArray[4] == 'S4')
{
sTransAc='S4-Special';
}
else if (rowArray[4] == 'S5')
{
sTransAc='S5-Special';
}
else if (rowArray[4] == 'S6')
{
sTransAc='S6-Special';
}
else if (rowArray[4] == 'S7')
{
sTransAc='S7-Special';
}
else if (rowArray[4] == 'S8')
{
sTransAc='S8-Special';
}
else if (rowArray[4] == 'S9')
{
sTransAc='S9-Special';
}
if (sStepBC.FirstRecord())
{
var sStepId = sStepBC.GetFieldValue("Id");
var sMVGBC = sStepBC.GetMVGBusComp("CMI SRT Step Access Code");
sMVGBC.ActivateField("SRT Hours");
sMVGBC.ClearToQuery();
sMVGBC.SetSearchSpec("Access Code", sTransAc);
sMVGBC.ExecuteQuery(ForwardOnly);
var sAccessct = sMVGBC.CountRecords();
if(sAccessct == 0)
{
var sMVGBC1 = sStepBC.GetMVGBusComp("CMI SRT Step Access Code");
sMVGBC1.ClearToQuery();
sMVGBC1.ExecuteQuery(ForwardOnly);
sMVGBC1.NewRecord(NewAfter);
bNewRec = true;
var AccodeBC = sMVGBC1.GetPicklistBusComp("Access Code");
with(AccodeBC)
{
ClearToQuery();
// ActivateField("CMI Master Code Type");
ActivateField("CMI Master Code");
ActivateField("CMI Type");
SetSearchSpec("CMI Master Code" , sTransAc);
SetSearchSpec("CMI Type" , 'Access Code');
ExecuteQuery(ForwardOnly);
if (FirstRecord())
Pick();
var Proceed = "Y";
}//end of with(AccodeBC)
if(Proceed == "Y")
{
//sMVGBC1.ActivateField("Desription");
sMVGBC1.SetFieldValue("SRT Hours", rowArray[5]);
sMVGBC1.SetFieldValue("Desription", rowArray[6]);
sMVGBC1.WriteRecord();
Ctr = Ctr + 1;
TheApplication().Utility.logStep("Created Access Code: " + rowArray[0]+ "|" + rowArray[1]+ "|" + rowArray[2] + "|" + rowArray[3] + "|" + rowArray[4] + "|" + rowArray[5]+ "|" + rowArray[6]);
}//End of Proceed
else
{
TheApplication().Utility.logStep("Access Code does not exist: " + rowArray[0]+ "|" + rowArray[1]+ "|" + rowArray[2] + "|" + rowArray[3] + "|" + rowArray[4] + "|" + rowArray[5] + "|" + rowArray[6]);
}//end of else
} // End of if(sAccessct == 0)
else
{
if(sAccessct == 1)
{
sMVGBC.ActivateField("SRT Hours");
var sIncHrs = sMVGBC.GetFormattedFieldValue("SRT Hours");
if (sIncHrs==rowArray[5])
{
TheApplication().Utility.logStep("Access Code already exists: " + rowArray[0]+"|"+rowArray[1]+"|"+rowArray[2] + "|"+rowArray [3]+"|"+rowArray[4]+"|"+rowArray[5]);
}
else
{
if(rowArray[5]!="")
{
sMVGBC.ActivateField("SRT Hours");
sMVGBC.SetFieldValue("SRT Hours",rowArray[5]);
sMVGBC.WriteRecord();
UpdCtr = UpdCtr + 1;
TheApplication().Utility.logStep("Updated Access Hours for: " + rowArray[0]+"|"+rowArray[1]+"|"+rowArray[2] + "|"+rowArray[3]+"|"+rowArray[4]+"|"+rowArray[5] + " from " + sIncHrs );
}
else
{
TheApplication().Utility.logStep("Cannot update null hours: " + rowArray[0]+"|"+rowArray[1]+"|"+rowArray[2] + "|"+rowArray[3]+"|"+rowArray[4]+"|"+rowArray[5]);
}
}
}
}
}//End of if (sStepBC.FirstRecord())
} // End of if (sSTPCT == 1)
else
{
TheApplication().Utility.logStep("Step Not Found: " + rowArray[0]+ "|" + rowArray[1]+ "|" + rowArray[2] + "|" + rowArray[3] + "|" + rowArray[4] + "|" + rowArray[5] + "|" + rowArray[6]);
}
} // End of if (sSRTCT == 1)
else
{
TheApplication().Utility.logStep("SRT Header Not Available: " + rowArray[0]+ "|" + rowArray[1]+ "|" + rowArray[2] + "|" + rowArray[3] + "|" + rowArray[4] + "|" + rowArray[5] + "|" + rowArray[6]);
}
} //End of if(sSPFCount == 1 && sSGCCount == 1 && sSPCCount ==1)
}//End of try
catch(e)
{
if(bNewRec)
{
sMVGBC1.UndoRecord();
bNewRec = false;
}
nErrCount = nErrCount + 1;
TheApplication().Utility.logStep("Error is: " +e.errText+" SRTAccessCode: "+ rowArray[0]+"|"+rowArray[1]+"|"+rowArray[2] + "|"+rowArray[3]+"|"+rowArray[4]+"|"+rowArray[5]);
}
}// end of if
fpRow = Clib.fgets (fp);
}//end of while
}//end of if ( fp != null )
else
{
sErrMsg = "File: " + sFileName + " not found";
TheApplication().Utility.logStep("File Exists? " + sErrMsg);
}
var sMsg = sBU+"_SRTAccessCode";
sErrCountMsg = sMsg + "Errors";
TheApplication().Utility.logStep(sMsg+"Created: " + Ctr);
TheApplication().Utility.logStep(sMsg+"Updated: " + UpdCtr);
TheApplication().Utility.logStep(sErrCountMsg+": "+ nErrCount);
}
catch(e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
fp = null;
Outputs.SetProperty(sMsg+"Created", Ctr);
Outputs.SetProperty(sMsg+"Updated", UpdCtr);
Outputs.SetProperty(sErrCountMsg, nErrCount);
TheApplication().Utility.logUnstack();
}
}

CMI SRT Load Service
fnSRTDescription
function fnSRTDescription(Inputs,Outputs,sInpFileName,sBU)
{
try
{
TheApplication().Utility.logStack("fnSRTDescription", this);
var sFilePath;
var sFileName;
var sErrMsg;
var nErrCount = 0;
var sErrCountMsg;
var bNewRec = false;
sFilePath = Inputs.GetProperty("FilePath");
sFileName = sFilePath + sInpFileName;
TheApplication().Utility.logStep("sFileName: " + sFileName);
sSRTDescBC.ActivateField("Parent Id");
sSRTDescBC.ActivateField("Description");
sSRTDescBC.ActivateField("Language Code");
var rowArray;
var Ctr = 0;
var UpdCtr =0;
var fp = Clib.fopen(sFileName,"r");
TheApplication().Utility.logStep("File Pointer: " + fp);
var fpRow = Clib.fgets (fp);
TheApplication().Utility.logStep("File Row Pointer: " + fpRow);
if ( fp != null )
{
while (fpRow!=null)
{
bNewRec = false;
rowArray = fpRow.split("|");
if ( sSRTBC != null )
{
try
{
var sSPF = rowArray[0];
var sSGC =sBU + rowArray[0]+rowArray[1]+"GC"
var sSPC = rowArray[2];
sIPBC.ClearToQuery();
sIPBC.SetSearchSpec("Name",sSPF);
sIPBC.ExecuteQuery(ForwardOnly);
var sSPFCount = sIPBC.CountRecords();
if(sIPBC.FirstRecord())
var PF = sIPBC.GetFieldValue("Id");
sMastBC.ClearToQuery();
sMastBC.SetSearchSpec("CMI Master Code Type",sSGC);
sMastBC.ExecuteQuery(ForwardOnly);
if(sMastBC.FirstRecord())
var GC = sMastBC.GetFieldValue("Id");
sSRTBC.ClearToQuery();
sSRTBC.SetSearchSpec("CMI Prod Family Id",PF);
sSRTBC.SetSearchSpec("CMI Group Id",GC);
sSRTBC.SetSearchSpec("CMI Procedure Id",sSPC);
sSRTBC.ExecuteQuery(ForwardOnly);
if (sSRTBC.FirstRecord())
{
var sSRId = sSRTBC.GetFieldValue("Id");
sSRTDescBC.SetSearchSpec("Language Code",'ENU');
sSRTDescBC.ExecuteQuery(ForwardOnly);
if (sSRTDescBC.CountRecords()==0)
{
sSRTDescBC.InvokeMethod("SetAdminMode", "TRUE");
sSRTDescBC.NewRecord(NewAfter);
bNewRec = true;
sSRTDescBC.SetFieldValue("Parent Id", sSRId);
sSRTDescBC.SetFieldValue("Description", rowArray[3]);
sSRTDescBC.SetFieldValue("Language Code","ENU");
sSRTDescBC.WriteRecord();
Ctr = Ctr + 1;
sErrMsg = rowArray[0]+ "|" + rowArray[1]+ "|" + rowArray[2]+ "|" + rowArray[3];
TheApplication().Utility.logStep("Created SRT Desc--"+ sErrMsg);
}//end of if (sSRTDescBC.CountRecords()==0)
else if ((sSRTDescBC.CountRecords()==1) && (rowArray[3]!=""))
{
var sInpDesc = rowArray[3];
var sSRTDesc = sSRTDescBC.GetFieldValue("Description");
if((Clib.stricmp(sInpDesc, sSRTDesc) != 0) && (sInpDesc.length != sSRTDesc.length))
{
sSRTDescBC.SetFieldValue("Description", rowArray[3]);
sSRTDescBC.WriteRecord();
UpdCtr = UpdCtr + 1;
sErrMsg = rowArray[0]+ "|" + rowArray[1]+ "|" + rowArray[2]+ "|" + rowArray[3];
TheApplication().Utility.logStep("sInpDesc--"+ sInpDesc+" sInpDescLength--"+sInpDesc.length);
TheApplication().Utility.logStep("sSRTDesc--"+ sSRTDesc+" sSRTDescLength--"+sSRTDesc.length);
TheApplication().Utility.logStep("Updated SRT Desc--"+ sErrMsg);
}
}//END OF else if ((sSRTDescBC.CountRecords()==1) && (rowArray[3]!=""))
}//end of if (sSRTBC.FirstRecord())
else
{
sErrMsg = rowArray[0]+ "|" + rowArray[1]+ "|" + rowArray[2]+ "|" + rowArray[3];
TheApplication().Utility.logStep("SRT Header does not exist--"+ sErrMsg);
}// end of else of if (sSRTBC.FirstRecord())
}//End of inner - try
catch(e)
{
if(bNewRec)
{
sSRTDescBC.UndoRecord();
bNewRec = false;
}
nErrCount = nErrCount + 1;
sErrMsg = rowArray[0]+ "|" + rowArray[1]+ "|" + rowArray[2]+ "|" + rowArray[3] + "--" + e.errText;
TheApplication().Utility.logStep("Error is: "+ sErrMsg);
}
}
fpRow = Clib.fgets (fp);
}//fpRow!=null
}//fp!=null
else
{
sErrMsg = "File: " + sFileName + " not found";
TheApplication().Utility.logStep("File Exists? " + sErrMsg);
}
var sMsg = sBU+"_SRTDesc";
sErrCountMsg = sMsg + "Errors";
TheApplication().Utility.logStep(sMsg + "Created: "+ Ctr);
TheApplication().Utility.logStep(sMsg + "Updated: "+ UpdCtr);
TheApplication().Utility.logStep(sErrCountMsg+": "+ nErrCount);
}//End of try
catch(e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
fp = null;
Outputs.SetProperty(sMsg+"Created", Ctr);
Outputs.SetProperty(sMsg+"Updated", UpdCtr);
Outputs.SetProperty(sErrCountMsg, nErrCount);
TheApplication().Utility.logUnstack();
}
}

CMI SRT Load Service
fnSRTGroupCode
function fnSRTGroupCode(Inputs,Outputs,sInpFileName,sBU)
{
try
{
TheApplication().Utility.logStack("fnSRTGroupCode", this);
var sFilePath;
var sFileName;
var sErrMsg;
var rowArray;
var ctr= 0 ;
var sVendor;
var bNewRec = false;
var nErrCount = -1;
var sErrCountMsg;
sFilePath = Inputs.GetProperty("FilePath");
sFileName = sFilePath + sInpFileName;
TheApplication().Utility.logStep("sFileName: "+ sFileName);
with(sMastBC)
{
ActivateField("CMI Master Code");
ActivateField("CMI Master Code Type");
ActivateField("CMI Engine Family Code");
ActivateField("CMI Type");
ActivateField("CMI Vendor");
}
var fp = Clib.fopen(sFileName,"r");
TheApplication().Utility.logStep("File Pointer: " + fp);
var fpRow = Clib.fgets (fp);
if (fp != null )
{
while (fpRow!=null)
{
bNewRec = false;
TheApplication().Utility.logStep("fpRow: " + fpRow);
rowArray = fpRow.split("|");
if ( sMastBC != null )
{
try
{
var sSPF = rowArray[0];
var sSGC =sBU + rowArray[0]+rowArray[1]+"GC";
TheApplication().Utility.logStep("sSGC: "+sSGC);
sIPBC.ClearToQuery();
sIPBC.SetSearchSpec("Name",sSPF);
sIPBC.ExecuteQuery(ForwardOnly);
//var sSPFCount = sIPBC.CountRecords();
if(sIPBC.FirstRecord())
var sPF = sIPBC.GetFieldValue("Id");
if(sPF != "")
{
TheApplication().Utility.logStep("sPF: " + sPF);
with(sMastBC)
{
InvokeMethod("SetAdminMode", "TRUE");
ClearToQuery();
SetSearchSpec("CMI Master Code Type",sSGC);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sErrMsg = rowArray[0] + rowArray[1] + rowArray[2] + rowArray[3];
TheApplication().Utility.logStep("GroupCodeExists: " + sErrMsg);
}
else
{
//Create New Master code
NewRecord(NewAfter);
bNewRec = true;
SetFieldValue("CMI Engine Family Code",sSPF);
SetFieldValue("CMI Master Code",rowArray[1]);
SetFieldValue("CMI Type",rowArray[3]);
if(sBU == "EBU")
sVendor = "Engine";
else
sVendor = "Power Generation";
SetFieldValue("CMI Vendor",sVendor);
SetFieldValue("CMI Master Code Type",sSGC);
WriteRecord();
var sMastCodeId = GetFieldValue("Id");
TheApplication().Utility.logStep("GroupCode Inserted Id: " + sMastCodeId +"|"+rowArray[0] + "|" + rowArray[1] +"|"+ rowArray[2] +"|"+ rowArray[3]);
//var sLangId = TheApplication().
with(sMastTransBC)
{
NewRecord(NewAfter);
SetFieldValue("Name", "ENU");
SetFieldValue("Par Row Id", sMastCodeId);
SetFieldValue("CMI Description", rowArray[2]);
SetFieldValue("CMI Language Id", "ENU");
SetFieldValue("Type", "GroupCode");
WriteRecord();
TheApplication().Utility.logStep("MastCodeTransId: " + GetFieldValue("Id") +"|"+rowArray[0] + "|" + rowArray[1] +"|"+ rowArray[2] +"|"+ rowArray[3]);
}
ctr = ctr + 1;
}
}//end of with(sMastBC)
}
else
{
TheApplication().Utility.logStep("Product Line: " + sPF + "does not exist. Please create it manually and reprocess.");
}
}// End of try
catch(e)
{
if(bNewRec)
{
sMastBC.UndoRecord();
bNewRec = false;
}
nErrCount = nErrCount + 1;
sErrMsg = "Error is: " + rowArray[0] + "|" + rowArray[1] + "|" + rowArray[2] + "|" + rowArray[3]+"--"+e.errText;
TheApplication().Utility.logStep(sErrMsg);
}//End of Catch
}// if ( sMastBC != null )
fpRow = Clib.fgets (fp);
}//while (fpRow!=null)
}//if ( fp != null )
else
{
sErrMsg = "File: " + sFileName + " not found";
TheApplication().Utility.logStep("File Exists? " + sErrMsg);
}
var sMsg = sBU+"_SRTGroupCode";
sErrCountMsg = sMsg + "Errors";
nErrCount = (nErrCount == -1)? 0 : nErrCount;
TheApplication().Utility.logStep(sMsg + ": "+ ctr);
TheApplication().Utility.logStep(sErrCountMsg + ": "+ nErrCount);
}//End of Main try
catch(e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
sSPF = null;
sSGC = null;
fpRow = null;
fp = null;
Outputs.SetProperty(sMsg, ctr);
Outputs.SetProperty(sErrCountMsg, nErrCount);
TheApplication().Utility.logUnstack();
}
}

CMI SRT Load Service
fnSRTHeader
function fnSRTHeader(Inputs,Outputs,sInpFileName,sBU)
{
try
{
TheApplication().Utility.logStack("fnSRTHeader", this);
var sFilePath;
var sFileName;
var sErrMsg;
var rowArray;
var ctr= 0 ;
var nErrCount = 0;
var sErrCountMsg;
var bNewRec = false;
sFilePath = Inputs.GetProperty("FilePath");
sFileName = sFilePath + sInpFileName;
TheApplication().Utility.logStep("sFileName: "+ sFileName);
with(sSRTBC)
{
ActivateField("CMI Prod Family");
ActivateField("CMI Group");
ActivateField("CMI Procedure Id");
ActivateField("Troubleshoot SRT Flag");
}
var fp = Clib.fopen(sFileName,"r");
TheApplication().Utility.logStep("File Pointer: " + fp);
var fpRow = Clib.fgets (fp);
TheApplication().Utility.logStep("fpRow: " + fpRow);
if (fp != null )
{
while (fpRow!=null)
{
bNewRec = false;
rowArray = fpRow.split("|");
if ( sSRTBC != null )
{
try
{
var sSPF = rowArray[0];
var sSGC =sBU + rowArray[0]+rowArray[1]+"GC" //var sSPC ="EBU"+ rowArray[0]+rowArray[1]+rowArray[2]+"PC"
sIPBC.ClearToQuery();
sIPBC.SetSearchSpec("Name",sSPF);
sIPBC.ExecuteQuery(ForwardOnly);
var sSPFCount = sIPBC.CountRecords();
if(sIPBC.FirstRecord())
var PF = sIPBC.GetFieldValue("Id");
sMastBC.ClearToQuery();
sMastBC.SetSearchSpec("CMI Master Code Type",sSGC);
sMastBC.ExecuteQuery(ForwardOnly);
var sSGCCount = sMastBC.CountRecords();
if(sMastBC.FirstRecord())
var GC = sMastBC.GetFieldValue("Id");
TheApplication().Utility.logStep("sSPFCount: " + sSPFCount + " sSGCCount: " + sSGCCount);
if(sSPFCount == 1 && sSGCCount == 1)
{
sSRTBC.InvokeMethod("SetAdminMode", "TRUE");
sSRTBC.ClearToQuery();
sSRTBC.SetSearchSpec("CMI Prod Family Id",PF);
sSRTBC.SetSearchSpec("CMI Group Id",GC);
//sSRTBC.SetSearchSpec("CMI Procedure Id",PC);
sSRTBC.SetSearchSpec("CMI Procedure Id",rowArray[2]); sSRTBC.SetSearchSpec("CMI Procedure Id",rowArray[2])
sSRTBC.ExecuteQuery(ForwardOnly);
if(sSRTBC.FirstRecord())
{
sErrMsg = rowArray[0] + rowArray[1] + rowArray[2] + rowArray[3];
TheApplication().Utility.logStep("SRTExists: " + sErrMsg);
}
else
{
sSRTBC.NewRecord(NewAfter);
bNewRec = true;
var ProdFmlyBC = sSRTBC.GetPicklistBusComp("CMI Prod Family");
with(ProdFmlyBC)
{
ClearToQuery();
sSPF = rowArray[0];
SetSearchSpec("Name" , sSPF);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
Pick();
}
TheApplication().Utility.logStep("ProdFamily Picked.");
var GroupcodeBC = sSRTBC.GetPicklistBusComp("CMI Group");
with(GroupcodeBC)
{
ClearToQuery();
ActivateField("CMI Master Code Type");
sSGC =sBU + rowArray[0]+rowArray[1]+"GC"
SetSearchSpec("CMI Master Code Type" , sSGC);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
Pick();
sSRTBC.SetFieldValue("CMI Procedure Id", rowArray[2]);
sSRTBC.SetFieldValue("Troubleshoot SRT Flag", rowArray[3]);
var sVendor;
if(sBU == "EBU")
sVendor = "Engine";
else
sVendor = "Power Generation";
sSRTBC.SetFieldValue("Vendor",sVendor);
sSRTBC.SetFieldValue("Global Flag",'Y');
sSRTBC.SetFieldValue("Active Flag",'Y');
sSRTBC.WriteRecord();
TheApplication().Utility.logStep("SRT Inserted Id: " + sSRTBC.GetFieldValue("Id"));
ctr = ctr + 1;
}
}
}
}// End of try
catch(e)
{
if(bNewRec)
{
sSRTBC.UndoRecord();
bNewRec = false;
}
nErrCount = nErrCount + 1;
sErrMsg = "Error is: " + rowArray[0] + "|" + rowArray[1] + "|" + rowArray[2] + "|" + rowArray[3]+"--"+e.errText;
TheApplication().Utility.logStep(sErrMsg);
}//End of Catch
}// if ( sSRTBC != null )
fpRow = Clib.fgets (fp);
}//while (fpRow!=null)
//Archives the File
//fnArchiveFile(sFilePath, sInpFileName);
}//if ( fp != null )
else
{
sErrMsg = "File: " + sFileName + " not found";
TheApplication().Utility.logStep("File Exists? " + sErrMsg);
}
var sMsg = sBU+"_SRTHeader";
sErrCountMsg = sMsg + "Errors";
TheApplication().Utility.logStep(sMsg + ": "+ ctr);
TheApplication().Utility.logStep(sErrCountMsg + ": "+ nErrCount);
}//End of Main try
catch(e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
PF = null;
GC = null;
// PC = null;
sSPF = null;
//sSPC = null;
sSGC = null;
fp = null;
ProdFmlyBC = null;
GroupcodeBC = null;
Outputs.SetProperty(sMsg, ctr);
Outputs.SetProperty(sErrCountMsg, nErrCount);
TheApplication().Utility.logUnstack();
}
}

CMI SRT Load Service
fnSRTStepDescription
function fnSRTStepDescription(Inputs,Outputs,sInpFileName,sBU)
{
try
{
TheApplication().Utility.logStack("fnSRTStepDescription", this);
var sFilePath;
var sFileName;
var sErrMsg;
var nErrCount = 0;
var sErrCountMsg;
var bNewRec = false;
sFilePath = Inputs.GetProperty("FilePath");
sFileName = sFilePath + sInpFileName;
TheApplication().Utility.logStep("sFileName: " + sFileName);
sStepBC.ActivateField("Header Id");
sStepBC.ActivateField("Step Num");
sStepDescBC.ActivateField("Parent Id");
sStepDescBC.ActivateField("Description");
sStepDescBC.ActivateField("Language Code");
var rowArray;
var Ctr = 0;
var UpdCtr = 0;
var fp = Clib.fopen(sFileName,"r");
TheApplication().Utility.logStep("File pointer: "+ fp);
var fpRow = Clib.fgets (fp);
TheApplication().Utility.logStep("FileRow pointer: "+ fpRow);
if ( fp != null )
{
while (fpRow!=null)
{
bNewRec = false;
rowArray = fpRow.split("|");
if ( sSRTBC != null )
{
try
{
//var sSPF ="EBU"+ rowArray[0]+"EF"
var sSPF =rowArray[0];
var sSGC =sBU + rowArray[0]+rowArray[1]+"GC"
var sSPC = rowArray[2];
sIPBC.ClearToQuery();
sIPBC.SetSearchSpec("Name",sSPF);
sIPBC.ExecuteQuery(ForwardOnly);
var sSPFCount = sIPBC.CountRecords();
if(sIPBC.FirstRecord())
var PF = sIPBC.GetFieldValue("Id");
sMastBC.ClearToQuery();
sMastBC.SetSearchSpec("CMI Master Code Type",sSGC);
sMastBC.ExecuteQuery(ForwardOnly);
if(sMastBC.FirstRecord())
var GC = sMastBC.GetFieldValue("Id");
sSRTBC.ClearToQuery();
sSRTBC.SetSearchSpec("CMI Prod Family Id",PF);
sSRTBC.SetSearchSpec("CMI Group Id",GC);
sSRTBC.SetSearchSpec("CMI Procedure Id",sSPC);
sSRTBC.ExecuteQuery(ForwardOnly);
if (sSRTBC.FirstRecord())
{
var sSRId = sSRTBC.GetFieldValue("Id");
sStepBC.ClearToQuery();
sStepBC.SetSearchSpec("Header Id",sSRId);
sStepBC.SetSearchSpec("Step Num", rowArray[3]);
sStepBC.ExecuteQuery(ForwardOnly);
if(sStepBC.FirstRecord())
{
var sStepId = sStepBC.GetFieldValue("Id");
sStepDescBC.SetSearchSpec("Language Code",'ENU');
sStepDescBC.ExecuteQuery(ForwardOnly);
if (sStepDescBC.CountRecords()==0)
{
sStepDescBC.InvokeMethod("SetAdminMode", "TRUE");
sStepDescBC.NewRecord(NewAfter);
bNewRec = true;
sStepDescBC.SetFieldValue("Parent Id", sStepId);
sStepDescBC.SetFieldValue("Description", rowArray[4]);
sStepDescBC.SetFieldValue("Language Code","ENU");
sStepDescBC.WriteRecord();
Ctr = Ctr + 1;
TheApplication().Utility.logStep("Created Step Desc - " + rowArray[0]+ "|" + rowArray[1]+ "|" + rowArray[2]+ "|" + rowArray[3] + "|" + rowArray[4]);
}//end of if (sStepDescBC.CountRecords()==0)
else if ((sStepDescBC.CountRecords()==1) && (rowArray[4]!="") && (rowArray[4] != sStepDescBC.GetFieldValue("Description")))
{
sStepDescBC.SetFieldValue("Description", rowArray[4]);
sStepDescBC.WriteRecord();
UpdCtr = UpdCtr + 1;
TheApplication().Utility.logStep("Updated Step Desc--" + rowArray[0]+ "|" + rowArray[1]+ "|" + rowArray[2]+ "|" + rowArray[3] + "|" + rowArray[4]);
}//end of else if (sStepDescBC.CountRecords()==1)
}//end of if(sStepBC.FirstRecord())
else
{
TheApplication().Utility.logStep("SRT Step does not exist for - " + rowArray[0]+ "|" + rowArray[1]+ "|" + rowArray[2]+ "|" + rowArray[3] + "|" + rowArray[4]);
}
}//end of if (sSRTBC.FirstRecord())
else
{
TheApplication().Utility.logStep("SRT Header does not exist for - " + rowArray[0]+ "|" + rowArray[1]+ "|" + rowArray[2]+ "|" + rowArray[3] + "|" + rowArray[4]);
}// end of else of if (sSRTBC.FirstRecord())
}//End of try
catch(e)
{
if(bNewRec)
{
sStepDescBC.UndoRecord();
bNewRec = false;
}
nErrCount = nErrCount + 1;
TheApplication().Utility.logStep("Error is: " +e);
}
}
fpRow = Clib.fgets (fp);
}
}
else
{
sErrMsg = "File: " + sFileName + " not found";
TheApplication().Utility.logStep("File Exists? " + sErrMsg);
}
var sMsg = sBU + "_SRTStepDesc";
sErrCountMsg = sMsg + "Errors";
nErrCount = (nErrCount == -1)? 0 : nErrCount;
TheApplication().Utility.logStep(sMsg+"Created: " + Ctr);
TheApplication().Utility.logStep(sMsg+"Updated: "+ UpdCtr);
TheApplication().Utility.logStep(sErrCountMsg+": "+ nErrCount);
}
catch(e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
fp = null;
Outputs.SetProperty(sMsg+"Created", Ctr);
Outputs.SetProperty(sMsg+"Updated", UpdCtr);
Outputs.SetProperty(sErrCountMsg, nErrCount);
TheApplication().Utility.logUnstack();
}
}

CMI SRT Load Service
fnSRTStep
function fnSRTStep(Inputs,Outputs,sInpFileName,sBU)
{
try
{
TheApplication().Utility.logStack("fnSRTStep", this);
var sFilePath;
var sFileName;
var sErrMsg;
var nErrCount = 0;
var sErrCountMsg;
var bNewRec = false;
sFilePath = Inputs.GetProperty("FilePath");
sFileName = sFilePath + sInpFileName;
TheApplication().Utility.logStep("sFileName: " + sFileName);
sStepBC.ActivateField("Header Id");
sStepBC.ActivateField("Step Num");
var rowArray;
var Ctr = 0;
var fp = Clib.fopen(sFileName,"r");
TheApplication().Utility.logStep("File Pointer: " + fp);
var fpRow = Clib.fgets (fp);
TheApplication().Utility.logStep("File Row Pointer: " + fpRow);
if ( fp != null )
{
TheApplication().SetProfileAttr("CMIBypassUIUpdate", "Y");
while (fpRow!=null)
{
bNewRec = false;
rowArray = fpRow.split("|");
if ( sSRTBC != null )
{
try
{
//var sSPF ="EBU"+ rowArray[0]+"EF";
var sSPF = rowArray[0];
var sSGC =sBU + rowArray[0]+rowArray[1]+"GC";
//var sSPC ="EBU"+ rowArray[0]+rowArray[1]+rowArray[2]+"PC";
var sSPC = rowArray[2];
sIPBC.ClearToQuery();
sIPBC.SetSearchSpec("Name",sSPF);
sIPBC.ExecuteQuery(ForwardOnly);
var sSPFCount = sIPBC.CountRecords();
if(sIPBC.FirstRecord())
var PF = sIPBC.GetFieldValue("Id");
sMastBC.ClearToQuery();
sMastBC.SetSearchSpec("CMI Master Code Type",sSGC);
sMastBC.ExecuteQuery(ForwardOnly);
if(sMastBC.FirstRecord())
var GC = sMastBC.GetFieldValue("Id");
var sSGCCount = sMastBC.CountRecords();
//if(sSPFCount == 1 && sSGCCount == 1 && sSPCCount ==1)
if(sSPFCount == 1 && sSGCCount == 1)
{
sSRTBC.ActivateField("Last Step Id");
sSRTBC.ClearToQuery();
sSRTBC.SetSearchSpec("CMI Prod Family Id",PF);
sSRTBC.SetSearchSpec("CMI Group Id",GC);
sSRTBC.SetSearchSpec("CMI Procedure Id",sSPC);
sSRTBC.ExecuteQuery(ForwardOnly);
if (sSRTBC.FirstRecord())
var sSRId = sSRTBC.GetFieldValue("Id");
var sSRTCT = sSRTBC.CountRecords();
if (sSRTCT == 1)
{
sStepBC.ClearToQuery();
sStepBC.SetSearchSpec("Header Id",sSRId);
sStepBC.SetSearchSpec("Step Num",rowArray[3]);
sStepBC.ExecuteQuery(ForwardOnly);
var sStepct = sStepBC.CountRecords();
if(sStepct == 0)
{
sStepBC.NewRecord(NewAfter);
bNewRec = true;
sStepBC.SetFieldValue("Header Id",sSRId);
sStepBC.SetFieldValue("Step Num", rowArray[3]);
sStepBC.WriteRecord();
var sStepId = sStepBC.GetFieldValue("Id");
sSRTBC.SetFieldValue("Last Step Id",sStepId);
sSRTBC.WriteRecord();
TheApplication().Utility.logStep("LastStepId: " + sStepId + " is updated for SRT Header Id: " + sSRId);
Ctr = Ctr + 1;
sErrMsg = rowArray[0] + "|" + rowArray[1] + "|" + rowArray[2] + "|" + rowArray[3];
TheApplication().Utility.logStep("Step("+sStepId+") created for SRT" + sErrMsg);
}//End if(sStepct == 1)
else
{
sErrMsg = rowArray[0] + "|" + rowArray[1] + "|" + rowArray[2] + "|" + rowArray[3];
TheApplication().Utility.logStep("Step exists for the SRT" + sErrMsg);
}
}
else
{
TheApplication().Utility.logStep("SRT Not Found: " + rowArray[0] +"|" + rowArray[1] + "|" + rowArray[2] + "|" + rowArray[3]);
}
}// End of if (sSRTCT == 1)
else
{
TheApplication().Utility.logStep("SRT Header Does Not Exist: " + rowArray[0]+ "|" + rowArray[1] + "|" + rowArray[2] + "|" + rowArray[3]);
}
}//End of try
catch(e)
{
if(bNewRec)
{
sStepBC.UndoRecord();
bNewRec = false;
}
nErrCount = nErrCount + 1;
TheApplication().Utility.logStep("Error is: " +e.errText + "\n" + rowArray[0] +"|" + rowArray[1] + "|" + rowArray[2] + "|" + rowArray[3]);
}
}// end of if
fpRow = Clib.fgets (fp);
}//end of while
}
else
{
sErrMsg = "File: " + sFileName + " not found";
TheApplication().Utility.logStep("File Exists? " + sErrMsg);
}
var sMsg = sBU+"_SRTStep";
sErrCountMsg = sMsg + "Errors";
TheApplication().Utility.logStep(sMsg +": " +Ctr);
TheApplication().Utility.logStep(sErrCountMsg +": " +nErrCount);
}
catch(e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
fp = null;
PF = null;
GC = null;
sSPF = null;
sSPC = null;
sSGC = null;
sSPFCount=null;
sSGCCount=null;
sSRTCT = null;
TheApplication().SetProfileAttr("CMIBypassUIUpdate", "N");
Outputs.SetProperty(sMsg, Ctr);
Outputs.SetProperty(sErrCountMsg, nErrCount);
TheApplication().Utility.logUnstack();
}
}

CMI SRT Validation Service
CheckSRTValidity
/*********************************************************
Modified By: Arun N Chellathurai
DESCRIPTION: Modified the function as per Bug # DBNG00000289
OUTPUTS: None
DATE CREATED: 13-Oct-2011
Bug # DBUNG00000289
UPDATES:
*********************************************************/
function CheckSRTValidity(sQuoteId, sSRProdLine, sSRAccessCode)
{
try {
TheApplication().Utility.logStack("CheckSRTValidity", this);
sSRTCount = 0;
var oQuoteBusObj:BusObject = TheApplication().GetBusObject("CMI Quote");
// var oQuoteBusComp:BusComp = oQuoteBusObj.GetBusComp("CMI Quote Simple");
var oQuoteItemBusComp:BusComp = oQuoteBusObj.GetBusComp("Quote Item (Simple)");
var sSRTBC:BusComp;
var sStepBC:BusComp;
var sGroupPickBusComp:BusComp;
var isItemRec;
var sSRTId;
var sStepId;
var sAccCd;
var sSRTGroupCodeId:String;
var sSRTStatus:String;
var sSRTErrorMsg:String = "";
var sSRTGroup:String;
var sSRTProcedure:String;
var sSRTProductLine:String;
var sSRTBU:String;
var sSRTStep:String;
var sSRTMsg:String;
var sSRTQuanReq:String;
var sSRTQuantity:String;
/* with(oQuoteBusComp) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sQuoteId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
*/
with(oQuoteItemBusComp) {
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 Group Id");
ActivateField("CMI SRT Group");
ActivateField("CMI SRT Step Num");
ActivateField("CMI SRT Procedure");
ActivateField("CMI Product Line");
ActivateField("CMI SRT Step Num");
ActivateField("Quantity Requested");
ActivateField("CMI SRT Quantity");
ActivateField("Description");
ActivateField("CMI Vendor");
ClearToQuery();
SetSearchSpec("Quote Id", sQuoteId);
SetSearchSpec("Product Type", TheApplication().InvokeMethod("LookupValue", "PRODUCT_TYPE", "Labor"));
ExecuteQuery();
isItemRec = FirstRecord();
while(isItemRec) {
sSRTStatus = "Success";
sSRTMsg = "";
sSRTId = GetFieldValue("CMI SRT Id");
sAccCd = GetFieldValue("CMI SRT Access Code");
sStepId = GetFieldValue("CMI SRT Step Id");
sSRTGroupCodeId = GetFieldValue("CMI SRT Group Id");
sSRTGroup = GetFieldValue("CMI SRT Group");
sSRTProcedure = GetFieldValue("CMI SRT Procedure");
sSRTProductLine = GetFieldValue("CMI Product Line");
sSRTStep = GetFieldValue("CMI SRT Step Num");
sSRTQuanReq = GetFieldValue("Quantity Requested");
sSRTQuantity = GetFieldValue("CMI SRT Quantity");
if (sSRProdLine != "" && sSRProdLine != null)
{
if (sSRTProductLine != sSRProdLine)
{
SetFieldValue("CMI Product Line", sSRProdLine);
sSRTProductLine = sSRProdLine;
}
}
sSRTProductLine = GetFieldValue("CMI Product Line");
sSRTBU = GetFieldValue("CMI Vendor");
if(sAccCd == "" || sAccCd == null)
{
SetFieldValue("CMI SRT Access Code", sSRAccessCode);
sAccCd = sSRAccessCode;
}
sAccCd = GetFieldValue("CMI SRT Access Code");
if (sSRTGroupCodeId != "" && sSRTGroupCodeId != null)
{
sGroupPickBusComp = oQuoteItemBusComp.GetPicklistBusComp("CMI SRT Group");
with(sGroupPickBusComp)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Master Code", sSRTGroup);
ExecuteQuery();
if(FirstRecord())
{
Pick();
}
else
{
sSRTCount = sSRTCount + 1;
sSRTStatus = "SRT Group Fail";
}
}
}
if(sSRTId != null && sSRTId != "" && sSRTStatus == "Success")
{
sSRTBC = oQuoteItemBusComp.GetPicklistBusComp("CMI SRT Procedure");
with(sSRTBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("CMI Procedure Id", sSRTProcedure);
ExecuteQuery();
if(FirstRecord())
{
Pick();
}
else
{
sSRTCount = sSRTCount + 1;
sSRTStatus = "SRT Proc Fail"
}
}
}//end of if(SRTId)
SetFieldValue("CMI SRT Quantity", sSRTQuantity);
if(sStepId != null && sStepId != "" && sSRTStatus == "Success")
{
sStepBC = oQuoteItemBusComp.GetPicklistBusComp("CMI SRT Step Num");
with(sStepBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Step Num", sSRTStep);
ExecuteQuery();
if(FirstRecord())
{
Pick();
}
else
{
sSRTCount = sSRTCount + 1;
sSRTStatus = "SRT Step Fail"
}
}
}//end of if(SRTStepId)
//}//end of if(AccCd)
SetFieldValue("Quantity Requested", sSRTQuanReq);
TheApplication().Utility.logStep("Process Line "+GetFieldValue("Line Number")+" Product Line/Group/Proc/Step/Access - "+sSRTProductLine+" / "+sSRTGroup+" / "+sSRTProcedure+" / "+sSRTStep+" / "+sAccCd+" - "+sSRTStatus);
if (sSRTStatus != "Success") {
//If there is an error, reset all SRT fields to blank (MJB 8/7/12 cq9366)
/* if (sSRTStatus == "SRT Group Fail")
{
SetFieldValue("CMI SRT Group Id", "");
SetFieldValue("CMI SRT Id", "");
}
else if(sSRTStatus == "SRT Proc Fail")
{
SetFieldValue("CMI SRT Id", "");
}
*/
SetFieldValue("CMI SRT Group Id", "");
SetFieldValue("CMI SRT Id", "");
SetFieldValue("CMI SRT Step Id", "");
SetFieldValue("CMI SRT Hours", "");
SetFieldValue("Quantity Requested", "0");
SetFieldValue("CMI SRT Quantity", "0");
var oErrorService = TheApplication().GetService("CMI DBU Generic BS");
var psInput = TheApplication().NewPropertySet();
var psOutput = TheApplication().NewPropertySet();
psInput.SetProperty("Message Name", "CMI SRT Error Msg");
psInput.SetProperty("SRT Group", sSRTGroup);
psInput.SetProperty("SRT Procedure", sSRTProcedure);
psInput.SetProperty("SRT Step", sSRTStep);
psInput.SetProperty("SRT Product Line", sSRTProductLine);
psInput.SetProperty("SRT Access Code", sAccCd);
psInput.SetProperty("SRT Business Unit", sSRTBU);
oErrorService.InvokeMethod("Error Message",psInput,psOutput);
sSRTMsg = psOutput.GetProperty("CMI Error Msg");
}
SetFieldValue("Description", sSRTMsg);
WriteRecord();
isItemRec = NextRecord();
}//end of isItemRec
}//end of BCQuoteItem
// }//end of if(FirstRecord)
// }//End of oBCQuote
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sStepBC = null;
sSRTBC = null;
sGroupPickBusComp = null;
oQuoteBusObj = null;
// oQuoteBusComp = null;
oQuoteItemBusComp = null;
oErrorService = null;
psInput = null;
psOutput = null;
TheApplication().Utility.logUnstack("Error Count: "+sSRTCount);
}
}

CMI SRT Validation Service
(declarations)
var sSRTCount = 0;

CMI SRT Validation Service
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if (MethodName == "SRT Validation") {
var sSRTQuoteId = Inputs.GetProperty("Quote Id");
var sSRTProdLine = Inputs.GetProperty("SR Product Line");
var sSRTAccessCode = Inputs.GetProperty("SR Access Code");
CheckSRTValidity(sSRTQuoteId, sSRTProdLine, sSRTAccessCode);
Outputs.SetProperty("SRT Fail Count",sSRTCount);
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI SRT Validation Service
Service_PreCanInvokeMethod
function Service_PreCanInvokeMethod (MethodName, &CanInvoke)
{
try
{
if (MethodName == "SRT Validation")
{
CanInvoke = "TRUE";
return (CancelOperation);
}
}
catch(e)
{
throw(e);
}
return (ContinueOperation);
}

CMI Set Asset Access Code BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : ix964
Created On : 04 Nov 2010
Method Name:
Functionality:
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//Add Try Catch Blockby jw920 on 22/08/11 <Code Clean UP>
try
{
if (MethodName == "SetAccessCode")
{
SetAccessCode();
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 Set Asset Access Code BS
SetAccessCode
/*************************************************************************************************************************
Created By : ix964
Created On : 04 Nov 2010
Method Name:
Functionality:
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function SetAccessCode()
{
try
{
var sAssetBO = TheApplication().ActiveBusObject();
var sAssetTransBC = sAssetBO.GetBusComp("Asset Mgmt - Asset Transaction");
var sAssetBC = sAssetBO.GetBusComp("Asset Mgmt - Asset");
var oAssetBO = TheApplication().GetBusObject("Asset Management");
var oAssetBC = oAssetBO.GetBusComp("Asset Mgmt - Asset");
var sParentAccessCode = "";
var sTransAssetId;
var sParentAssetId;
var sAddressId = "";
with(sAssetBC)
{
ActivateField("Personal Address Id");
sParentAccessCode = GetFieldValue("CMI Access Code");
sParentAssetId = GetFieldValue("Id");
sAddressId = GetFieldValue("Personal Address Id");
}
with(sAssetTransBC)
{
sTransAssetId = GetFieldValue("Transaction Asset Id");
}
with(oAssetBC)
{
SetViewMode(AllView);
ClearToQuery();
var searchst = "[Id] = '" + sTransAssetId + "'";
SetSearchExpr(searchst);
ExecuteQuery(ForwardOnly);
var sActive = TheApplication().InvokeMethod("LookupValue", "IMPL_PHASE", "Active");
if (FirstRecord())
{
// added by jr430 to fix ClearQuest Issue : DBUNG00000326
if (sParentAccessCode != null && sParentAccessCode != "")
{
/* only change the child asset's access code when parent asset's
access code is not null and is not blank
*/
SetFieldValue("CMI Access Code", sParentAccessCode);
}
// end add
SetFieldValue("Status", sActive);
if(sAddressId != "" && sAddressId != null)
{
var oAddressBC = GetPicklistBusComp("Personal Address");
with(oAddressBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sAddressId);
ExecuteQuery(ForwardOnly);
var haveAddress = FirstRecord();
if(haveAddress)
{
Pick();
}
}
}//end if
WriteRecord();
}
}
}
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());
}
}
finally
{
//added by shanmukh for code clean up 08/27/2011
oAddressBC = null;
sAssetTransBC = null;
sAssetBC = null;
oAssetBC = null;
sAssetBO = null;
oAssetBO = null;
}
}

CMI Set Exchange Date BS
SetOrderLineWarrantyExchangeDate
/*************************************************************************************************************************
Created By : JR429
Created On : 29th Apirl 2011
Method Name: function BusComp_PreInvokeMethod (MethodName) == "SetQuoteExchangeDate"
Functionality: when Order Status change to Order Placed, it will set the today time to Exchagne Date in CMI Order Item Warranty and order item.
Input: Object Id
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function SetOrderLineWarrantyExchangeDate(Inputs, Outputs)
{
try
{
var strOrderId = Inputs.GetProperty("Order Id");
var strToday = Inputs.GetProperty("strToday");
var oBO = TheApplication().GetBusObject("CMI Order Line Item Warranty");
var oBCWarrItem = oBO.GetBusComp("CMI Order Line Item Warranty");
var isRecord = "";
var strTime;
var boOrder = TheApplication().GetBusObject("PDS Simplified Order");
var bcOrderItem = boOrder.GetBusComp("PDS Simplified Order Entry - Line Items");
var isRecordItem = "";
with(bcOrderItem)
{
SetViewMode(AllView);
ActivateField("Exchange Date");
ActivateField("Order Header Id");
ClearToQuery();
SetSearchSpec("Order Header Id",strOrderId);
ExecuteQuery(ForwardOnly);
isRecordItem = FirstRecord();
while(isRecordItem)
{
SetFieldValue("Exchange Date", strToday);
WriteRecord();
isRecordItem = NextRecord();
}
}
with(oBCWarrItem)
{
SetViewMode(AllView);
ActivateField("CMI Exchange Date");
ActivateField("CMI Order Id");
ActivateField("CMI Calculate Today");
ClearToQuery();
SetSearchSpec("CMI Order Id",strOrderId);
ExecuteQuery(ForwardOnly);
isRecord = FirstRecord();
if(isRecord)
{
strTime = GetFieldValue("CMI Calculate Today");
SetFieldValue("CMI Exchange Date", strTime);
WriteRecord();
}
}
}// end try
catch(e)
{
throw(e);
}
finally
{
bcOrderItem = null;
boOrder = null;
oBCWarrItem = null;
oBO = null;
}
}

CMI Set Exchange Date BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName,Inputs,Outputs)
{
//Add try catch block by jw920 on 22/08/11 <Code Clean Up>
try
{
if(MethodName == "SetQuoteExchangeDate")
{
var sQuoteId = TheApplication().GetProfileAttr("Object Id");
SetQuoteExchangeDate(sQuoteId);
return(CancelOperation);
}
if(MethodName == "SetOrderLineWarrantyExchangeDate")
{
SetOrderLineWarrantyExchangeDate(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());
}
}
return(ContinueOperation);
}

CMI Set Exchange Date BS
SetQuoteExchangeDate
/*************************************************************************************************************************
Created By : JR429
Created On : 29th Apirl 2011
Method Name: function BusComp_PreInvokeMethod (MethodName) == "SetQuoteExchangeDate"
Functionality: when Quote Status change to Quote Ready, it will set the today time to the Exchange Date in Quote Item and
CMI Quote Item Warranty.
Input: sQuoteId
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function SetQuoteExchangeDate(sQuoteId)
{
try
{
//var sQuoteId = Inputs.GetProperty("Quote Id");
var oBO = TheApplication().GetBusObject("Quote");
var oBCQuoteItem = oBO.GetBusComp("Quote Item");
var oBCWarrItem = oBO.GetBusComp("CMI Quote Item Warranty");
var isRecordItem = "";
var isRecordWarr = "";
var strTime = "";
with(oBCQuoteItem)
{
SetViewMode(AllView);
ActivateField("Exchange Date");
ActivateField("Quote Id");
ActivateField("CMI Calculate Today");
ClearToQuery();
SetSearchSpec("Quote Id",sQuoteId);
ExecuteQuery(ForwardOnly);
isRecordItem = FirstRecord();
while(isRecordItem)
{
strTime = GetFieldValue("CMI Calculate Today");
SetFieldValue("Exchange Date",strTime);
WriteRecord();
isRecordItem = NextRecord();
}
}
with(oBCWarrItem)
{
SetViewMode(AllView);
ActivateField("CMI Exchange Date");
ActivateField("CMI Quote Id");
ClearToQuery();
SetSearchSpec("CMI Quote Id",sQuoteId);
ExecuteQuery(ForwardOnly);
isRecordWarr = FirstRecord();
while(isRecordWarr)
{
SetFieldValue("CMI Exchange Date",strTime);
WriteRecord();
isRecordWarr = NextRecord();
}
}
}// end try
catch(e)
{
throw(e);
}
finally
{
oBCWarrItem = null;
oBCQuoteItem = null;
oBO = null;
}
}

CMI Set Quote Head Bill To Site
Service_PreInvokeMethod
/***********************************************************************************
**Process to set the Bill To Site at Header when its picked at Payment level,
****or set it at Payment when picked at Header level (currently this is active).
**Circular loop to be avoided by setting the Runtime Events appropriately.
** CMI Set Order Head Bill To Site
** CMI Set Quote Head Bill To Site
** CMI Set Order Payment
** CMI Set Quote Payment
***********************************************************************************/
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 "SetQuoteHead":
setQuoteHeadBillFlag();
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
case "SetOrderHead":
setOrderHeadBillFlag();
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
case "SetQuotePayment":
SetQuotePayment();
return (CancelOperation);
//Commented by shanmukh for code clean up 08/29/2011
//break;
case "SetOrderPayment":
SetOrderPayment();
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 by shanmukh for code clean up 08/27/2011
finally
{
}*/
//<End>
return (ContinueOperation);
}
/* Removing the if Condition as it will take 4hits to reach Set Order Payment, where as switch only once.
if(MethodName == "SetQuoteHead")
{
setQuoteHeadBillFlag();
return (CancelOperation);
}
else if(MethodName == "SetOrderHead")
{
setOrderHeadBillFlag();
return (CancelOperation);
}
else if(MethodName == "SetQuotePayment")
{
SetQuotePayment();
return (CancelOperation);
}
else if(MethodName == "SetOrderPayment")
{
SetOrderPayment();
return (CancelOperation);
}
*/

CMI Set Quote Head Bill To Site
SetOrderPayment
/*************************************************************************************************************************
Created By : Macro Wang
Created On : 7th Jan 2011
C&I Number :
Requirement # :
Method Name: function SetOrderPayment ()
Functionality: Set Order Payment
Input:
Output:
Customization Approval #:
************************************************************************************************************************/
function SetOrderPayment ()
{
try
{
var boOrder = TheApplication().ActiveBusObject();
var bcOrderHead = boOrder.GetBusComp("Order Entry - Orders");
var bcPayments = boOrder.GetBusComp("Payments");
bcOrderHead.ActivateField("CMI Bill To Profile Name");
var sPaymentProfileName = bcOrderHead.GetFieldValue("CMI Bill To Profile Name");
var sOrderHeadId = bcOrderHead.GetFieldValue("Id");
var nNum = 0;
if(sPaymentProfileName != "")
{
with(bcPayments)
{
ActivateField("Payment Profile Name");
ActivateField("Order Id");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Order Id",sOrderHeadId);
ExecuteQuery(ForwardBackward);
nNum = CountRecords();
if(nNum == 0)
{
NewRecord(1);
SetFieldValue("Payment Profile Name",sPaymentProfileName);
WriteRecord();
}
else if(nNum == 1)
{
SetFieldValue("Payment Profile Name",sPaymentProfileName);
WriteRecord();
}
}
}
}
catch(e)
{
throw e;
}
finally
{
boOrder = null;
bcPayments = null;
bcOrderHead = null;
sPaymentProfileName = null;
}
}

CMI Set Quote Head Bill To Site
SetQuotePayment
/*************************************************************************************************************************
Created By : Macro Wang
Created On : 7th Jan 2011
C&I Number :
Requirement # :
Method Name: function SetQuotePayment ()
Functionality: Set Quote Payment
Input:
Output:
Customization Approval #:
************************************************************************************************************************/
function SetQuotePayment ()
{
try
{
var boQuote = TheApplication().ActiveBusObject();
var bcQuoteHead = boQuote.GetBusComp("Quote");
var bcPayments = boQuote.GetBusComp("Payments");
bcQuoteHead.ActivateField("CMI Bill To Profile Name");
var sPaymentProfileName = bcQuoteHead.GetFieldValue("CMI Bill To Profile Name");
var sQuoteId = bcQuoteHead.GetFieldValue("Id");
var nNum = 0;
if(sPaymentProfileName != "")
{
with(bcPayments)
{
ActivateField("Payment Profile Name");
ActivateField("Order Id");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Order Id",sQuoteId);
ExecuteQuery(ForwardBackward);
nNum = CountRecords();
if(nNum == 0)
{
NewRecord(1);
SetFieldValue("Payment Profile Name",sPaymentProfileName);
WriteRecord();
}
else if(nNum == 1)
{
SetFieldValue("Payment Profile Name",sPaymentProfileName);
WriteRecord();
}
}
}
}
catch(e)
{
throw e;
}
finally
{
boQuote = null;
bcPayments = null;
bcQuoteHead = null;
sPaymentProfileName = null;
}
}

CMI Set Quote Head Bill To Site
setOrderHeadBillFlag
/*************************************************************************************************************************
Created By : Macro Wang
Created On : 7th Jan 2011
C&I Number :
Requirement # :
Method Name: function setOrderHeadBillFlag()
Functionality: Set Order Header BillFlag
Input:
Output:
Customization Approval #:
************************************************************************************************************************/
function setOrderHeadBillFlag()
{
try
{
var boOrder = TheApplication().ActiveBusObject();
var bcOrderHead = boOrder.GetBusComp("Order Entry - Orders");
var bcPayments = boOrder.GetBusComp("Payments");
var sPaymentProfileName = bcPayments.GetFieldValue("Payment Profile Name");
var bcPick;
if(sPaymentProfileName != "")
{
with(bcOrderHead)
{
ActivateField("CMI Bill To Profile Name");
/*
bcPick = GetPicklistBusComp("CMI Bill To Profile Name");
with(bcPick)
{
ActivateField("Name");
ClearToQuery();
SetSearchSpec("Name",sPaymentProfileName);
ExecuteQuery(ForwardBackward);
var iCount = CountRecords();
if(FirstRecord())
Pick();
}
WriteRecord();
*/
SetFieldValue("CMI Bill To Profile Name",sPaymentProfileName);
}
}
}
catch(e)
{
throw e;
}
finally
{
boOrder = null;
bcPayments = null;
bcOrderHead = null;
// bcPick = null;
sPaymentProfileName = null;
// hasRec = null;
}
}

CMI Set Quote Head Bill To Site
setQuoteHeadBillFlag
/*************************************************************************************************************************
Created By : Macro Wang
Created On : 7th Jan 2011
C&I Number :
Requirement # :
Method Name: function setQuoteHeadBillFlag()
Functionality: Set Quote Head Bill Flag
Input:
Output:
Customization Approval #:
************************************************************************************************************************/
function setQuoteHeadBillFlag()
{
try
{
var boQuote = TheApplication().ActiveBusObject();
var bcPayments = boQuote.GetBusComp("Payments");
var sPaymentProfileName = bcPayments.GetFieldValue("Payment Profile Name");
var bcQuote = boQuote.GetBusComp("Quote");
var bcPick;
if(sPaymentProfileName != "")
{
with(bcQuote)
{
ActivateField("CMI Bill To Profile Name");
/*
bcPick = GetPicklistBusComp("CMI Bill To Profile Name");
with(bcPick)
{
ActivateField("Name");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Name",sPaymentProfileName);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
Pick();
}
WriteRecord();
*/
SetFieldValue("CMI Bill To Profile Name",sPaymentProfileName);
}
}
}
catch(e)
{
throw e;
}
finally
{
boQuote = null;
bcPayments = null;
bcQuote = null;
// bcPick = null;
sPaymentProfileName = null;
// hasRec = null;
}
}

CMI Set Summary Currency Code BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if(MethodName == "SetSummaryCurrencyCode") {
var oBOSR = TheApplication().ActiveBusObject();
if (oBOSR != null && typeof(oBOSR) != "undefined") {
if(oBOSR.Name() == "Service Request" || oBOSR.Name() == "CMI Parent SR") {
var oBCSR = oBOSR.GetBusComp("Service Request");
var oBCQuote = oBOSR.GetBusComp("Quote");
var sSRId = oBCSR.GetFieldValue("Id");
with (oBCQuote) {
ExecuteQuery(ForwardOnly);
if (FirstRecord()) {
TheApplication().SetProfileAttr("CMISumCurrencyCode", GetFieldValue("Currency Code"));
} else {
var oBCOrder = oBOSR.GetBusComp("Order Entry - Orders");
with (oBCOrder) {
ExecuteQuery(ForwardOnly);
if (FirstRecord()) {
TheApplication().SetProfileAttr("CMISumCurrencyCode", GetFieldValue("Currency Code"));
}
}
}
}
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCOrder = null;
oBCQuote = null;
oBCSR = null;
oBOSR = null;
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

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

CMI Show UserName BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : Woody Wu (JR426)
Created On : 2011-6-17
C&I Number : 4468
Functionality: Create new BS to Chang the CCFrameViewbar.swt for Enhancement S121.
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("PreInvoke."+MethodName, this, false);
if (MethodName == "GetUserName") {
var displayType = TheApplication().Utility.GetSysPref("CMI Toolbar Display Fields");
var display = TheApplication().GetProfileAttr("Full Name");
//Use a system preference to conditionall add Position and Organization to the display string in the toolbar
if (displayType.toUpperCase().indexOf("POS") >= 0)
display += " (" + TheApplication().PositionName() + ")";
if (displayType.toUpperCase().indexOf("ORG") >= 0)
display += " - " + TheApplication().GetProfileAttr("CMI Current Organization");
TheApplication().SetProfileAttr("PositionDisplay", display);
return (CancelOperation);
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack();
}
return (ContinueOperation);
}

CMI Submit For Invoice BS
(declarations)
var sParentSRId:String="";
var sRelatedSRId:String="";
var sQuoteId:String="";
var sInvokeLevel:String="";
var sIRN:String="";

CMI Submit For Invoice BS
CreateInvRefNum
function CreateInvRefNum()
{
/*********************************************************
AUTHOR: KM330
C&I:4469
Enhancement: S126,147
DESCRIPTION: The below function will create Invoice reference number
and return the new IRN back to calling function
DATE CREATED: 23 Sep 2011
*********************************************************/
try {
TheApplication().Utility.logStack("CreateInvRefNum", this);
var dateVar = new Date;
var sYear = dateVar.getFullYear();
var stringYear :String = ToString(sYear);
var lastNum = stringYear.charAt(stringYear.length-1);// to get the last digit of the year
var secondLastNum :String= stringYear.charAt(stringYear.length-2);// to get the second last digit of the year
var lasttwodigityear = Clib.strncat(secondLastNum, lastNum, 1);//appends the last num to second last num
var CharPerYear = 100000;
var newIRN :String;
var found = false;
var lastIRN="";
var oBOFS = TheApplication().GetBusObject("FS Invoice");
var oBCFS = oBOFS.GetBusComp("FS Invoice");
var currentOrg;
//added below block to get current highest invoice number,KM330,06/12/2011,for defect 854
with(oBCFS) {
SetViewMode(AllView);
ActivateField("Integration Id");
ActivateField("CMI Current Organization Id");
ClearToQuery();
SetSearchExpr("[Integration Id] IS NOT NULL AND [Order Id] IS NOT NULL AND [CMI Bill To Profile Organization Id] = [CMI Current Organization Id]");
SetSortSpec("Integration Id (DESCENDING)");
ExecuteQuery(ForwardOnly);
found = FirstRecord();
if (found) {
lastIRN = GetFieldValue("Integration Id");
currentOrg = GetFieldValue("CMI Current Organization Id");
}
TheApplication().Utility.logVars("Invoice Found?", found, "Old IRN", lastIRN, "Current Org", currentOrg);
}//end for block added for defect 854
newIRN = ToString(lastIRN);
var FirstDigitOfRefNum = newIRN.charAt(0);
var SecondDigitOfRefNum = newIRN.charAt(1);
var FirstTwoDigit = FirstDigitOfRefNum + SecondDigitOfRefNum; //removed the string type as the compile was failing by ki795
if(FirstTwoDigit != lasttwodigityear) {
newIRN = Clib.strncat(lasttwodigityear, CharPerYear, 6);
} else if(lastIRN == "" || lastIRN == null) {
newIRN = Clib.strncat(lasttwodigityear, CharPerYear, 6);
} else {
/*lastIRN = lastIRN+1;
newIRN =lastIRN;*/ // added below block to increment the invoice number.
newIRN = lastIRN.substr(2,lastIRN.length);
lastIRN = ToNumber(newIRN);
lastIRN++;
newIRN =Clib.strncat(lasttwodigityear, lastIRN, 6);
}
if(newIRN.length < 8 || newIRN.length>10) {
TheApplication().RaiseErrorText("Length of Invoice Reference number should be minimum '8' characters and maximum '10' characters.");
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCFS =null;
oBOFS =null;
dateVar=null;
TheApplication().Utility.logUnstack(newIRN);
}
return(newIRN);
}

CMI Submit For Invoice BS
GenerateInvoiceRefNumber
function GenerateInvoiceRefNumber(Inputs, Outputs)
{
/*********************************************************
AUTHOR: KM330
C&I:4469
Enhancement: S126,147
DESCRIPTION: The below function will update Invoice reference number on Order
and return the new IRN back to calling function
DATE CREATED: 15 Sep 2011
*********************************************************/
try
{
TheApplication().Utility.logStack("GenerateInvoiceRefNumber", this);
var sPSRCon = Inputs.GetProperty("CMI Parent SR Consolidated");
var sRSRCon = Inputs.GetProperty("CMI Related SR Consolidated");
var sOrderId = Inputs.GetProperty("CMI Order Id");
var sIRN = Inputs.GetProperty("CMI Invoice Reference number");
var sInvoke = Inputs.GetProperty("CMI Invokation level");
var oBO:BusObject;
TheApplication().Utility.logVars("Invokation Level", sInvoke);
if(sInvoke=="Order") oBO = TheApplication().GetBusObject("Order Entry (Sales)");
else oBO = TheApplication().GetBusObject("Service Request");
var oBCOrder:BusComp = oBO.GetBusComp("Order Entry - Orders");
var oBCFSInv:BusComp = oBO.GetBusComp("FS Invoice");
var found = false;
var currIRN="";
var billToProfileId = "";
TheApplication().Utility.logVars("Invoice Ref #", sIRN, "Order Id", sOrderId);
with(oBCOrder) {
SetViewMode(AllView);
ActivateField("CMI Inv Ref Number");
ActivateField("CMI Bill To Profile Id");
ClearToQuery();
SetSearchSpec("Id",sOrderId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
//Only create a new IRN if order is not a resubmit
currIRN = GetFieldValue("CMI Inv Ref Number");
billToProfileId = GetFieldValue("CMI Bill To Profile Id");
TheApplication().Utility.logVars("Current Invoice Ref #", currIRN);
if (currIRN == "" || currIRN == null) {
//Is still null, generate the next number
if (sIRN == null || sIRN == "") sIRN = CreateInvRefNum();
with(oBCFSInv) {
SetViewMode(AllView);
ActivateField("Integration Id");
ActivateField("Order Id");
ClearToQuery();
SetSearchSpec("Order Id",sOrderId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Invoice Found?", found);
if (found) {
SetFieldValue("Integration Id", sIRN);
SetFieldValue("Personal Payment Profile Id", billToProfileId);
WriteRecord();
} else {
NewRecord(NewAfter);
SetFieldValue("Integration Id", sIRN);
SetFieldValue("Personal Payment Profile Id", billToProfileId);
SetFieldValue("Order Id",sOrderId);
WriteRecord();
}
TheApplication().Utility.logVars("Invoice Id", GetFieldValue("Id"));
}
Outputs.SetProperty("IRN",sIRN);
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCOrder = null;
oBCFSInv = null;
oBO = null;
TheApplication().Utility.logUnstack(sIRN);
}
}

CMI Submit For Invoice BS
ParseXMLForIRN
function ParseXMLForIRN(Inputs)
{
/*********************************************************
AUTHOR: JU982,
C&I:4469
Enhancement: S126,146
DESCRIPTION: The below function will parse Siebel message returned from ILog and pass it to generate Invoice reference number function
DATE CREATED: 11 Sep 2011
*********************************************************/
try {
TheApplication().Utility.logStack("ParseXMLForIRN", this);
TheApplication().Utility.logPS(Inputs);
var i, j, cntRSR, cntOrder, sPSRId, sRSRId, sOrderId, sRSRCon, sOrderType;
var psPSR = TheApplication().NewPropertySet();
var psRSR = TheApplication().NewPropertySet();
var psOrder = TheApplication().NewPropertySet();
var sIRN = "";
var sOrdTyp1 = TheApplication().InvokeMethod("LookupValue", "FS_ORDER_TYPE", "Sales Order");
var sOrdTyp2 = TheApplication().InvokeMethod("LookupValue", "FS_ORDER_TYPE", "Return Order");
var sOrdTyp3 = TheApplication().InvokeMethod("LookupValue", "FS_ORDER_TYPE", "Warranty Credit Order");
var sInvoiceSubmitted:String = TheApplication().InvokeMethod("LookupValue" ,"SR_SUB_STATUS", "Invoice Submitted");
var sNonConsolidated:String = TheApplication().InvokeMethod("LookupValue" ,"CMI_SR_INVOICE_CONSOLIDATION", "NoConsolidation");
var sConsolidated:String = TheApplication().InvokeMethod("LookupValue" ,"CMI_SR_INVOICE_CONSOLIDATION", "Consolidated");
var oSRBO = TheApplication().GetBusObject("Service Request");
var oSRBC = oSRBO.GetBusComp("Service Request");
var sParentSRId = Inputs.GetProperty("CMI Parent SR Id");
var sInvoke = Inputs.GetProperty("CMI Invoke Level");
var sPSRCon = Inputs.GetProperty("PSR Consolidated");
var sInput = TheApplication().NewPropertySet();
var sOutput = TheApplication().NewPropertySet();
var svc = TheApplication().GetService("Workflow Process Manager");
var psIn = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();
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");
sRSRCon = psRSR.GetChild(i).GetProperty("CMI SR Invoice Consolidation");
psOrder= psRSR.GetChild(i).GetChild(0);
cntOrder = psOrder.GetChildCount();
for(j=0; j<cntOrder; j++) {
sOrderId = psOrder.GetChild(j).GetProperty("Id");
sOrderType = psOrder.GetChild(j).GetProperty("CMI Order Type");
TheApplication().Utility.logVars("Order Type", sOrderType);
if ((sOrderType == sOrdTyp1)||(sOrderType == sOrdTyp2)||(sOrderType == sOrdTyp3)) {
// Conditions in which case sIRN should be nullified (for subsequent orders...)
TheApplication().Utility.logVars("Invokation Level", sInvoke, "PSR Invoice Consolidated", sPSRCon, "RSR Invoice Consolidated", sRSRCon);
if((sInvoke == "Order") ||
(sInvoke == "Related SR" && sRSRCon == sNonConsolidated) ||
(sInvoke == "Parent SR" && sPSRCon == sNonConsolidated && sRSRCon == sNonConsolidated)) {
sIRN = "";
}
// Call Invoice Reference Number Generation WF/BS and pass Order Id, sRSRCon, sPSRCon, CurrentIRN, RSRId, PSRId as an input;
psIn.SetProperty("CMI Parent SR Id",sParentSRId);
psIn.SetProperty("CMI Related SR Id",sRSRId);
psIn.SetProperty("CMI Parent SR Consolidated",sPSRCon);
psIn.SetProperty("CMI Related SR Consolidated",sRSRCon);
psIn.SetProperty("CMI Order Id",sOrderId);
psIn.SetProperty("CMI Order Type",sOrderType);
psIn.SetProperty("CMI Invoice Reference number",sIRN);
psIn.SetProperty("CMI Invokation level",sInvoke);
GenerateInvoiceRefNumber(psIn,psOut);
sIRN = psOut.GetProperty("IRN");
}
} // end of Order for loop
// Update RSR IRN if RSR is consolidated
if (sInvoke == "Related SR" || sInvoke == "Parent SR") {
if (sRSRCon == sConsolidated && sIRN != "") {
//if RSR is consolidated update IRN on RSR and nullify IRN variable
with(oSRBC) {
//This WF will take SR Id, IRN and IRN flag as an input
sInput.SetProperty("ProcessName", "CMI Update SR Sub Status and IRN");
sInput.SetProperty("Object Id", sRSRId);
sInput.SetProperty("CMI IRN", sIRN);
sInput.SetProperty("CMI IRN Flag", "Y");
svc.InvokeMethod("RunProcess", sInput, sOutput);
}// end of With
if ((sInvoke == "Related SR" ) || (sInvoke == "Parent SR" && sPSRCon == sNonConsolidated)) { //nullify IRN variable
sIRN = "";
}
} // end of sRSRCon == "Consolidated”
} // end of if (sInvokeLevel == "Related SR" or Parent SR)
} //end of For i loop of Related SR
// Update PSR sub status
if(sInvoke == "Parent SR" && (sPSRCon == sConsolidated)) {
with(oSRBC) {
//This WF will take SR Id, IRN and IRN flag as an input
sInput.SetProperty("ProcessName", "CMI Update SR Sub Status and IRN");
sInput.SetProperty("Object Id", sParentSRId);
sInput.SetProperty("CMI IRN", sIRN);
sInput.SetProperty("CMI IRN Flag", "Y");
svc.InvokeMethod("RunProcess", sInput, sOutput);
}// end of With
sIRN = ""; // nullify IRN
}// End of If sInvokeLevel= Parent SR
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
svc = null;
sInput = null;
sOutput = null;
oSRBO=null;
oSRBC=null;
sInvoke=null;
psPSR = null;
psRSR = null;
psOrder = null;
psIn = null;
psOut=null;
TheApplication().Utility.logUnstack();
}
}

CMI Submit For Invoice BS
ParseXMLForSubmit
function ParseXMLForSubmit(Inputs)
{
/*********************************************************
AUTHOR: JU982,
C&I:4469
Enhancement: S126,146
DESCRIPTION: The below function will parse Siebel message and pass it to workflow to update Asset Revision number and Submit Order process
DATE CREATED: 15 Sep 2011
*********************************************************/
try {
TheApplication().Utility.logStack("ParseXMLForSubmit", this);
TheApplication().Utility.logPS(Inputs);
var oSRBO, oSRBC, sInvokeLevel;
var i, j, cntRSR, cntQuote, sPSRId, sRSRId,sQuoteId,sRSRCon, sPSRCon, sOrderType, sFlag;
var psPSR = TheApplication().NewPropertySet();
var psRSR = TheApplication().NewPropertySet();
var psQuote = TheApplication().NewPropertySet();
var psOrder = TheApplication().NewPropertySet();
var sInvoiceSubmitted = TheApplication().InvokeMethod("LookupValue" ,"SR_SUB_STATUS", "Invoice Submitted");
var sSalesOrd = TheApplication().InvokeMethod("LookupValue", "FS_ORDER_TYPE", "Sales Order");
var sServiceRebuildOrd = TheApplication().InvokeMethod("LookupValue", "FS_ORDER_TYPE", "Service Rebuild Order");
var svc = TheApplication().GetService("Workflow Process Manager");
var sInput = TheApplication().NewPropertySet();
var sOutput = TheApplication().NewPropertySet();
var sParentSRId, sInvoke, sRSRConsolidated, sOrderId;
var cntOrder;
oSRBO = TheApplication().GetBusObject("Service Request");
oSRBC = oSRBO.GetBusComp("Service Request");
sParentSRId = Inputs.GetProperty("CMI Parent SR Id");
sInvoke = Inputs.GetProperty("CMI Invoke Level");
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");
sRSRConsolidated= psRSR.GetChild(i).GetProperty("CMI SR Invoice Consolidation");
psOrder= psRSR.GetChild(i).GetChild(0);
cntOrder = psOrder.GetChildCount();
TheApplication().Utility.logVars("Order Count", cntOrder);
if (cntOrder == 0) {// Added by kr124 to fix the bug 4770 to allow SR status to be Invoice Submitted if related orders are already submitted on 23-01-2012
sFlag = "Y";
}
for(j=0; j<cntOrder; j++) {
sOrderId = psOrder.GetChild(j).GetProperty("Id");
sOrderType = psOrder.GetChild(j).GetProperty("CMI Order Type");
TheApplication().Utility.logVars("Order Type", sOrderType);
if (sOrderType == sServiceRebuildOrd ) {
//This WF will take SROrder Id and Order Type as an input
sInput = TheApplication().NewPropertySet();
sOutput = TheApplication().NewPropertySet();
sInput.SetProperty("ProcessName", "CMI Update Asset Revision Number");
//sInput.SetProperty("Object Id", sOrderId);
sInput.SetProperty("Object Id", sRSRId);//changed the input from orderid to Related Sr 24/10/2011
sInput.SetProperty("CMI Order Type", sOrderType);
svc.InvokeMethod("RunProcess", sInput, sOutput);
}
// Call generate Tax reason message WF. Inactivated below WF invocation by ju982 on 10182011 as WF being invoked by CMI Submit Order Sub Process in next steps
/*{
sInput = TheApplication().NewPropertySet();
sOutput = TheApplication().NewPropertySet();
sInput.SetProperty("ProcessName", "CMI Generate Tax Reason Code Workflow");
sInput.SetProperty("Object Id", sOrderId);
sInput.SetProperty("sOrderType ", sOrderType);
svc.InvokeMethod("RunProcess", sInput, sOutput);
}*/
if (sOrderType == sSalesOrd) {
sFlag = "Y";
}
//This WF will take Order Id as an input
sInput = TheApplication().NewPropertySet();
sOutput = TheApplication().NewPropertySet();
sInput.SetProperty("ProcessName", "CMI Submit Order Mass Changes WF"); //Defect 3656: Updated the WF name not to Submit Order if BO Status is Submitted
sInput.SetProperty("Object Id", sOrderId);
svc.InvokeMethod("RunProcess", sInput, sOutput);
} //end of for loop for cntOrder
TheApplication().Utility.logVars("Invokation Level", sInvoke);
if (sInvoke == "Related SR" || sInvoke == "Parent SR" ) {
if (sFlag == "Y") {
//This WF will take SR Id, Substatus and IRN flag as an input
sInput = TheApplication().NewPropertySet();
sOutput = TheApplication().NewPropertySet();
sInput.SetProperty("ProcessName", "CMI Update SR Sub Status and IRN");
sInput.SetProperty("Object Id", sRSRId);
sInput.SetProperty("CMI SR Sub Status", sInvoiceSubmitted);
sInput.SetProperty("CMI IRN Flag", "N");
svc.InvokeMethod("RunProcess", sInput, sOutput);
if (sInvoke == "Related SR") {
sFlag="";
}
} // end of if sFlag = Y
}//end of For i loop of Related SR
}
// Update PSR sub status
if(sInvoke == "Parent SR" && sFlag == "Y") {
//This WF will take SR Id, Substatus and IRN flag as an input
sInput = TheApplication().NewPropertySet();
sOutput = TheApplication().NewPropertySet();
sInput.SetProperty("ProcessName", "CMI Update SR Sub Status and IRN");
sInput.SetProperty("Object Id", sParentSRId);
sInput.SetProperty("CMI SR Sub Status", sInvoiceSubmitted);
sInput.SetProperty("CMI IRN Flag", "N");
svc.InvokeMethod("RunProcess", sInput, sOutput);
}// End of If sInvokeLevel= Parent SR
sFlag="";
//Added for Defect # 494 to Refresh record by ko874 on 15/11/2011:
var srv = TheApplication().GetService("FINS Teller UI Navigation");
var sInp = TheApplication().NewPropertySet();
var sOut = TheApplication().NewPropertySet();
srv.InvokeMethod("RefreshCurrentApplet", sInp, sOut);
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sInput = null;
sOutput = null;
oSRBC=null;
sInvokeLevel=null;
psPSR = null;
psRSR = null;
psQuote = null;
psOrder = null;
oSRBO=null;
svc=null;
sOut = null;
sInp = null;
srv = null;
TheApplication().Utility.logUnstack();
}
}

CMI Submit For Invoice BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//Added by KM326 for code cleanup on 20/10/2011
try
{
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
/*if(MethodName=="GenerateInvoiceRefNumber")
{
GenerateInvoiceRefNumber(Inputs,Outputs);
return(CancelOperation);
}*/
if (MethodName == "ParseXMLForIRN") {
ParseXMLForIRN (Inputs);
}
if (MethodName == "ParseXMLForSubmit") {
ParseXMLForSubmit (Inputs);
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Task UI Clock In Out BS
AddDays
//Removed the try catch block as error handling done in the parent function by ki795 on 7-Dec-2011
function AddDays(sStatDate,days)
{
return new Date(sStatDate.getTime() + days*24*60*60*1000);
}

CMI Task UI Clock In Out BS
IsFutureDate
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 Task UI Clock In Out BS
GetStartTime
function GetStartTime(strTime)
{
var v_TimeStr;
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 = "00";
var sMinutes = "00";
var sSeconds = "00";
v_TimeStr = sMonth +"/"+ sDay +"/" + v_Time.getFullYear()+ " " + sHours+":"+sMinutes+":"+sSeconds;
}
catch(e)
{
throw(e);
}
return v_TimeStr;
}

CMI Task UI Clock In Out BS
GetEndTime
function GetEndTime(strTime)
{
var v_TimeStr;
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 = "23";
var sMinutes = "59";
var sSeconds = "59";
v_TimeStr = sMonth +"/"+ sDay +"/" + v_Time.getFullYear()+ " " + sHours+":"+sMinutes+":"+sSeconds;
}
catch(e)
{
throw(e);
}
return v_TimeStr;
}

CMI Task UI Clock In Out BS
GetCurrentDate
function GetCurrentDate(strTime)
{
var v_Time = strTime;
try
{
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 v_TimeStr;
v_TimeStr = sMonth +"/"+ sDay +"/" + v_Time.getFullYear();
v_Time = null;
}
catch(e)
{
throw(e);
}
return v_TimeStr;
}

CMI Task UI Clock In Out BS
DailyClock
function DailyClock(Inputs,Outputs)
{
try {
TheApplication().Utility.logStack("DailyClock", this);
var sStatus = Inputs.GetProperty("Status");
if (sStatus == "" || sStatus == null)
TheApplication().RaiseErrorText("Please select Start Day / End Day to proceed");
var sStartTime = Inputs.GetProperty("Start Time");
var sEndTime = Inputs.GetProperty("End Time");
var sStartTimeStr1 = new Date(sStartTime);
var sStartTimeStr = GetCurrentTime(sStartTimeStr1);
var sTimeStart = GetCurrentDate(sStartTimeStr1);
if(sEndTime != "" && sEndTime != null)
{
var sEndTimeStr1 = new Date(sEndTime);
var sEndTimeStr = GetCurrentTime(sEndTimeStr1);
var sTimeEnd = GetCurrentDate(sEndTimeStr1);
}
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("Object Id", TheApplication().LoginId());
InputPS.SetProperty("CMI Date", sStartTimeStr);
if(sStatus == TheApplication().InvokeMethod("LookupValue","CMI_DAILY_CLOCK_STATUS","Start Day"))
{
InputPS.SetProperty("Operation", "Create");
sTaskWF.InvokeMethod("RunProcess", InputPS, OutputPS);
var 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");
}
else if(sCreated != "Success")
{
TheApplication().RaiseErrorText("Error Creating Payroll Activity. Please contact Siebel Administrator");
}
}
if(sStatus == TheApplication().InvokeMethod("LookupValue","CMI_DAILY_CLOCK_STATUS","End Day"))
{
InputPS.SetProperty("Operation", "Validate");
sTaskWF.InvokeMethod("RunProcess", InputPS, OutputPS);
var sLogedIn = OutputPS.GetProperty("CMI Clocked In");
if (sLogedIn == "Y")
{
var sActId = OutputPS.GetProperty("CMI Pay Activity Id");
var sTimeId = OutputPS.GetProperty("CMI Pay Time Id");
if(sTimeId != null && sTimeId != "")
{
var boTime:BusObject = TheApplication().GetBusObject("Action");
var bcAction:BusComp = boTime.GetBusComp("Action");
with (bcAction) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sActId)
ExecuteQuery(ForwardOnly)
}
var bcTime:BusComp = boTime.GetBusComp("Time Sheet Daily Hours");
with (bcTime)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sTimeId)
ExecuteQuery(ForwardOnly)
if (FirstRecord())
{
if (sTimeStart == sTimeEnd)
{
SetFieldValue("End Time", sEndTimeStr);
WriteRecord();
}
else
{
var sStartDayEnd = GetEndTime(sStartTimeStr1);
SetFieldValue("End Time", sStartDayEnd);
WriteRecord();
var sEndDateCalc = new Date(sStartTimeStr1);
var sEndDateCalcAd;
var sTimStartHardstr;
var sTimeEndHardstr;
var sTimeEndstr = GetCurrentTime(sEndTimeStr1);
var sEndStartDateCmp;
var sEndEndDateCmp;
while(IsFutureDate(sEndDateCalc,sEndTimeStr1))
{
sEndEndDateCmp = GetCurrentDate(sEndTimeStr1);
sEndDateCalcAd = AddDays(sEndDateCalc,1);
sEndStartDateCmp = GetCurrentDate(sEndDateCalcAd);
sTimStartHardstr = GetStartTime(sEndDateCalcAd);
sTimeEndHardstr = GetEndTime(sEndDateCalcAd);
ActivateField("Start Time");
ActivateField("Item Date");
ActivateField("Activity Id");
ActivateField("Project");
NewRecord(NewAfterCopy);
SetFieldValue("Item Date", sTimStartHardstr);
SetFieldValue("Start Time", sTimStartHardstr);
SetFieldValue("Owner Login", TheApplication().GetProfileAttr("Login Name")); //Added by ki795 as part of internal Bug # 77
SetFieldValue("Activity Id", sActId);
SetFieldValue("Project", "Daily Clock");
if (sEndStartDateCmp == sEndEndDateCmp)
SetFieldValue("End Time", sTimeEndstr);
else
SetFieldValue("End Time", sTimeEndHardstr);
WriteRecord();
sEndDateCalc = sEndDateCalcAd;
}// end of while
}// end of if else if (sTimeStart == sTimeEnd)
}//end of if (FirstRecord())
}//end of with (bcTime)
}//end of if(sTimeId != null && sTimeId != "")
}//end of if (sLogedIn = "Y")
else
TheApplication().RaiseErrorText("You have not clocked in. Please clock in.");
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
bcTime = null;
bcAction = null;
boTime = null;
sTaskWF = null;
InputPS = null;
OutputPS = null;
TheApplication().Utility.logUnstack();
}
}

CMI Task UI Clock In Out 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 Task UI Clock In Out BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
switch (MethodName) {
case "DailyClock":
DailyClock(Inputs,Outputs);
break;
case "ClearDailyClock":
ClearDailyClock(Inputs,Outputs);
break;
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Task UI Clock In Out 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:
*********************************************************/
var v_TimeStr;
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;
v_TimeStr = sMonth +"/"+ sDay +"/" + v_Time.getFullYear() + " " + sHours+":"+sMinutes+":"+sSeconds;
v_Time = null;
}
catch(e)
{
throw(e);
}
return v_TimeStr;
}

CMI Task UI Generic 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)
{
DeleteRecord();
//NewRecord(NewBefore);
/*if(GetFieldValue("End Time") != "")
{
//SetFieldValue("RO Control", "N");
SetFieldValue("Comments","");
SetFieldValue("End Time","");
SetFieldValue("Start Time","");
SetFieldValue("Status","");
// SetFieldValue("RO Control", "N");
WriteRecord();
}*/
}//end-with
}
}
catch(e)
{
throw(e);
}
finally
{
bcNonBillable = null;
}
}

CMI Task UI Generic 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 sPreReading = TheApplication().GetProfileAttr("PreReading"); // Release #2 CQ Defect # 2819 Added by jw920 on 13/11/2011
var sPreSerialEntry = TheApplication().GetProfileAttr("PreSerialNo"); // Release #2 CQ Defect # 2819 Added by jw920 on 13/11/2011
var noteText = "";
var srReadingId = "";
var boAction = TheApplication().GetBusObject("Action");
var bcAction = boAction.GetBusComp("Action");
with (bcAction) {
ActivateField("CMI SN Confirmed Flag");
ActivateField("CMI Reading");
ActivateField("CMI Serial#");
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)
TheApplication().Utility.logVars("Activity Found?", FirstRecord());
if(FirstRecord()) {
var lReading = GetFieldValue("CMI Reading");
var lSerial = GetFieldValue("CMI Serial#");
sAssetNum = GetFieldValue("Asset Number");//CMI<defect#DBUNG00001108> we need dispaly Asset # in message<added by jj638 on 28july2011>
var bcTimeTracker = boAction.GetBusComp("Time Sheet Unassoc Daily Hours");
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
TheApplication().Utility.logVars("Confirm / SN / SR# / Asset Id", sConfirmFlag+"/"+sSerialInput+"/"+sSRNum+"/"+sAssetId);
if(((sConfirmFlag == "Y" || sSerialInput != "") && sSRNum != "" && sAssetId != "")) {
var boSR = TheApplication().GetBusObject("Service Request");
var bcSR = boSR.GetBusComp("Service Request");
with(bcSR) {
ActivateField("CMI Primary Asset Reading Id");
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("SR Number",sSRNum);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("SR Found?", FirstRecord());
if(FirstRecord()) {
srReadingId = GetFieldValue("CMI Primary Asset Reading Id");
//Only attempt if NEW (different) Reading has been provided
TheApplication().Utility.logVars("Activity / Input Reading", lReading+" / "+sReading);
if ((lReading != sReading && sReading != "")||(lReading == "" && sReading != "")) {
var bcMeasurement = boSR.GetBusComp("FS Asset Measurement Characteristics");
bcMeasurement.ClearToQuery();
//bcMeasurement.SetSearchSpec("Measurement Type Code",sMeasurementType);
bcMeasurement.ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Measurement Found?", bcMeasurement.FirstRecord());
if(bcMeasurement.FirstRecord()) {
var bcReading = boSR.GetBusComp("FS Asset Reading");
bcReading.NewRecord(NewAfter);
bcReading.SetFieldValue("Reading",sReading);
bcReading.SetFieldValue("Comments","SR#: "+ sSRNum);
bcReading.WriteRecord();
TheApplication().Utility.logVars("SR Reading Id", srReadingId);
//If the SR Reading has already been set, do not set it again
if (srReadingId == "") {
bcReading.InvokeMethod("ResetPrimary");
}
}
}
}
TheApplication().Utility.logVars("Serial", lSerial);
//Serial will either be confirmed by checking flag or will be manually entered. If entered, system
//should indicate if matched or not
if((lSerial != sSerialInput) || (sConfirmFlag == "Y") || (lSerial == sSerialInput && lSerial != "")) {
if (sAssetSerialNum != sSerialInput && sSerialInput !="" && sAssetSerialNum !="") {
lSerial= sSerialInput;
noteText = "Serial# does not match asset. Confirmed Serial#:";
} else {
lSerial = sAssetSerialNum;
noteText = "Serial# on SR confirmed. Confirmed Serial#:";
}
if (sReading == "") {
noteText += lSerial;
} else if (sReading != "" && sMeasurementType =="") {
noteText += lSerial+" Reading:"+ sReading+".No Measurement type listed";
} else {
noteText += lSerial+" Reading:"+ sReading+" Hours";
}
var bcNote = boSR.GetBusComp("FIN Service Request Notes");
var sLoginId = TheApplication().LoginId();//Added by LU871 on 16-09-2013 for the Note read only Issue
bcNote.ActivateField("Created By");
bcNote.ActivateField("Note");
bcNote.ActivateField("Note Type");
bcNote.ActivateField("CMI Description");
bcNote.ClearToQuery();
bcNote.SetSearchSpec("CMI Description", "SR Confirmation");
bcNote.SetSearchSpec("Created By", sLoginId);//Added by LU871 on 16-09-2013 for the Note read only Issue
bcNote.SetSearchSpec("Note Type", TheApplication().InvokeMethod("LookupValue","FS_NOTE_TYPE","Technician Summary"));
bcNote.ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Text", noteText, "Existing Note Found?", bcNote.FirstRecord());
if (!bcNote.FirstRecord()) {
bcNote.NewRecord(NewBefore);
}
try {
bcNote.SetFieldValue("Note Type", TheApplication().InvokeMethod("LookupValue","FS_NOTE_TYPE","Technician Summary"));
} catch(e) {
//picklist constrain
TheApplication().Utility.logError(e);
}
bcNote.SetFieldValue("CMI Description", "SR Confirmation");
try {
bcNote.SetFieldValue("Note",noteText);
} catch(e) {
TheApplication().Utility.logVars("Created By", bcNote.GetFieldValue("Created By"));
//Field may be read only
throw(e);
}
bcNote.WriteRecord();
}
}
bcSR.SetFieldValue("Current Mileage",sReading);
bcSR.SetFieldValue("CMI Serial#",lSerial);
bcSR.WriteRecord();
}
//Tiger: create expense tracker
TheApplication().Utility.logVars("Mileage Required", TheApplication().GetProfileAttr("CMIMileageRequired"));
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();
}
}
bcAction.WriteRecord();
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally{
bcExpTrkr = null;
bcNote = null;
bcReading = 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>
bcSR = null;
boSR = null;
bcTimeTracker = null; //Added by jw920 on 21-08-11 <Code Clean UP Process>
bcAction = null;
boAction = null;
TheApplication().Utility.logUnstack();
}
}

CMI Task UI Generic BS
ClearBillableJob
/* Created By : Rachel-Zang
Created On : 25-Jan-2011
C&I Number : 4468
Method Name: ClearBillableJob
Functionality:
*/
function ClearBillableJob(Inputs, Outputs) {
try {
TheApplication().Utility.logStack("ClearBillableJob", this);
TheApplication().SetProfileAttr("TBUIActivityId", "") ; //lq305 08/06/2013 for retaining ActId only on Prev Button
var bcBillable = TheApplication().ActiveBusObject().GetBusComp("CMI Billable Job Option");
var oActBO;
var oBillableBC;
var bcAction;
if(bcBillable != null) {
with(bcBillable) {
var sActivityId;
var sDistance;
var sDistanceType;
var sTaskActId;
var sConfirmSN;
var sSerialNo;
var sReading;
var sSerialFlgRO;
var sReadRO;
var sSerialRO;
var sActRecord;
if(FirstRecord()) {
TheApplication().SetProfileAttr("CMITaskPreWrite","Yes");
sActivityId = GetFieldValue("Action Id");
sTaskActId = GetFieldValue("Id");
sDistance = GetFieldValue("Distance");
sDistanceType = GetFieldValue("Distance Type");
sConfirmSN = GetFieldValue("Confirm SN Flag");
sSerialNo = GetFieldValue("Serial # Entry");
sReading = GetFieldValue("Reading");
sSerialFlgRO = GetFieldValue("Confirm SN Flag Control Flag");
sReadRO = GetFieldValue("Reading Cal");
sSerialRO = GetFieldValue("Confirm SN Flag");
}//if(FirstRecord())
if (sActivityId != null && sActivityId != "") {
DeleteRecord();
NewRecord(NewBefore);
//SetFieldValue("RO Control", "N");
bcAction = GetPicklistBusComp("Action");//need to quoery the records,
if(sTaskActId != "" && sTaskActId != null) {
with(bcAction) {
ClearToQuery();
SetSearchSpec("Id", sActivityId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
Pick();
sActRecord = "Yes";
}
}// end of with(bcAction)
if (sActRecord == "Yes") {
SetFieldValue("Expense Flag","");
SetFieldValue("Interview Flag","");
SetFieldValue("Note Flag","");
SetFieldValue("Parts Tracker Flag","");
SetFieldValue("Repair Plan Flag","");
if (sSerialFlgRO != "Y") SetFieldValue("Confirm SN Flag",sConfirmSN);
if (sSerialRO != "Y") {
SetFieldValue("Serial # Entry", sSerialNo);
TheApplication().SetProfileAttr("PreSerialNo", sSerialNo); // Release #2 CQ Defect # 2819 Added by jw920 on 13/11/2011
}
if (sReadRO != "Y") {
SetFieldValue("Reading", sReading);
TheApplication().SetProfileAttr("PreReading", sReading); // Release #2 CQ Defect # 2819 Added by jw920 on 13/11/2011
}
//if Distance is required field this time, need to clear the control profile
TheApplication().SetProfileAttr("CMIMileageRequired", "N");
TheApplication().SetProfileAttr("ReadingNull","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", "Y");
} else {
with(bcAction) {
ClearToQuery();
SetSortSpec("Updated(Desc)");
ExecuteQuery(ForwardOnly);
if(FirstRecord()) {
Pick();
TheApplication().SetProfileAttr("PreSerialNo", sSerialNo); // Release #2 CQ Defect # 2819 Added by jw920 on 13/11/2011
TheApplication().SetProfileAttr("PreReading", sReading); // Release #2 CQ Defect # 2819 Added by jw920 on 13/11/2011
} else {
TheApplication().RaiseErrorText("No Billable activity scheduled. Please contact your Manager");
}
}//with(bcAction)
}//else of if (sActRecord == "Yes")
WriteRecord();
}// end of if(sTaskActId != "" && sTaskActId != null)
} else { //if (sActivityId != null && sActivityId != "")
oActBO = TheApplication().GetBusObject("Action");
oBillableBC = oActBO.GetBusComp("Action");//
var sLoginId = TheApplication().LoginId();
var sStatus = TheApplication().InvokeMethod("LookupValue","SR_STATUS","Open");
var sType = TheApplication().InvokeMethod("LookupValue","TODO_TYPE","Service Labor");
var sExpr = "[Primary Owner Id] = '" +sLoginId +"' AND [Status] <> 'Done' AND [Status] <> 'Unscheduled' AND [Status] <> 'Cancelled' AND [Type] = '" +sType +"' AND [SR Status] = '" +sStatus +"' AND [Status] <> 'Completed'";
with (oBillableBC) {
ClearToQuery();
SetSearchExpr(sExpr);
ExecuteQuery(ForwardOnly);
if(!FirstRecord()) TheApplication().RaiseErrorText("No Billable activity scheduled. Please contact your Manager");
}
}//else of if (sActivityId != null && sActivityId != "")
}//with(bcBillable)
}//if(bcBillable != "")
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().SetProfileAttr("CMITaskPreWrite","");
bcBillable = null;
oBillableBC = null;
oActBO = null;
bcAction = null;
TheApplication().Utility.logUnstack();
}
}

CMI Task UI Generic BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
try {
var retVal = CancelOperation;
switch(MethodName) {
case "ClearBillableJob":
ClearBillableJob(Inputs,Outputs);
break;
case "ClearNonBillableJob":
ClearNonBillableJob(Inputs,Outputs);
break;
case "BillableJob":
BillableJob(Inputs,Outputs);
break;
case "IsJobDone":
IsJobDone(Inputs,Outputs);
break;
case "ClearDailyClock":
ClearDailyClock(Inputs,Outputs);
break;
}
} catch(e) {
TheApplication().SetProfileAttr("CMITaskPreWrite","");
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Task UI Generic 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 Task UI Generic 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 {
TheApplication().Utility.logStack("IsJobDone", this);
Outputs.SetProperty("DoneFlag","Y"); //set default
var sActionId = Inputs.GetProperty("ActionId");
TheApplication().Utility.logVars("Action Id", sActionId);
if(sActionId != "") {
var bcSheet:BusComp = 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) {
TheApplication().Utility.RaiseError(e);
} finally{
sActionId = null;//added by jj638 on 25 May2011
bcSheet = null;//added by jj638 on 25 May2011
TheApplication().Utility.logUnstack(Outputs.GetProperty("DoneFlag"));
}
}

CMI Time Tracker BS
CMIAssignTT
function CMIAssignTT(sTTId)
{
try {
var sTSLId = "";
var sTSId = "";
var sPeriodFlag = "";
var boTSI = TheApplication().GetBusObject("Time Sheet Item No Link") ; //modified by LU871 as part of CQ 12500
var bcUnassoc = boTSI.GetBusComp("Time Sheet Unassoc Daily Hours No Link");//modified by LU871 as part of CQ 12500
var bcTS = TheApplication().GetBusObject("Time Sheet").GetBusComp("Time Sheet");
with (bcUnassoc)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sTTId) ;
ExecuteQuery(ForwardOnly)
if (FirstRecord())
{
ActivateField("Owner Id") ;
ActivateField("Item Date") ;
ActivateField("Time Sheet Daily Line Id") ;
var sOwnerId = GetFieldValue("Owner Id") ;
var sItemDate = GetFieldValue("Item Date") ;
var boTS = TheApplication().GetBusObject("CMI TS Daily Line") ;
var bcDailyLine = boTS.GetBusComp("Time Sheet Daily Line") ;
with(bcDailyLine)
{
ActivateField("Time Sheet Owner Id") ;
ActivateField("Time Sheet Line Date") ;
ActivateField("Time Sheet Id");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Time Sheet Owner Id", sOwnerId) ;
SetSearchSpec("Time Sheet Line Date", sItemDate) ;
ExecuteQuery(ForwardOnly)
if (FirstRecord())
{
sTSLId = GetFieldValue("Id");
//Getting the Time Sheet Id
sTSId = GetFieldValue("Time Sheet Id");
}
}
//Getting Closed flag of the period
with(bcTS)
{
ActivateField("Closed Flag");
ActivateField("Id");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sTSId) ;
ExecuteQuery(ForwardOnly)
if (FirstRecord())
{
sPeriodFlag = GetFieldValue("Closed Flag");
}
}
if(sPeriodFlag== "N")
{
SetFieldValue("Time Sheet Daily Line Id", sTSLId) ;
WriteRecord() ;
}
else
sErr = "Period is closed. You are not allowed to make any changes to time entries.";
} //end-if
} //end-with
}//end-try
catch(e){
throw(e);
}
finally {
if(defined(bcUnassoc)) bcUnassoc = null ;
if(defined(boTSI)) boTSI = null ;
if(defined(bcDailyLine)) bcDailyLine = null ;
if(defined(bcTS)) bcTS = null;
if(defined(boTS)) boTS = null ;
}
}

CMI Time Tracker BS
(declarations)
var sErr = "";

CMI Time Tracker BS
ClosePeriodActivity
function ClosePeriodActivity(sPeriodId)
{
try
{
var boTSI = TheApplication().GetBusObject("CMI Time Sheet Items List") ;
var bcTSI = boTSI.GetBusComp("CMI Time Sheet Items");
var bcAction = TheApplication().GetBusObject("Action No Link").GetBusComp("Action No Link");
var sSearchExpr = "([CMI Activity Category] = 'Admin' OR [CMI Activity Category] = 'Training' OR [CMI Activity Category] = 'Supervision' OR [CMI Activity Category] = 'Unpaid Benefits' OR [CMI Activity Category] = 'Benefits Paid') AND [Time Sheet Period Id]='" +sPeriodId+ "'";
var sActId = "" ;
var sActCategory = "" ;
with (bcTSI)
{
ActivateField("Activity Id") ;
ActivateField("Time Sheet Period Id") ;
ActivateField("CMI Activity Category") ;
SetViewMode(AllView);
ClearToQuery();
//SetSearchSpec("Time Sheet Period Id", sPeriodId) ;
SetSearchExpr(sSearchExpr) ;
ExecuteQuery(ForwardOnly) ;
var isRecord = FirstRecord() ;
//TheApplication().RaiseErrorText("Error First Rec Not Found");
while(isRecord)
{
sActId = GetFieldValue("Activity Id") ;
if(sActId == "" || sActId == null) sActId = "CMINOACTID";
sActCategory = GetFieldValue("CMI Activity Category") ;
bcAction = TheApplication().GetBusObject("Action").GetBusComp("Action");
//bcAction = TheApplication().GetBusObject("Action No Link").GetBusComp("Action No Link");
//TheApplication().RaiseErrorText("Error");
try
{
with(bcAction)
{
ActivateField("Status");
InvokeMethod("SetAdminMode", "TRUE") ;
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sActId) ;
ExecuteQuery(ForwardOnly) ;
if(FirstRecord())
{
SetFieldValue("Status", "Completed") ;
WriteRecord() ; //retaining this statement as In-progrss to Done throws state transition error as Act should be completed first
//TheApplication().RaiseErrorText("Error 1"+ sActId);
if(sActCategory == "Benefits Paid" || sActCategory == "Unpaid Benefits")
{
SetFieldValue("Done Flag", "Y") ;
//SetFieldValue("Done", new Date()) ; - system sets it when done flag is set
SetFieldValue("Status", "Done") ;
WriteRecord() ;
//TheApplication().RaiseErrorText("Error 2"+ sActId);
}
//WriteRecord(); //RM - move the WriteRecocrd event here to fix the RTE issue - 10/14/2013
//Commented again //LQ305 - as two writes are needed for each state commit (completed then done)
}
}//end-with
}
catch(e)
{
//suppressing error on post activity update for completed status
}
finally
{
bcAction = null ;
isRecord=NextRecord();
}
}//end-while
}//end-with
}//end-try
catch(e){
throw(e);
}
finally {
if(defined(bcTSI)) bcTSI = null ;
if(defined(boTSI)) boTSI = null ;
if(defined(bcAction)) bcAction = null ;
}
}

CMI Time Tracker BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if(MethodName == "CMIAssignTT")
{
var sTTId = Inputs.GetProperty("TimeTrackerId") ;
CMIAssignTT(sTTId) ;
Outputs.SetProperty("Error",sErr);
return (CancelOperation);
}
if(MethodName == "ClosePeriodActivity")
{
var sPeriodId = Inputs.GetProperty("PeriodId") ;
ClosePeriodActivity(sPeriodId) ;
return (CancelOperation);
}
return (ContinueOperation);
}

CMI Time Tracker Split
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if(MethodName == "TTTracker")
{
TTTracker(Inputs, Outputs);
return (CancelOperation);
}
}
catch(e)
{
//throw e;
}
return (ContinueOperation);
}

CMI Time Tracker Split
TTTracker
function TTTracker(Inputs, Outputs)
{
/*************************************************************************************
Created to split Time tracker activity in case the time tracker entry proceeds
to the next day without ending then we have one time tracker for thae day from start time to 11:59
and another for the next day starting from 0:00.Created by LU871 for release R1.2 on 29.06.2013
//Updated by lq305
***************************************************************************************/
try
{
var CMIActionBO= TheApplication().GetBusObject("Time Sheet Daily Hours");
var CMIActionBC = CMIActionBO.GetBusComp("Time Sheet Daily Hours");
with (CMIActionBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",Inputs.GetProperty("TTId")) ;
ExecuteQuery(ForwardOnly)
if (FirstRecord())
{
ActivateField("Activity Id");
ActivateField("Service Request Id");
ActivateField("Start Time");
ActivateField("End Time");
ActivateField("Item Date");
ActivateField("Project");
var CMIEndtime=GetFieldValue("End Time");
var CMIStartTime=GetFieldValue("Start Time");
var CMIActivity=GetFieldValue("Activity Id");
var CMIITemDate=GetFieldValue("Item Date");
var CMISR=GetFieldValue("Service Request Id");
if(CMIActivity != null)
{
{
SetFieldValue("End Time","23:59:00");
WriteRecord();
TheApplication().SetProfileAttr("TTSplit", "N");
NewRecord(NewAfterCopy);
var dtChar = (ToInteger(new Date().getMonth()) + 1) + "/" + new Date().getDate() + "/" + (ToInteger(new Date().getYear())+1900) ;
SetFieldValue("Item Date", dtChar);
SetFieldValue("Start Time", "00:00:00");
SetFieldValue("End Time", "");
SetFieldValue("Service Request Id", CMISR);
SetFieldValue("Activity Id", CMIActivity);
WriteRecord();
TheApplication().SetProfileAttr("TTSplit", "Y");
}
}
}//end-if
}//end-with
}
catch(e)
{
//throw(e) ;
}
finally
{
if(defined(CMIActionBC))
CMIActionBO = null ;
if(defined(CMIActionBO))
CMIActionBO = null ;
}
}

CMI Trunk Inventory Validation
CreateTempInventory
function CreateTempInventory(Inputs, Outputs)
{
try {
TheApplication().Utility.logStack("CreateTempInventory", this);
var oInvLocMgmtBO:BusObject = TheApplication().GetBusObject("FS Inventory Location Mgmt");
var oInvLocMgmtBC:BusComp = oInvLocMgmtBO.GetBusComp("FS Inventory Location");
var sInvoType = TheApplication().InvokeMethod("LookupValue", "FS_INVLOCTYPE_TYPE", "Trunk");
var sPostionId = "";
var found = false;
var positionSource = "Active User";
var sInvId;
var boActive:BusObject = TheApplication().ActiveBusObject();
var bcActive:BusComp
//OOTB class level validation when a new record is created checks that owner of parent activity has
//Inventory record. So check that one exists and create one if not to skip possible validation error
//This Temp inventory record will be deleted and replaced on new record
if (boActive != null && boActive.Name() == "Action") {
bcActive = boActive.GetBusComp("Action");
sPostionId= bcActive.GetFieldValue("CMI Owner Primary Position Id");
positionSource = "Activity Owner";
} else {
sPostionId= TheApplication().PositionId();
}
with(oInvLocMgmtBC) {
ActivateField("Primary Position ID");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Primary Position ID", sPostionId);
SetSearchSpec("Inventory Type", sInvoType);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logStep(sInvoType+" for position of "+positionSource+" ("+sPostionId+") Found? "+found);
if(found==false) {
NewRecord(NewAfter);
SetFieldValue("Inventory Type", sInvoType);
SetFieldValue("Inventory Name", "tempInv "+sPostionId);
//Sales team will default to the logged in user. If activity owner is different, need to add
//activity position to Inventory role. The Active User position must also be present in order
//for the location to pass the picklist visibility
if (sPostionId != TheApplication().PositionId()) {
var bcMVG = GetMVGBusComp("Sales Team");
var bcAssoc = bcMVG.GetAssocBusComp();
with (bcAssoc) {
ClearToQuery();
SetSearchSpec("Id", sPostionId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Associated Position Found?", found);
if (found) {
Associate(NewAfter);
//Make the activity owner position the primary as this is what is used in the vanilla validation
oInvLocMgmtBC.SetFieldValue("Primary Position ID", sPostionId);
}
}
}
WriteRecord();
sInvId = GetFieldValue("Id");
} else {
//MJB added to assist in deletion of bad inventory records once created
var invName = GetFieldValue("Inventory Name");
TheApplication().Utility.logVars("Inventory Name ("+GetFieldValue("Id")+")", invName);
if (invName.indexOf("tempInv") == 0) sInvId = GetFieldValue("Id");
}
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
bcActive = null;
boActive = null;
bcAssoc = null;
bcMVG = null;
oInvLocMgmtBO = null;
oInvLocMgmtBC = null;
Outputs.SetProperty("Inventory Id", sInvId);
TheApplication().Utility.logUnstack(sInvId);
}
}

CMI Trunk Inventory Validation
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retValue = CancelOperation;
var oNewInvLocMgmtBO:BusObject = TheApplication().GetBusObject("FS Inventory Location Mgmt");
var oNewInvLocMgmtBC:BusComp = oNewInvLocMgmtBO.GetBusComp("FS Inventory Location");
var oInvMgmtBO:BusObject = TheApplication().GetBusObject("FS Inventory Location Mgmt");
var oInvTypeBC:BusComp = oInvMgmtBO.GetBusComp("FS InvLoc PickList Type");
var oInvLocRoleBC:BusComp = oInvMgmtBO.GetBusComp("CMI FS Inventory Location Roles");
var sPostionId= TheApplication().PositionId();
switch (MethodName) {
case "PreNewRecord":
CreateTempInventory(Inputs, Outputs);
break;
case "NewRecord":
var sInvId = Inputs.GetProperty("Inventory Id");
with(oNewInvLocMgmtBC) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sInvId);
ExecuteQuery(ForwardOnly);
TheApplication().Utility.logVars("Temp Inventory ("+sInvId+") Found?", FirstRecord());
if(FirstRecord()) {
DeleteRecord();
}
}
var sInvTypeId:String;
var sNewInvoType = TheApplication().InvokeMethod("LookupValue", "FS_INVLOCTYPE_TYPE", "Trunk");
var sCount:Number;
var sInventId:String;
with(oInvTypeBC) {
SetViewMode(AllView);
ActivateField("Inventory Location Type");
ClearToQuery();
SetSearchSpec("Inventory Location Type",sNewInvoType);
ExecuteQuery(ForwardOnly);
var iRecord1 = FirstRecord();
TheApplication().Utility.logVars(sNewInvoType+" Inventory Found?", iRecord1);
if (iRecord1) {
sInvTypeId = GetFieldValue("Id");
}
}
if (sInvTypeId != null && sInvTypeId != "") {
with(oInvLocRoleBC) {
SetViewMode(AllView);
ActivateField("Inventory Location ID");
ActivateField("Position ID");
ActivateField("CMI Inventory Type Id");
ClearToQuery();
SetSearchSpec("Position ID", sPostionId);
SetSearchSpec("CMI Inventory Type Id",sInvTypeId);
// SetSearchSpec("CMI Inventory Type",sNewInvoType);
ExecuteQuery(ForwardBackward);
var iRecord = FirstRecord();
TheApplication().Utility.logStep(sNewInvoType+" for position ("+sPostionId+") Found? "+iRecord);
if (iRecord) {
sCount = CountRecords();
if (sCount == 1) {
sInventId = GetFieldValue("Inventory Location ID");
}
}
Outputs.SetProperty("Inventory Id", sInventId);
Outputs.SetProperty("Count", sCount);
}
}
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
oNewInvLocMgmtBO = null;
oNewInvLocMgmtBC = null;
oInvMgmtBO = null;
oInvTypeBC = null;
oInvLocRoleBC = null;
TheApplication().Utility.logUnstack(retValue);
}
return (retValue);
}

CMI Update Activity From Quote
(declarations)
/*Global Variables*/
var sSRId;
var sQuoteId;

CMI Update Activity From Quote
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if (MethodName == "CreateActivity")
{
sSRId = TheApplication().GetProfileAttr("PartSRId");
sQuoteId = TheApplication().GetProfileAttr("Quote Id");
CreateActivityQuote(sSRId,sQuoteId);
return(CancelOperation);
}
}
catch(e)
{
throw e;
}
return (ContinueOperation);
}

CMI Update Activity From Quote
CreateActivityQuote
function CreateActivityQuote(sSRId,sQuoteId)
{
/*******************************************************************************************
Created By : <JQ487>
Created On : <08/03/2011>
Method Name: CreateActivity
C&I Number: 4467
Requirement #: Enhancement s124
Functionality: this Bs will Query in Action BC for following rules
Action.Quote Id <> Quote.Id
Action. Service Request Id = Quote.Service Request Id
Action.CMI Quote Number = Quote.Quote Number
Action.Quote Status <> Cancelled and Lost and Alternate Quote Selected
if all conditions satisfy we map Quote id from Quote Accepted quote to Activity
****************************************************************************************** */
try
{
var oBO:BusObject = TheApplication().ActiveBusObject();
var oBCQuote:BusComp = oBO.GetBusComp("Quote");
var oBOAction:BusObject = TheApplication().GetBusObject("Action");
var oBCAction:BusComp = oBOAction.GetBusComp("Action");
var sSta:String = TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Lost");
var sSta1:String = TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Cancelled");
var sSta2:String = TheApplication().InvokeMethod("LookupValue","QUOTE_STATUS","Alternate Quote Selected");
var isQuoteRec:Boolean;
var isActRec:Boolean;
//var sQuoteNum = GetFieldValue("Quote Number");
//Query Quote BC for Quote number
with(oBCQuote)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id",sQuoteId);
ExecuteQuery(ForwardBackward);
isQuoteRec = FirstRecord();
if(isQuoteRec)
{
var sQuoteNum = GetFieldValue("Quote Number");
}
}//end with(oBCQuote)
//Query in Action BC with Quote Number and SR id
with(oBCAction)
{
SetViewMode(AllView);
ActivateField("Quote Id")
ActivateField("CMI Quote Status");
ActivateField("Activity SR Id");
ActivateField("CMI Quote Number");
ClearToQuery();
SetSearchSpec("Activity SR Id",sSRId);
SetSearchSpec("CMI Quote Number", sQuoteNum);
ExecuteQuery(ForwardOnly);
var sCount = CountRecords();
isActRec = FirstRecord();
while(isActRec != false)
{
var sQid = GetFieldValue("Quote Id");
var sQuoteSta:String = GetFieldValue("CMI Quote Status");
if((sQuoteSta != sSta) && (sQuoteSta != sSta1) && (sQuoteSta != sSta2))
{
if(sQid != sQuoteId)
{
SetFieldValue("Quote Id", sQuoteId);
}
}
isActRec = NextRecord();
}
WriteRecord();
}//end with(oBCAction)
}//end 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
{
oBCQuote = null;
oBO = null;
oBCAction = null;
oBOAction = null;
}
}

CMI Update Discount Percent
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*********************************************************
AUTHOR: Shyamal Nath
DESCRIPTION:
INPUTS:
OUTPUTS:
DATE CREATED:
UPDATES:
*********************************************************/
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);
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();
}
}
/*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
catch(e)
{
throw(e);
}
finally
{
iLineItem1 = null;
bcQuoteItemWarranty = null;
bcQuoteItem = null;
boQuote = null;
oBCQI = null;
oBC = null;
oBO = null;
//added by shanmukh for code clean up 08/27/2011
obc = null;
obo = null;
sIP = null;
sOP = null;
sBS = null;
}
}

CMI Update Order LI Line Type BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
switch(MethodName) {
case "UpdateLineType":
UpdateLineType(Inputs,Outputs);
break;
case "UpdateSROrderShipToAddress":
UpdateSROrderShipToAddress();
break;
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Update Order LI Line Type BS
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
Input:
Output:
****************************************************************************************** */
function UpdateLineType(Inputs,Outputs)
{
try{
TheApplication().Utility.logStack("UpdateLineType", this);
var sOrderId = Inputs.GetProperty("OrderId");
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 bcOrderAction:BusComp;
var bcAssocOrder:BusComp;
var oQuoteBO:BusObject;
var oActionBC:BusComp;
var SOLCo = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Order Line Component"); //LOV name corrected by KM326 on 25/11/2011 for bug 633
var SOLCh = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Order Line Charges"); //LOV name corrected by KM326 on 25/11/2011 for bug 633
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 sOverhual = TheApplication().InvokeMethod("LookupValue", "CMI_SR_SUB_TYPE_CATEGORY", "Overhaul");//C&I 4657 Enhancement# S138
var sRebuild = TheApplication().InvokeMethod("LookupValue", "CMI_SR_SUB_TYPE_CATEGORY", "Remanufacture");//C&I 4657 Enhancement# S138
var sRbtMain = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Rebuild Assembly");//C&I 4657 Enhancement# S138
var sRbtMaterial = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Rebuild Material");//C&I 4657 Enhancement# S138
var sRbtResource = TheApplication().InvokeMethod("LookupValue", "CMI_LINE_TYPE", "Service Rebuild Resource");//C&I 4657 Enhancement# S138
var sSRId = "";
var sQuoteId = "";
var sQuoteNum:String = "";//<CMI DBU><CQ Def: DBUNG00001449><Added New Variable Declartion><By JQ486 on 29th Aug 2011>
var sWriteInIdentifier="";//KM330 for defect 592
var found;
with(bcOrder) {
ActivateField("CMI IsRebuild");
ActivateField("Service Request Id");
ActivateField("Quote Id");
ActivateField("Quote Number");//<CMI DBU><CQ Def: DBUNG00001449><By JQ486 on 29th Aug 2011>
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sOrderId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Order ("+sOrderId+") found?", found);
if(found) {
var sIsRebuild = GetFieldValue("CMI IsRebuild");
sSRId = GetFieldValue("Service Request Id");
sQuoteId = GetFieldValue("Quote Id");
sQuoteNum = GetFieldValue("Quote Number");//<CMI DBU><CQ Def: DBUNG00001449><By JQ486 on 29th Aug 2011>
with(bcOrderItem) {
ActivateField("CMI Main Assembly Flag");
ActivateField("Product Type");
ActivateField("CMI Line Type");
ActivateField("CMI Write In Identifier");//KM330 for defect592
SetViewMode(AllView);
ClearToQuery();
// SetSearchSpec("Order Header Id", sOrderId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("First Order Line found?", found);
while(found) {
//C&I 4657 Enhancement# S138
var sProdType = GetFieldValue("Product Type");
var sMainAssembly = GetFieldValue("CMI Main Assembly Flag");
var sLIType = GetFieldValue("CMI Line Type");
sWriteInIdentifier = GetFieldValue("CMI Write In Identifier");//KM330 for defect 592
TheApplication().Utility.logVars("Rebuild", sIsRebuild);
if(sIsRebuild=="Y") {//Rebuild process
TheApplication().Utility.logVars("Product Type/Main Assembly", sProdType+"/"+sMainAssembly);
if (sProdType == "Misc" || sProdType == "Labor") {
SetFieldValue("CMI Line Type", sRbtResource);
} else if(sMainAssembly == "Y") {
SetFieldValue("CMI Line Type", sRbtMain);
} else {
TheApplication().Utility.logVars("Line Type/Write In", sLIType+"/"+sWriteInIdentifier);
if((sLIType == null) || (sLIType == "") || (sWriteInIdentifier == "Yes")) {
SetFieldValue("CMI Line Type", sRbtMaterial);
}
}
} else {
TheApplication().Utility.logVars("Product Type/Write In", sProdType+"/"+sWriteInIdentifier);
if ((sProdType == "Misc") || (sProdType == "Labor")) {
if(sWriteInIdentifier == "Yes") {
SetFieldValue("CMI Line Type", SOLCo);
} else {
SetFieldValue("CMI Line Type", SOLCh);
}
} else {
TheApplication().Utility.logVars("Line Type", sLIType);
if((sLIType == null) || (sLIType == "") || (sWriteInIdentifier == "Yes")) {
SetFieldValue("CMI Line Type", SOLCo);
}
}
}//End C&I 4657 Enhancement# S138
WriteRecord();
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)");
// oActionBC = oQuoteBO.GetBusComp("Action");
bcOrderAction = boOrder.GetBusComp("Order Activities");
var completed = TheApplication().InvokeMethod("LookupValue", "EVENT_STATUS", "Completed");
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 sActStatus:String;
var sActType;
with(oActionBC) {
ActivateField("Order Id");
ActivateField("Type");
// ActivateField("CMI Status");
ActivateField("Status");
ActivateField("Price 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.logVars("Activity Type", 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("Current Unbounded 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("Pricing", GetFieldValue("Price List"));
InvokeMethod("RefreshRecord");
InvokeMethod("CompleteActivity");
// } else {
// WriteRecord();
}
found = NextRecord();
}
}
}//end if
}//end (bcOrder)
} catch(e){
Outputs.SetProperty("Error Code", "1");
Outputs.SetProperty("Error Message", "Error Detail:" +e.message);
TheApplication().Utility.RaiseError(e);
} finally {
bcOrderAction = null;
bcAssocOrder = null;
bcOrderItem = null;
bcOrder = null;
boOrder = null;
oActionBC = null;
oQuoteBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Update Order LI Line Type BS
UpdateSROrderShipToAddress
/*************************************************************************************************************************
Created By : ix964
Created On : 24-Feb-11
Method Name:
Functionality:
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function UpdateSROrderShipToAddress()
{
try {
TheApplication().Utility.logStack("UpdateSROrderShipToAddress", this);
var sSRId = TheApplication().GetProfileAttr("UpdateSROrderShipToAddressSRId");
var oSRBO:BusObject = TheApplication().GetBusObject("Service Request");
var oSRBC:BusComp = oSRBO.GetBusComp("Service Request");
var oOrderBC:BusComp = oSRBO.GetBusComp("Order Entry - Orders");
var oBCAddress:BusComp;
var found;
with(oSRBC) {
SetViewMode(AllView);
ActivateField("CMI Service Location Address Id");
ClearToQuery();
SetSearchSpec("Id", sSRId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Service Request ("+sSRId+") found?", found);
if(found) {
var sAddressId = GetFieldValue("CMI Service Location Address Id");
with(oOrderBC) {
SetViewMode(AllView);
ActivateField("Service Request Id");
ActivateField("CMI Ship To Profile Name");
ClearToQuery();
SetSearchSpec("Service Request Id", sSRId);
ExecuteQuery(ForwardOnly);
var haveRecord = FirstRecord();
TheApplication().Utility.logVars("First Order found?", haveRecord);
while(haveRecord) {
oBCAddress = GetPicklistBusComp("CMI Ship To Profile Name");
with (oBCAddress) {
ClearToQuery();
SetSearchSpec("Id", sAddressId);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) Pick();
}
oBCAddress = null;
WriteRecord();
haveRecord = NextRecord();
}
}
}
}//end with(oSRBC)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCAddress = null;
oOrderBC = null;
oSRBC = null;
oSRBO = null;
TheApplication().Utility.logUnstack();
}
}//end func

CMI Update Parts Labor On Order Line Items BS
UpdateLaborOnOrder
function UpdateLaborOnOrder(boAction, bcAction, boOrder, bcOrder, Inputs,Outputs)
{
/*************************************************************************************************************************
Created By : ix964
Created On : 21-Dec-10
Method Name:
Functionality:
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
try{
TheApplication().Utility.logStack("UpdateLaborOnOrder", this);
var bcActionLabor = boAction.GetBusComp("Time Sheet Daily Hours");
var bcOrderItem = boOrder.GetBusComp("Order Entry - Line Items");
var sQuoteNumber = Inputs.GetProperty("QuoteNumber");
var sOrderId = Inputs.GetProperty("OrderId");
var sTotalDistance = 0;
var sDistance = 0;
var hasLaborActivity = true;
while(hasLaborActivity) {
with(bcActionLabor) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("Start Time");
ActivateField("End Time");
ActivateField("Project");//Activate Field, JQ486 on 23 Sep 2011.
ActivateField("CMI Distance");
SetSearchSpec("End Time", "IS NOT NULL");
SetSearchSpec("Start Time", "IS NOT NULL");
SetSearchSpec("Project", "Travel");
ExecuteQuery(ForwardBackward); //Change to forwardbackward to insure unique product records
var HasLabor = FirstRecord();
TheApplication().Utility.logVars("1st Labor Item found", HasLabor);
while(HasLabor) {
sDistance += ToNumber(GetFieldValue("CMI Distance"));
HasLabor = NextRecord();
}//end while(HasLabor)
}// end with(bcActionLabor)
sTotalDistance = sTotalDistance + sDistance;
hasLaborActivity = NextRecord();
}//end while(hasLaborActivity)
var sMileage = "Mileage";
var sMileageProdId = GetLaborProdId(sMileage);
TheApplication().Utility.logVars("Total Distance", sTotalDistance);
if (sTotalDistance != 0) {
with(bcOrderItem) {
//==========================Mileage=========================
NewRecord(NewAfter);
SetFieldValue("Order Header Id", sOrderId);
bcPickProduct = GetPicklistBusComp("Product");
with(bcPickProduct) {
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Id", sMileageProdId);
ExecuteQuery(ForwardOnly);
if(FirstRecord()) Pick();
}
SetFieldValue("Quantity Requested", sTotalDistance);
SetFieldValue("CMI Quantity Quoted", 0);
SetFieldValue("CMI Actual Quantity", sTotalDistance);
WriteRecord();
} //end with(bcOrderItem)
}//end if (sTotalDistance != 0)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcPickProduct = null;
bcOrderItem = null;
bcActionLabor = null;
TheApplication().Utility.logUnstack();
}
}

CMI Update Parts Labor On Order Line Items BS
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 UpdateLineType(boOrder, bcOrder, Inputs,Outputs) {
try {
TheApplication().Utility.logStack("UpdateLineType", this);
var sOrderId = Inputs.GetProperty("OrderId");
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;
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(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("First Order Line found?", found);
while(found) {
//C&I 4657 Enhancement# S138
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();
}
if (sActType == partsTracker) {
UpdatePartsOnOrder(oQuoteBO, oActionBC, boOrder, bcOrder, Inputs, Outputs);
}
found = NextRecord();
}
}
} catch(e){
Outputs.SetProperty("Error Code", "1");
Outputs.SetProperty("Error Message", "Error Detail:" +e.message);
TheApplication().Utility.RaiseError(e);
} finally {
bcOrderAction = null;
bcAssocOrder = null;
bcOrderItem = null;
oActionBC = null;
oQuoteBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Update Parts Labor On Order Line Items BS
UpdateOrderItem
function UpdateOrderItem(Inp, Out, bcOrderItem)
{
/*************************************************************************************************************************
Created By : ix964
Created On : 21-Dec-10
Method Name:
Functionality:
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
try
{
TheApplication().Utility.logStack("UpdateOrderItem", this);
var sProductId = Inp.GetProperty("ProductId");
var sUsedQuantity = Inp.GetProperty("UsedQuantity");
var sSerialNumber = Inp.GetProperty("SerialNumber");
var sInventoryId = Inp.GetProperty("InventoryId");
var partTrkReturn = Inp.GetProperty("CMIReturn");
var sReturnQty = Inp.GetProperty("CMIReturnQuantity");
var sQuoteQty = Inp.GetProperty("CMIQuoteQty");
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] = '" + sProductId + "' AND [CMI Actual Quantity] = '" + sZERO + "' AND [Parent Order Item Id] IS NULL";
//AND [CMI Serial Number] IS NULL";// Commented by JQ487 on 07/28/2011 for fixing rebuild defect
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", sUsedQuantity);
SetFieldValue("Extended Quantity Requested", sUsedQuantity);
SetFieldValue("CMI Actual Quantity", sUsedQuantity);
SetFieldValue("CMI Return", partTrkReturn);
SetFieldValue("Source Inventory Loc Id", sInventoryId);
SetFieldValue("Destination Inventory Loc Id", ""); //Jq487: added for fixing defect 833
SetFieldValue("CMI Quantity Quoted", sQuoteQty);//By JQ487: for fixing defect 4827, 4831
TheApplication().Utility.logVars("Serial #", sSerialNumber);
if (sSerialNumber != "") {
SetFieldValue("CMI Serial Number", sSerialNumber);
}
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] = '"+sProductId+"') 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 {
ProcessDependentLines(bcOrderItem, sLineType, sInventoryId, mainAssembly,
covMainAsby, sUsedQuantity, sReturnQty, sQuoteQty);
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;
var priceListId = Inp.GetProperty("PriceListId");
var rebuild = Inp.GetProperty("Rebuild");
TheApplication().Utility.logVars("Price List Id", priceListId);
if(priceListId != "" && priceListId != null) {
var sOut = TheApplication().NewPropertySet();
GetPriceList(priceListId, sProductId, sOut);
cost = sOut.GetProperty("Cost");
price = sOut.GetProperty("Price");
}
NewRecord(NewAfter);//crate new line item
SetFieldValue("CMI Serial Number", sSerialNumber);
SetFieldValue("Quantity Requested", sUsedQuantity);
SetFieldValue("Extended Quantity Requested", sUsedQuantity);
SetFieldValue("CMI Actual Quantity", sUsedQuantity);
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", sInventoryId);
var bcPickProduct:BusComp = GetPicklistBusComp("Product");
with(bcPickProduct) {
SetViewMode(AllView);
ActivateField("CMI Return");
ClearToQuery();
SetSearchSpec("Id", sProductId);
ExecuteQuery(ForwardBackward);
var haveProduct = FirstRecord();
TheApplication().Utility.logVars("Product Found?", haveProduct);
if(haveProduct) {
returnType = GetFieldValue("CMI Return");
Pick();
}
}//end with
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", Inp.GetProperty("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 {
ProcessDependentLines(bcOrderItem, sLineType, sInventoryId, "", "",
sUsedQuantity, sReturnQty, sQuoteQty);
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 Update Parts Labor On Order Line Items BS
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 UpdatePartsOnOrder(boAction, bcAction, boOrder, bcOrder, Inputs, Outputs) {
try {
TheApplication().Utility.logStack("UpdatePartsOnOrder", this);
var bcActionParts = boAction.GetBusComp("FS Activity Parts Movement");
var bcOrderItem = boOrder.GetBusComp("Order Entry - Line Items (Simple)");
var sOrderId = Inputs.GetProperty("OrderId");
var Inp;
var Out;
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");
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"));
Inp = TheApplication().NewPropertySet();
Out = TheApplication().NewPropertySet();
Inp.SetProperty("OrderId", sOrderId);
Inp.SetProperty("ProductId", sProductId);
Inp.SetProperty("UsedQuantity", ToNumber(GetFieldValue("Used Quantity")));
Inp.SetProperty("InventoryId",GetFieldValue("Trunk Invloc Id"));
Inp.SetProperty("SerialNumber", GetFieldValue("Write In Serial Number"));
Inp.SetProperty("CMIReturn", GetFieldValue("CMI Return"));
Inp.SetProperty("CMIReturnQuantity", GetFieldValue("CMI Return Quantity"));
Inp.SetProperty("CMIQuoteQty", GetFieldValue("CMI Quoted Quantity"));
Inp.SetProperty("PriceListId", bcOrder.GetFieldValue("Price List Id"));
Inp.SetProperty("Rebuild", bcOrder.GetFieldValue("CMI IsRebuild"));
UpdateOrderItem(Inp, Out, bcOrderItem);
bHasPartsMove = NextRecord();
}// end while(bHasPartsMove)
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
Inp = null;
Out = null;
bcOrderItem = null;
bcActionParts=null;
TheApplication().Utility.logUnstack();
}
}//end function

CMI Update Parts Labor On Order Line Items BS
UpdateSROrderShipToAddress
/*************************************************************************************************************************
Created By : ix964
Created On : 24-Feb-11
Method Name:
Functionality:
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function UpdateSROrderShipToAddress() {
try {
TheApplication().Utility.logStack("UpdateSROrderShipToAddress", this);
var sSRId = TheApplication().GetProfileAttr("UpdateSROrderShipToAddressSRId");
var oSRBO:BusObject = TheApplication().GetBusObject("Service Request");
var oSRBC:BusComp = oSRBO.GetBusComp("Service Request");
var oOrderBC:BusComp = oSRBO.GetBusComp("Order Entry - Orders");
var oBCAddress:BusComp;
var found;
with(oSRBC) {
SetViewMode(AllView);
ActivateField("CMI Service Location Address Id");
ClearToQuery();
SetSearchSpec("Id", sSRId);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
TheApplication().Utility.logVars("Service Request ("+sSRId+") found?", found);
if(found) {
var sAddressId = GetFieldValue("CMI Service Location Address Id");
with(oOrderBC) {
SetViewMode(AllView);
ActivateField("Service Request Id");
ActivateField("CMI Ship To Profile Name");
ClearToQuery();
SetSearchSpec("Service Request Id", sSRId);
ExecuteQuery(ForwardOnly);
var haveRecord = FirstRecord();
TheApplication().Utility.logVars("First Order found?", haveRecord);
while(haveRecord) {
oBCAddress = GetPicklistBusComp("CMI Ship To Profile Name");
with (oBCAddress) {
ClearToQuery();
SetSearchSpec("Id", sAddressId);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) Pick();
}
oBCAddress = null;
WriteRecord();
haveRecord = NextRecord();
}
}
}
}//end with(oSRBC)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oBCAddress = null;
oOrderBC = null;
oSRBC = null;
oSRBO = null;
TheApplication().Utility.logUnstack();
}
}//end func

CMI Update Parts Labor On Order Line Items BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
/*************************************************************************************************************************
Created By : ix964
Created On : 31-Dec-10
Method Name:
Functionality:
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
//Try-catch added as part of Code cleanup activity by JW919 on 08/22/2011
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
var boOrder:BusObject = TheApplication().GetBusObject("Order Entry (Sales)");
var bcOrder:BusComp = boOrder.GetBusComp("Order Entry - Orders");
var boAction = TheApplication().GetBusObject("Action");
var bcAction = boAction.GetBusComp("Action");
var found = false;
var sOrderId = Inputs.GetProperty("OrderId");
var partsTracker = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Parts Tracker");
var serviceLabor = TheApplication().InvokeMethod("LookupValue", "TODO_TYPE", "Service Labor");
switch(MethodName) {
case "UpdateLineType":
case "UpdateOrderLineItem":
found = InstantiateOrder(sOrderId, boOrder, bcOrder);
if(found) {
//Within UpdateLineType function is a call to process Parts Tracker
UpdateLineType(boOrder, bcOrder, Inputs,Outputs);
}
break;
case "UpdateSROrderShipToAddress":
UpdateSROrderShipToAddress();
break;
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
bcAction=null;
boAction=null;
bcOrder = null;
boOrder = null;
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Update Parts Labor On Order Line Items BS
ProcessDependentLines
function ProcessDependentLines(bcOrderItem, sLineType, sInventoryId, mainAssembly, covMainAsby, sUsedQuantity, sReturnQty, sQuoteQty) {
try {
TheApplication().Utility.logStack("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 Update Parts Labor On Order Line Items BS
(declarations)
var bcPickProduct;//added, jq486,23 sep 2011, defect 104, 182.

CMI Update Parts Labor On Order Line Items BS
GetLaborProdId
function GetLaborProdId(sLaborProductName)
/*************************************************************************************************************************
Created By : ix964
Created On : 21-Dec-10
Method Name:
Functionality:
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
{
try
{
var boProduct = TheApplication().GetBusObject("Internal Product");
var bcProduct = boProduct.GetBusComp("Internal Product");
var sProductId = "";
with(bcProduct)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Name",sLaborProductName);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
sProductId = GetFieldValue("Id");
}
}// end with
}
catch(e)
{
TheApplication().RaiseErrorText("Exception raised in BS:"+this.Name()+". Exception:"+e.toString());
}
finally
{
bcProduct = null;
boProduct = null;
}
return(sProductId);
}

CMI Update Parts Labor On Order Line Items BS
GetPriceList
function 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("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 Update Parts Labor On Order Line Items BS
InstantiateActivity
function InstantiateActivity(sOrderId, boAction, bcAction, activityType)
{
try {
TheApplication().Utility.logStack("InstantiateActivity", this);
TheApplication().Utility.logVars("Type", activityType);
var found;
with(bcAction) {
ActivateField("Order Id");
ActivateField("Type");
ActivateField("Status");
ActivateField("Price List");
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec("Order Id", sOrderId);
SetSearchSpec("Type", activityType);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(found);
}
return(found);
}

CMI Update Parts Labor On Order Line Items BS
InstantiateOrder
function InstantiateOrder(sOrderId, boOrder, bcOrder)
{
try {
TheApplication().Utility.logStack("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 Update Parts Labor On Order Line Items BS
ProcessLine
function ProcessLine(bcOrderItem, sIsRebuild)
{
try {
TheApplication().Utility.logStack("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 Update Promised Date
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
//CMI DBU Release# 1, Req# S001, C&I# 4462, Configuration: Created the new Method to update Promised date By JW919 on 12/04/11.
if(MethodName == "UpdatePromisedDate")
{
UpdatePromisedDate(Inputs, Outputs);
return (CancelOperation);
}
}
catch(e)
{
throw e;
}
return (ContinueOperation);
}

CMI Update Promised Date
UpdatePromisedDate
function UpdatePromisedDate(Inputs, Outputs)
{
/*******************************************************************************************
Created By : Deepak NK (JW919)
Created On : 2011-12-04
C&I Number : Req# S001, 4462
Functionality: Method fetches Ship Date from Promise Lines and
updates the promised date on Line item if there is only one Promise Line
**********************************************************************************************/
try
{
var vQuoteBo = TheApplication().GetBusObject("Quote");
var vPromiseBC = vQuoteBo.GetBusComp("Quote - Promised Schedule Lines");
var sQuoteId = Inputs.GetProperty("CMI Quote Item Id");
with(vPromiseBC)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("Available Date");
SetSearchSpec("Quote Item Id", sQuoteId);
ExecuteQuery(ForwardOnly);
var sHasRecord = FirstRecord();
var sCount = CountRecords();
Outputs.SetProperty("CMI Promised Lines Count", sCount);
Outputs.SetProperty("CMI Promised Date", "");
if(sHasRecord && sCount == 1)
{
var sPromisedDate = GetFieldValue("Available Date");
var vQLIBC = vQuoteBo.GetBusComp("Quote Item");
with(vQLIBC)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("CMI Promised Date");
SetSearchSpec("Id", sQuoteId);
ExecuteQuery(ForwardOnly);
if(FirstRecord())
{
SetFieldValue("CMI Promised Date", sPromisedDate);
WriteRecord();
Outputs.SetProperty("CMI Promised Date", sPromisedDate);
}
}
vQLIBC = null;
}
}
}
catch(e)
{
throw e;
}
finally
{
vPromiseBC = null;
vQuoteBo = null;
}
}

CMI Update Quote Item
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if (MethodName == "Execute")
{
UpdateQuoteData(Inputs, Outputs);
return (CancelOperation);
}
return (ContinueOperation);
}

CMI Update Quote Item
UpdateQuoteData
function UpdateQuoteData(Inputs, Outputs)
{
try{
var sQuoteId = Inputs.GetProperty("RowId");
var oQuoteBO = TheApplication().GetBusObject("Quote");
var oQuoteBC = oQuoteBO.GetBusComp("Quote");
var oQuoteItemBC = oQuoteBO.GetBusComp("Quote Item (Simple)");
var oQuoteItemBCMain = oQuoteBO.GetBusComp("Quote Item");
with (oQuoteBC)
{
//var sSearchExpr = "[Id] = '" + sQuoteId + "'";
SetViewMode(AllView);
SetSearchExpr("[Id] = '" + sQuoteId + "'");
ExecuteQuery(ForwardOnly);
if (FirstRecord())
{
var sSourceInventory = GetFieldValue("Source Inventory Location Id");
var sRootItemId = "";
var sParQItemId = "";
with (oQuoteItemBC)
{
//var sSearchExpr = "[Quote Id] = '" + sQuoteId + "' AND [Source Inventory Location Id] <> '" + sSourceInventory + "'";
var sSearchExpr = "[Quote Id] = '" + sQuoteId + "' AND [Source Inventory Location Id] IS NOT NULL";
ActivateField("Quote Id");
ActivateField("Source Inventory Location Id");
ActivateField("Root Quote Item Id");
ActivateField("Parent Quote Item Id");
ActivateField("CMI Root Source Inventory Id");
ActivateField("Unit Price");
SetSearchExpr(sSearchExpr);
ExecuteQuery(ForwardBackward);
var isRecord =FirstRecord();
while (isRecord)
{
sRootItemId = GetFieldValue("Root Quote Item Id");
sParQItemId = GetFieldValue("Parent Quote Item Id");
if (sParQItemId != "" && sParQItemId != null)
{
var sSourceRootInvId = GetFieldValue("CMI Root Source Inventory Id");
SetFieldValue("Source Inventory Location Id", sSourceRootInvId);
WriteRecord();
}
//LC657 CQ#12539
if (sParQItemId == sRootItemId)
{
SetFieldValue("Net Price", 0);
SetFieldValue("Unit Price", 0);
WriteRecord();
}
isRecord = NextRecord();
}
}
}
sRootItemId = "";
sParQItemId = "";
with (oQuoteItemBCMain)
{
//var sSearchExpr1 = "[Quote Id] = '" + sQuoteId + "' AND [Extended Quantity Requested] IS NOT NULL";
var sSearchExpr1 = "[Quote Id] = '" + sQuoteId + "'";
ActivateField("Extended Quantity Requested");
ActivateField("Extended Quantity");
ActivateField("Quote Id");
ActivateField("Root Quote Item Id");
ActivateField("Parent Quote Item Id");
SetSearchExpr(sSearchExpr1);
ExecuteQuery(ForwardBackward);
var isRecord1 =FirstRecord();
while (isRecord1)
{
sRootItemId = GetFieldValue("Root Quote Item Id");
sParQItemId = GetFieldValue("Parent Quote Item Id");
if (sParQItemId != "" && sParQItemId != null)
{
var sExtdQuantity = ToNumber(GetFieldValue("Extended Quantity"));
SetFieldValue("Extended Quantity Requested", sExtdQuantity);
WriteRecord();
}
isRecord1 = NextRecord();
}
}
}
} //end try
catch (e)
{
throw(e);
}
finally
{
oQuoteItemBC = null;
oQuoteItemBCMain = null;
oQuoteBC = null;
oQuoteBO = null;
}
}

CMI Update SR Sub Status IRN
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if(MethodName == "UpdateIRNSubStatus") {
UpdateIRNSubStatus(Inputs,Outputs);
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Update SR Sub Status IRN
UpdateIRNSubStatus
function UpdateIRNSubStatus(sInputs,sOutputs)
{
try
{
TheApplication().Utility.logStack("UpdateIRNSubStatus", this);
var oSRBusObject:BusObject = TheApplication().GetBusObject("Service Request");
var oSRBusComp:BusComp = oSRBusObject.GetBusComp("Service Request");
var oSRLWBusComp:BusComp = oSRBusObject.GetBusComp("Service Request - Lightweight");
var sBusComp:BusComp;
var sField:String;
var sValue:String;
var sSRId = sInputs.GetProperty("Object Id");
var sIRNFlg = sInputs.GetProperty("CMI IRN Flag");
TheApplication().Utility.logVars("SR Id", sSRId);
if (sSRId != "" && sSRId != null)
{
TheApplication().Utility.logVars("IRN Flag", sIRNFlg);
if (sIRNFlg == "Y" || sIRNFlg == "y")
{
sBusComp = oSRBusComp;
sField = "CMI Invoice Number";
sValue = sInputs.GetProperty("CMI IRN");
} else {
sBusComp = oSRLWBusComp;
sField = "Sub-Status";
sValue = sInputs.GetProperty("CMI SR Sub Status");
}
with (sBusComp) {
SetViewMode(AllView);
ActivateField(sField);
ClearToQuery();
SetSearchSpec("Id", sSRId);
ExecuteQuery(ForwardOnly);
var sFirstRecord = FirstRecord();
if (sFirstRecord)
{
SetFieldValue(sField, sValue);
WriteRecord();
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
oSRBusObject = null;
oSRBusComp = null;
oSRLWBusComp = null;
sBusComp = null;
TheApplication().Utility.logUnstack();
}
}

CMI Update Service Exposure BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By : ix964
Created On : 23rd NOV 2010
Method Name: (MethodName == "UpdateServiceExposure")
Functionality: This BS will be invoked by CMI Update Service Exposure WF which will be schedule in Server Job
Input: NA
Output: NA
Customization Approval #: NA
Modified by KM330 For C&I4530 on 29/08/2011
Modified by KK For CQ# 9572 on 08/21/2012
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs) {
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if (MethodName == "UpdateServiceExposure") {
var oServiceExposureBO :BusObject = TheApplication().GetBusObject("CMI Service Exposure");
var oServiceExposureBC :BusComp = oServiceExposureBO.GetBusComp("CMI Service Exposure");
var oQuoteBC :BusComp = oServiceExposureBO.GetBusComp("Quote");
var oLOVBO :BusObject = TheApplication().GetBusObject("List Of Values");
var oLOVBC :BusComp = oLOVBO.GetBusComp("List Of Values");
var iDeleted = 0;
var iInserted = 0;
var iProcessed = 0;
var strPrevQuoteNum;
var strCurrQuoteNum;
//deleting all old Error Log records of Type “CreditCheck” and Status “Complete”
fnClearErrorLog();
//deleting all old Service Exposure records
with(oServiceExposureBC)
{
SetViewMode(AllView);
ClearToQuery();
ExecuteQuery(ForwardBackward);
while(FirstRecord())
{
DeleteRecord();
iDeleted++;
NextSelected();
}
TheApplication().Utility.logVars("Num of Exposure Recs Deleted", iDeleted);
}
var sQuoteSRStatus :String = TheApplication().InvokeMethod("LookupValue", "CMI_SRV_EXP_SR_STATUS", "Open");
var sQuoteType : String = TheApplication().InvokeMethod("LookupValue", "CMI_SRV_EXP_QUOTE_TYPE", "Service Quote");//Service
var sSRSubType:String = TheApplication().InvokeMethod("LookupValue", "CMI_SRV_EXP_SRSUB_TYPE", "Work Order");//
//Added by KM330, modifying search expression :29-Aug-2011:Enhancement # S174
//var sSearchst = "[CMI SR Status] = '" + sQuoteSRStatus + "' AND [Quote Display Type] = '" + sQuoteType + "' AND [Active] = 'Y' AND (";
//var sSearchst:String = "[CMI SR Sub Type] = '" + sSRSubType + "' AND [CMI SR Status] = '" + sQuoteSRStatus + "' AND [Quote Display Type] = '" + sQuoteType + "' AND [Active] = 'Y'";
var sSearchst:String = "[CMI SR Sub Type] = '" + sSRSubType + "' AND [CMI SR Status] = '" + sQuoteSRStatus + "' AND [Quote Display Type] = '" + sQuoteType + "'";
//var isRecord = "";
var isRecord:bool = false;
var isAddBrace:bool = false;
with(oLOVBC)
{
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr("[Type] = 'CMI_SRV_EXP_QUOTE_STATUS' AND [Active] = 'Y'");
ActivateField("Type");
ActivateField("Active");
ActivateField("Value");
ActivateField("Name"); // Added for S174,KM330
ExecuteQuery(ForwardOnly);
isRecord = FirstRecord();
//Added by KM330, modifying search expression to add braces :29-Aug-2011:Enhancement # S174
if(isRecord)//new-line
{
isAddBrace = isRecord;
sSearchst = sSearchst + " AND (";
}
while(isRecord)
{
//Added by KM330, using LookupValue() and forming Search spec accordingly:29-Aug-2011:Enhancement#:S174
//sSearchst = sSearchst + "[Status] = '" + GetFieldValue("Value") + "'"; commented for S174
sSearchst = sSearchst + "[Status] = '" + TheApplication().InvokeMethod("LookupValue", "CMI_SRV_EXP_QUOTE_STATUS", GetFieldValue("Name")) + "'";//new-line
isRecord = NextRecord();
if(isRecord)
sSearchst = sSearchst + " OR ";
}
//Added by KM330, modifying search expression to add braces :16-Aug-2011:Enhancement # S174
if(isAddBrace)//new-line
{
sSearchst = sSearchst + ")";
}
}//with(bcLOV)
TheApplication().Utility.logVars("sSearchst", sSearchst);
with(oQuoteBC)
{
var sAccountId = "";
var sBillToSiteId = "";
var sBillToAddressId = "";
var sQuoteNumber = "";
var sQuoteAmount = "";
var sQuoteCurrencyCode = "";
var iOrderCount = 0;//added by KM330 for S174
SetViewMode(AllView);
ClearToQuery();
//var sQuoteStatus = TheApplication().InvokeMethod("LookupValue", "CMI_SRV_EXP_QUOTE_STATUS", "Accepted");//Accepted
//var sQuoteType = TheApplication().InvokeMethod("LookupValue", "CMI_SRV_EXP_QUOTE_TYPE", "Service Quote");//Service
//SetSearchExpr("[Status] = '" + sQuoteStatus + "' AND [Quote Display Type] = '" + sQuoteType + "'");
SetSearchExpr(sSearchst);
SetSortSpec("Quote Number, Revision(DESCENDING)");
ActivateField("CMI SR Status");
ActivateField("Active");
ActivateField("Account Id");
//Commented out by Dinesh, correct field identified is "CMI Bill To Profile Id":16-Aug-2011:Enhancement# S174
//ActivateField("Primary Organization Id");
ActivateField("CMI Bill To Profile Id");//Added for S174
ActivateField("Bill To Address Id");
ActivateField("Quote Total");
ActivateField("Revision");
//Nag; 7/25/2012; Added for CQ# 9207
ActivateField("CMI Quote Total Calc");
ActivateField("Currency Code");
ExecuteQuery(ForwardOnly);
//var haveQuote = FirstRecord();
var isQuote:bool = FirstRecord();//changed from havequote to isQuote,Km330,S174
TheApplication().Utility.logVars("isQuote", isQuote);
while (isQuote)//changed from haveQuote to isQuote
{
//Added by KM330, checking for number of Orders that are not submitted:08-Aug-2011:Enhancement # S174
iOrderCount = GetFieldValue("CMI Service Exposure Order");//new-line
if(iOrderCount.valueOf() == 0)//new-line
{
sAccountId = GetFieldValue("Account Id");
//Commented out by Dinesh, correct field identified is "CMI Bill To Profile Id":16-Aug-2011:Enhancement# S174
//sBillToSiteId = GetFieldValue("Primary Organization Id");
sBillToSiteId = GetFieldValue("CMI Bill To Profile Id");
sBillToAddressId = GetFieldValue("Bill To Address Id");
sQuoteNumber = GetFieldValue("Quote Number");
//Nag; 7/25/2012; Changed the field from Quote Total to CMI Quote Total Calc to reflect UI changes
sQuoteAmount = GetFieldValue("CMI Quote Total Calc");//Quote Total
sQuoteCurrencyCode = GetFieldValue("Currency Code");
//TheApplication().Utility.logVars("Quote# for SE is ", sQuoteNumber + " Revision: " + GetFieldValue("Revision"));
strCurrQuoteNum = sQuoteNumber;
if ( strPrevQuoteNum != strCurrQuoteNum)
{
with(oServiceExposureBC)
{
NewRecord(NewAfter);
SetFieldValue("CMI Account Id", sAccountId);
SetFieldValue("CMI Bill To Site Id", sBillToSiteId);
SetFieldValue("CMI Bill To Address Id", sBillToAddressId);
SetFieldValue("CMI Quote Number", sQuoteNumber);
SetFieldValue("CMI Quote Amount", sQuoteAmount);
SetFieldValue("CMI Currency Code", sQuoteCurrencyCode);
WriteRecord();
iInserted++;
}//with
} // end if
}//end if
//haveQuote = NextRecord();
strPrevQuoteNum = strCurrQuoteNum
iProcessed++;
isQuote = NextRecord();//replaced haveQuote by isQuote S174
}//end while (isQuote)
}// end with(bcQuote)
TheApplication().Utility.logVars("Num of Quote Recs Processed", iProcessed);
TheApplication().Utility.logVars("Num of Exposure Recs Inserted", iInserted);
//inserting an Error Log record of Type “CreditCheck”
fnInsertErrorLog();
return (CancelOperation);
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
oServiceExposureBC = null;
oQuoteBC = null;
oServiceExposureBO = null;
oLOVBC = null;
oLOVBO = null;
TheApplication().Utility.logUnstack(retVal);
}
return (retVal);
}

CMI Update Service Exposure BS
fnClearErrorLog
/*************************************************************************************************************************
Created By : km330
Created On : 25 Aug 2011
Method Name: MethodName == "fnClearErrorLog"
Functionality: This function deletes all old record of Type "CreditCheck" and Status "Complete"
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function fnClearErrorLog()
{
try
{
TheApplication().Utility.logStack("fnClearErrorLog", this);
var oErrBO:BusObject = TheApplication().GetBusObject("CMI Error Log");
var oErrBC:BusComp = oErrBO.GetBusComp("CMI Error Log Summary");
var sType:String = TheApplication().InvokeMethod("LookupValue", "CMI_SRV_EXP_ERR_TYPE", "CreditCheck");
var sStatus:String = TheApplication().InvokeMethod("LookupValue", "CMI_SRV_EXP_ERR_STATUS", "Complete");
//var sSrchStr:String = "[CMI Type] = '"+sType+"' AND [CMI Status] = '"+sStatus+"'";
var sSrchStr:String = "[CMI Type] = '"+sType+"'";
var iDeleted = 0;
with(oErrBC)
{
//query for Status = 'Complete' records and delete them
SetViewMode(AllView);
ClearToQuery();
SetSearchExpr(sSrchStr);
ExecuteQuery(ForwardBackward);
var isRecord:bool = FirstRecord();
TheApplication().Utility.logVars("isRecord", isRecord);
while(isRecord)
{
DeleteRecord();
iDeleted++;
//isRecord = NextRecord();
isRecord = NextSelected();
}
TheApplication().Utility.logVars("Num of Error Log Recs Deleted", iDeleted);
}
}
catch(e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
isRecord = null;
sType = null;
sStatus = null;
sSrchStr = null;
oErrBC = null;
oErrBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Update Service Exposure BS
fnInsertErrorLog
/*************************************************************************************************************************
Created By : km330
Created On : 25 Aug 2011
Method Name: MethodName == "fnInsertErrorLog"
Functionality: This function inserts record of Type "CreditCheck" and Status "In Progress"
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function fnInsertErrorLog()
{
try
{
TheApplication().Utility.logStack("fnInsertErrorLog", this);
var oErrBO:BusObject = TheApplication().GetBusObject("CMI Error Log");
var oErrBC:BusComp = oErrBO.GetBusComp("CMI Error Log Summary");
var sType:String = TheApplication().InvokeMethod("LookupValue", "CMI_SRV_EXP_ERR_TYPE", "CreditCheck");
var sStatus:String = TheApplication().InvokeMethod("LookupValue", "CMI_SRV_EXP_ERR_STATUS", "In Progress");
with(oErrBC)
{
//create new record
NewRecord(NewAfter);
SetFieldValue("CMI Object Name","Service Exposure");
SetFieldValue("CMI Type",sType);
SetFieldValue("CMI Status",sStatus);
WriteRecord();
TheApplication().Utility.logVars("ErrorLogId", GetFieldValue("Id"));
}
}
catch(e)
{
TheApplication().Utility.RaiseError(e);
}
finally
{
sType = null;
sStatus = null;
oErrBC = null;
oErrBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Utilities
trimPS
function trimPS(ps, fieldName, bc, maxLength)
{
try {
var psIn = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();
var bsService = TheApplication().GetService ("XML Converter (Data in Child PropSet)");
psIn.SetProperty("EscapeNames", "False");
var text:String = "";
psIn.AddChild(ps);
bsService.InvokeMethod("PropSetToXML", psIn, psOut);
bc.SetFieldValue(fieldName, ToString(psOut).substring(0, maxLength));
bc.SetFieldValue(fieldName+" Time", TimeStamp("DateTimeFormatted"));
text = bc.GetFieldValue(fieldName);
text = text.lTrim();
if (text.substring(0, 14) == "PropertySet [ ")
text = text.substring(14);
text = text.rTrim("]");
bc.SetFieldValue(fieldName,text);
} catch (e) {
throw(e);
} finally {
psOut = null;
psIn = null;
bsService = null;
}
}

CMI Utilities
(declarations)
var giStackIndex = 0; //Where in the function stack the current function resides
var gsIndent = ''; //used in debug methods to identify stack indents
var giLogBuffer = 0;
var giLogLines = 0;
var gsLogPath = "";
var gsLogCache = "";
var gsLogSession;
var gsLogCurRecordId = "";
var gsLogCurAction = "";
var gsLogCurObjName = "";
var gsLogCurObjType = "";
var gsLogCurObjMethod = "";
var giErrorStack = 0;
var ge = new Object();
var gStack = new Object();
var gCurrentLogLvl;
var storeBOs = new Array();
var storeBCs = new Array();
var gsTraceIntfaceReqResp;
var giPadVars = 35;
var gWriteMode = "Path";
var gsMergeGuestSessions;
var gsOutPutFileName;
var gsFileName;
var gsGuest;
var gsLogMode;
var giIndent = 2; //Indent child prop sets this many spaces to the right for each level down.
var giPSDepth = 0; // How deep in the property set tree, what levelvar CurrentLogLevel = 2;
var gaFunctionStack = new Array(); //used in debugStack function so store called functions
var gaFunctionStackLog = new Array(); //used in debugStack function to store called functions log level
/*var gboSession:BusObject;
var gbcSession:BusComp;
var gbcSessionLog:BusComp;
var gbcSessionXML:BusComp;
*/
var gSessionId = "";
var gHoldBuffer:bool = false;
var gTraceType = "GENERAL";
var gLastLogAction = "";
var gLastLogObject = "";
var gLastLogMethod = "";
var gLastLogLength = 0;
var gCascadeBO:BusObject = null;
var gSysLogLevel = 0;
var gsPreEventCache = "";
var giPreEventLines = 0;
var maxPreEventLines = 2;
var gHoldPayloads = new Array();
var gIntermediateBufferDump = "";

CMI Utilities
AddAttachment
/************************************************************************
** Created By: Mik Branchaud
** Created On: 19MAY2011
**
** Add an attachment file to a BC
**
** Upd On Upd By Description
** ------ ------ -----------
************************************************************************************************************************************************/
function AddAttachment (Inputs,Outputs) {
try {
logStack("AddAttachment", 5);
var sBOName = Inputs.GetProperty("BusinessObject");
var sObjectId = Inputs.GetProperty("ObjectId");
var sAttBcName = Inputs.GetProperty("AttBusinessComponent");
var sAttFieldName = Inputs.GetProperty("AttachmentFieldName");
var sPrimBcName = Inputs.GetProperty("PrimaryBusinessComponent");
var sFileName = Inputs.GetProperty("File");
var sRenameString = Inputs.GetProperty("RenameString");
var sRenameKey = Inputs.GetProperty("RenameKey");
var sLookupKeyField = Inputs.GetProperty("LookupKeyField");
var sDelete = Inputs.GetProperty("DeleteTemp");
var boObject = TheApplication().GetBusObject(sBOName);
var bcObject = boObject.GetBusComp(sPrimBcName);
var bcAttach, sReturn, sIndex, bFound, sCommand;
var timeBuf = "";
var sPropName = "";
Outputs.SetProperty("Return","");
bcObject.ActivateField("Id");
bcObject.SetViewMode(AllView);
bcObject.ClearToQuery();
bcObject.SetSearchSpec("Id", sObjectId);
bcObject.ExecuteQuery(ForwardOnly);
logVars(sPrimBcName+" found?", bcObject.FirstRecord(), 5);
if (bcObject.FirstRecord()) {
bcAttach = boObject.GetBusComp(sAttBcName);
//If a this is not an update, and a rename string is provided without a key to make it unique, check to see if that name
//is used for this object. If it is already used (record found) use Siebel vanilla naming
//convention which prepends the machine name and PID
logVars("Rename String/Key/Field", sRenameString+" / "+sRenameKey+" / "+sLookupKeyField, 5);
if ((sRenameString != "") && (sRenameKey == "") && (sLookupKeyField == "")) {
bcAttach.InvokeMethod("SetAdminMode", "TRUE"); //Set in case BC is read only due to configured business rules
bcAttach.ClearToQuery();
bcAttach.SetSearchSpec(sAttFieldName, sRenameString);
bcAttach.ExecuteQuery(ForwardOnly);
bFound = bcAttach.FirstRecord();
Clib.strftime(timeBuf,"%d" + "%m" + "%Y" + "%H" + "%M"+ "%S" + "%p",Clib.localtime(Clib.time()));
if (bFound) sRenameKey = timeBuf;
} else if (sRenameKey != "") sRenameString = sRenameString+"_"+sRenameKey;
if (sLookupKeyField != "") {
bcAttach.ClearToQuery();
bcAttach.InvokeMethod("SetAdminMode", "TRUE"); //Set in case BC is read only due to configured business rules
if (sLookupKeyField.indexOf("FileName") >= 0) bcAttach.SetSearchSpec(sAttFieldName, sRenameString);
else bcAttach.SetSearchSpec(Inputs.GetProperty("SetFieldName"), Inputs.GetProperty("SetFieldValue"));
logVars("Update Key Expression", bcAttach.GetSearchExpr(), 5);
bcAttach.ExecuteQuery(ForwardOnly);
bFound = bcAttach.FirstRecord();
if (!bFound) bcAttach.NewRecord(NewBefore);
} else {
bcAttach.NewRecord(0);
}
// The following line - or something similar - is needed if there
// are required fields (e.g. Title) for the attachment buscomp
// bcAttach.SetFieldValue("Title", "Declaration");
sPropName = Inputs.GetFirstProperty();
while (sPropName != "") {
if (sPropName.indexOf("SetFieldName") >= 0) {
sIndex = sPropName.substring(12);
try {
bcAttach.SetFieldValue(Inputs.GetProperty(sPropName), Inputs.GetProperty("SetFieldValue"+sIndex));
} catch(e) {
//If BC is still read only even in admin mode ignore the error and continue with report generation
}
}
sPropName = Inputs.GetNextProperty();
}
sReturn = bcAttach.InvokeMethod("CreateFile", sFileName, sAttFieldName, "Y");
Outputs.SetProperty("Return",sReturn);
if (sRenameString != "") {
bcAttach.SetFieldValue(sAttFieldName, sRenameString);
}
bcAttach.WriteRecord();
logVars("Delete", sDelete, 5);
if ((sDelete == "")||(sDelete.toUpperCase == "N")||(sDelete.toUpperCase == "FALSE")) {
var fp = Clib.fopen(sFileName,"r"); //Create a new File Pointer to check if the file exists
if (fp != null) //Check if the file exists, if the file pointer is null, it does not exist.
{
Clib.fclose(fp); //close the file pointer
Clib.remove(sFileName); //remove the file
} //end if (fp != null)
}
}
else throw("Record in '"+sPrimBcName+"' BC not found");
} catch(e) {
RaiseError(e);
} finally {
bcAttach = null;
bcObject = null;
boObject = null;
logUnstack(Outputs.GetProperty("Return"), 5);
}
} //End function

CMI Utilities
TimeStamp
function TimeStamp(mode)
{
/*****************************************************************
* Description: Return TimeStamp. Pass in a mode to refine the
type of timestamp desired.
*****************************************************************/
var dateVar = new Date();
var year = dateVar.getFullYear().toString();
var month = (dateVar.getMonth() + 1).toString();
var day = dateVar.getDate().toString();
var hour = dateVar.getHours().toString();
var minute = dateVar.getMinutes().toString();
var second = dateVar.getSeconds().toString();
var milli = dateVar.getMilliseconds().toString();
//Pad
var dateStamp = Clib.rsprintf("%04s%02s%02s", year, month, day);
var timeStamp = Clib.rsprintf("%02s%02s%02s", hour, minute, second);
milli = Clib.rsprintf("%03s", milli);
var retVal = dateStamp + "_" + timeStamp; //default DateTime //20070103_123422
switch (mode) {
case "DateOnly": //20070103
retVal = dateStamp;
break;
case "TimeOnly": //123422
retVal = timeStamp;
break;
case "TimeMilli": //123422.22
retVal = timeStamp + "." + milli;
break;
case "DateTimeMilli": //20070103_123422_222
retVal = retVal + "_" + milli;
break;
case "DateTimeFormatted": //20070103_123422_222
retVal = month + "/" + day + "/" + year + " " + hour + ":" + minute + ":" + second
break;
}
return (retVal);
}

CMI Utilities
UTF8toString
function UTF8toString(binaryMsg)
{
// For Binary, Message must be in Value and can not be moved
try
{
var retString = "";
var psOut = TheApplication().NewPropertySet();
var bsService = TheApplication().GetService ("Transcode Service");
binaryMsg.SetProperty("ConversionMode", "EncodingToString");
binaryMsg.SetProperty("SourceEncoding", "UTF-8");
bsService.InvokeMethod("Convert", binaryMsg, psOut);
retString = psOut.GetValue();
}
catch(e) {
RaiseError(e);
} finally {
psOut = null;
bsService = null;
}
return(retString);
}

CMI Utilities
Validate
function Validate(obc, sRuleSet) {
/**************************************************************************************
* Description: Run Data Validation rulest via script call
*****************************************************************************************
* Revision History:
* M. Branchaud 10/13/10 - Initial Development
***************************************************************************************/
// try {
var errorMsg = "";
//--Invoke BC userprop named method which in turn invokes dvm.validate for a particular ruleset
try {
TheApplication().SetProfileAttr("DVMRuleSetName",sRuleSet);
obc.InvokeMethod("Validate");
} catch (e) {
//--Strip off the extra error code siebel tacks on...
errorMsg = e.errText.replace(/\(SBL-...-.....\)/g,"")
}
//--Throw Validation errors to user
if (errorMsg != "") {
throw (errorMsg);
}
// }
// catch (e) {
// TheApplication().RaiseErrorText(errorMsg);
// }
}

CMI Utilities
cascade
function cascade(bcSource, boName, bcName, searchExpr, refresh, refreshBC)
{
try {
TheApplication().Utility.logStack("cascade."+bcName, this);
var numAdminArgs:float = 6;
var fields = TheApplication().NewPropertySet();
var recCount = 0;
var retry = false;
var retryFields = TheApplication().NewPropertySet();
var checkDependencies = true;
var dependencyCounter:float = 1;
var dependencyProp = "";
var dependencyFields = TheApplication().NewPropertySet();
var fieldUpdated = false;
if (arguments.length == numAdminArgs+1) {
fields = arguments[numAdminArgs];
} else {
for (var i=numAdminArgs; i < (arguments.length); i++) {
fields.SetProperty(arguments[i++], arguments[i])
}
}
// logPS(fields);
var remainingFields = fields.Copy();
//Because properties in a property set cannot be sequenced, provide a mechanism to insure certain fields
//can be set before others
while (checkDependencies) {
dependencyProp = "FieldDependency"+dependencyCounter;
if (fields.PropertyExists(dependencyProp)) {
logVars(dependencyProp, fields.GetProperty(dependencyProp), 4);
dependencyFields.SetProperty(dependencyCounter, fields.GetProperty(dependencyProp));
//If FieldDependency properties are used, we will have 2 property sets, dependencyFields for
//sequencing fields, and remainingFields will contain all others for which sequence does not matter
remainingFields.RemoveProperty(fields.GetProperty(dependencyProp));
remainingFields.RemoveProperty(dependencyProp);
dependencyCounter += 1;
} else {
checkDependencies = false;
}
}
//Allow Parent/Child relationships by instantiating the BO once when first called. All subsequent iterative
//calls will simply reuse the same BO
if (gCascadeBO == null) gCascadeBO = TheApplication().GetBusObject(boName);
var vBusComp = gCascadeBO.GetBusComp(bcName);
var vUpdatedflag = "N";
var propName;
var propValue;
var nextProperty = true;
with(vBusComp) {
SetViewMode(AllView);
ActivateMultipleFields(fields);
ClearToQuery();
SetSearchExpr(searchExpr);
ExecuteQuery(ForwardBackward);
var lsRec = FirstRecord();
//Loop Thought each data transactional record
while(lsRec) {
vUpdatedflag = "Y";
//Set the fields that have dependencies in sequential order
for (var i=1; i < dependencyCounter; i++) {
propName = dependencyFields.GetProperty(i);
propValue = fields.GetProperty(propName);
if (recCount == 0) logVars(propName, propValue, 4);
SetFieldValue(propName, propValue);
}
//Set the all other fields that have no dependency
propName = remainingFields.GetFirstProperty();
while(propName!="") {
propValue = remainingFields.GetProperty(propName);
if (recCount == 0) logVars(propName, propValue, 4);
try {
//when using a property set, field sequence is random, therefore save failed updates (from
//dependent pickmaps to try a second time
SetFieldValue(propName, propValue);
fieldUpdated = true;
} catch(e) {
if (e.errCode != "7667937") logError(e);
retryFields.SetProperty(propName, propValue)
retry = true;
}
propName = remainingFields.GetNextProperty();
}
if (retry) {
propName = retryFields.GetFirstProperty();
while(propName!="") {
propValue = retryFields.GetProperty(propName);
if (recCount == 0) logVars("Retry - "+propName, propValue, 4);
SetFieldValue(propName, propValue);
fieldUpdated = true;
propName = retryFields.GetNextProperty();
}
}
if (fieldUpdated) WriteRecord();
recCount++;
//If the Input property set has been setup with children, this method can be called iteratively to
//update records in parent child relationships so that the links are active. The correct setup to do
//so is a child property set containing parameters that will be used in the iterative call, and a
//grandchild containing the actual fields to be set on the child. This can be done any number of times
if (fields.GetChildCount() > 0) {
var childBC = fields.GetChild(0).GetProperty("childBC");
var childSearchExpr = fields.GetChild(0).GetProperty("childSearchExpr");
fields.GetChild(0).GetChild(0).SetType("DIVE");
cascade(vBusComp, boName, childBC, childSearchExpr, false, "", fields.GetChild(0).GetChild(0));
}
lsRec = NextRecord();
}
}
TheApplication().Utility.logStep(bcName+" - Updated (Count)/Refresh: "+vUpdatedflag+" ("+recCount+") / "+refresh);
if (refresh == true && vUpdatedflag == "Y") {
if (refreshBC != "") {
bcSource.BusObject().GetBusComp(refreshBC).InvokeMethod("RefreshBusComp");
} else {
bcSource.WriteRecord();
bcSource.BusObject().GetBusComp(bcSource.Name()).InvokeMethod("RefreshBusComp");
}
}
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
vBusComp = null;
//only clear the BO when back at the top level
if (fields.GetType() == "") gCascadeBO = null;
fields = null;
retryFields = null;
dependencyFields = null;
remainingFields = null;
TheApplication().Utility.logUnstack();
}
}

CMI Utilities
insertError
function insertError()
{
try {
TheApplication().Utility.logStack("insertError");
var boIntegrationError = TheApplication().GetBusObject("CMI Interface Log");
var bcIntegrationError = boIntegrationError.GetBusComp("CMI Interface Log");
var errorStatus;
var errorType:String = (arguments[0] == undefined ? "" : arguments[0].toString());
var grandParentId:String= (arguments[1] == undefined ? "" : arguments[1].toString());
var parentId:String = (arguments[2] == undefined ? "" : arguments[2].toString());
var childId:String = (arguments[3] == undefined ? "" : arguments[3].toString());
var interfaceName:String= (arguments[4] == undefined ? "" : arguments[4].toString());
var method:String = (arguments[5] == undefined ? "" : arguments[5].toString());
var errorCode:String = (arguments[6] == undefined ? "" : arguments[6].toString());
var errorMessage:String = (arguments[7] == undefined ? "" : arguments[7].toString());
var sXvar_30_01:String = (arguments[8] == undefined ? "" : arguments[8].toString());
var sXvar_30_02:String = (arguments[9] == undefined ? "" : arguments[9].toString());
TheApplication().Utility.logVars("Call/Line/Component",grandParentId+" / "+parentId+" / "+childId,"Interface/Method", interfaceName+" / "+method, "Code/Message", errorCode+" / "+errorMessage,1);
if (errorCode == "0") errorStatus = "Success";
else errorStatus = "Error";
with(bcIntegrationError) {
NewRecord(NewAfter);
SetFieldValue("Error Code", errorCode.substring(0, 15));
SetFieldValue("Error Message", errorMessage.substring(0, 250));
SetFieldValue("Interface Name", interfaceName.substring(0, 30));
SetFieldValue("Par Row Id", grandParentId.substring(0, 15));
SetFieldValue("Status", errorStatus);
SetFieldValue("Type", errorType.substring(0, 30));
SetFieldValue("X_VARCHAR_15_01", grandParentId.substring(0, 15)); // CMI Call Row Id
SetFieldValue("X_VARCHAR_15_02", parentId.substring(0, 15)); // CMI Call Line Row Id
SetFieldValue("X_VARCHAR_15_03", childId.substring(0, 15)); // CMI Transaction Row Id
SetFieldValue("X_VARCHAR_250_01", method.substring(0, 250)); // CMI Transaction Name
SetFieldValue("X_VARCHAR_30_01", sXvar_30_01.substring(0, 30));
SetFieldValue("X_VARCHAR_30_02", sXvar_30_02.substring(0, 30));
SetFieldValue("Extended Error Message", errorMessage.substring(0, 1900));
WriteRecord();
} // with
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
bcIntegrationError = null;
boIntegrationError = null;
TheApplication().Utility.logUnstack("");
}
}

CMI Utilities
logClose
function logClose() {
try {
logStep("End Of Session");
DumpBuffer();
/* gbcSession.InvokeMethod("RefreshRecord");
gbcSession.SetFieldValue("Session End Date",gbcSession.GetFieldValue("Now"));
gbcSession.WriteRecord();
*/
var boSession = TheApplication().GetBusObject("CMI User Session");
var bcSession = boSession.GetBusComp("CMI User Session");
with (bcSession) {
ClearToQuery();
ActivateField("Session End Date");
ActivateField("Now");
SetSearchSpec("Id", gSessionId);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) {
SetFieldValue("Session End Date", GetFieldValue("Now"));
WriteRecord();
}
}
} catch(e) {
throw(e);
} finally {
ge = null;
gStack = null;
storeBCs = null;
storeBOs = null;
gaFunctionStack = null;
gaFunctionStackLog = null;
/* gbcSessionLog = null;
gbcSessionXML = null;
gbcSession = null;
gboSession = null;
*/
bcSession = null;
boSession = null;
}
}

CMI Utilities
logError
function logError() {
/* ***********************************
Created by Mik Branchaud on 09/20/11
Purpose: Log an error to the session log then return control to the function. Defaults to log level 0
Usage: TheApplication().Utility.logError(e);
Arguments: 1 - exception
**************************************** */
//TheApplication().Trace("In RaiseError");
// Log.step("RaiseError", 5);
var oE = arguments[0];
var objectName = (arguments.length < 2 ? "" : arguments[1]);
var rowId = (arguments.length < 3 ? "" : arguments[2]);
var stackLength = gaFunctionStack.length;
var objMethod = gaFunctionStack[stackLength-1];
var objDisplay = objMethod;
if (objectName != "") objDisplay = objectName+"."+objDisplay;
if (rowId != "") objDisplay = objDisplay + " ("+rowId+")";
gsIndent = "".rPad(giIndent*stackLength, " ");
if(!defined(oE.errText)) ge.errText = oE.toString();
else ge.errText = oE.errText;
ge.errText = ge.errText.substring(0, 500);
if(!defined(oE.errCode)) ge.errCode = "";
else ge.errCode = oE.errCode;
logStep("".rPad(100, "*"),0);
logStep("*** - ERROR - "+objDisplay+" - "+ge.errCode,0);
logStep("*** "+ge.errText.replace(/\n/g, "\n"+"*** "),0);
logStep("".rPad(100, "*")+"\n",0);
DumpBuffer();
return("An exception occurred in "+objDisplay+": \n"+ge.errText);
}

CMI Utilities
logHoldBuffer
function logHoldBuffer(val)
{
logVars("HoldBuffer", val, 5);
if (val.toUpperCase() == "TRUE") {
DumpBuffer();
gHoldBuffer = true;
} else {
try {
gHoldBuffer = false;
DumpBuffer();
var holdArguments = new Array();
var count = 0;
var max = gHoldPayloads.length;
logVars("Payload Count", max);
while (count < max) {
holdArguments = gHoldPayloads[count];
logInterface(holdArguments[0],
holdArguments[1],
holdArguments[2],
holdArguments[3],
holdArguments[4],
holdArguments[5],
holdArguments[6],
holdArguments[7],
holdArguments[8],
holdArguments[9],
holdArguments[10],
holdArguments[11],
holdArguments[12],
holdArguments[13],
holdArguments[14]);
count++;
}
} catch(e) {
throw(e);
} finally {
gHoldPayloads = [];
holdArguments = null;
}
}
logUnstack("", 5);
}

CMI Utilities
logId
function logId()
{
if (typeof(arguments[0])=="object") {
if (arguments[0] != null) {
gsLogCurObjName = arguments[0].Name();
gsLogCurRecordId = arguments[0].GetFieldValue("Id");
}
} else {
gsLogCurObjName = arguments[0];
gsLogCurRecordId = arguments[1];
}
DumpBuffer();
}

CMI Utilities
logInsert
function logInsert(text) {
/*
//If one has not yet been created, create the session record against which log lines will be written
if (typeof(gboSession) == "undefined" || gboSession == null) {
gboSession = TheApplication().GetBusObject("CMI User Session");
gbcSession = gboSession.GetBusComp("CMI User Session");
gbcSession.NewRecord(NewBefore);
gbcSession.SetFieldValue("Employee Id",TheApplication().LoginId());
gbcSession.SetFieldValue("Session Id",gsLogSession);
gbcSession.WriteRecord();
gbcSessionLog = gbcSession.GetMVGBusComp("User Session Log Id");
gbcSessionXML = gboSession.GetBusComp("CMI User Session XML");
}
gbcSessionLog.NewRecord(NewAfter);
gbcSessionLog.SetFieldValue("Log Text",text);
gbcSessionLog.SetFieldValue("Record Id",gsLogCurRecordId);
gbcSessionLog.SetFieldValue("Record BC",gsLogCurObjName);
gbcSessionLog.WriteRecord();
*/
try {
var boSession:BusObject = TheApplication().GetBusObject("CMI User Session");
var bcSession:BusComp;
var bcSessionLog:BusComp;
var maxlength = 131072;
// var writeText;
if (gSessionId == "") {
bcSession = boSession.GetBusComp("CMI User Session");
with (bcSession) {
NewRecord(NewBefore);
SetFieldValue("Employee Id",TheApplication().LoginId());
SetFieldValue("Session Stamp",gsLogSession);
WriteRecord();
gSessionId = GetFieldValue("Id");
}
}
bcSessionLog = boSession.GetBusComp("CMI User Session Log");
// if (text.length > maxlength) writeText = text.substring(0, maxlength);
// else writeText = text;
while (text.length > 0) {
bcSessionLog.NewRecord(NewAfter);
bcSessionLog.SetFieldValue("Parent Id",gSessionId);
bcSessionLog.SetFieldValue("Log Text",text.substring(0, maxlength));
bcSessionLog.SetFieldValue("Record Id",gsLogCurRecordId);
bcSessionLog.SetFieldValue("Record BC",gsLogCurObjName);
bcSessionLog.SetFieldValue("Sub Type",gTraceType);
bcSessionLog.WriteRecord();
text = text.substring(maxlength, text.length);
}
} catch(e) {
throw(e);
} finally {
bcSessionLog = null;
bcSession = null;
boSession = null;
//Initialize so unrelated log events do not get associated to this record
gsLogCurRecordId = "";
}
}

CMI Utilities
logInterface
function logInterface(key, request, response, dir, recId, recBC, status, srcObject, name, logText, userText, retCode, ref1, ref2, ref3)
{
try {
logStack("logInterface", 5);
logVars("key", key, "Record Id", recId, "Record BC", recBC, "Global Session Row Id", gSessionId, "Hold Buffer", gHoldBuffer, "Guest Login", gsGuest, 5);
var found:Boolean = false;
var sessionId:String = "";
var guestSessionId:String = "";
var guestSessionFound = false;
var createSession = false;
var firstMessage = false;
var boSessionFlat;
var bcSessionXMLFlat;
var useGuestSession = (response != null && gsMergeGuestSessions=="TRUE" && gsGuest != "" ? true : false);
var boSession:BusObject = TheApplication().GetBusObject("CMI User Session");
var bcSession:BusComp;
if (gHoldBuffer) {
//If in a EAI Txn, store all payloads in an array so they can be written after the commit or rollback
gHoldPayloads[gHoldPayloads.length] = arguments;
} else if (gsTraceIntfaceReqResp == "TRUE" && key != "") {
//If an interface is being logged for the first time, need to instantiate the session
if (gSessionId == "") {
//If Guest connections are not used, a simplified session management can be used
if (gsGuest == "" && key != "") {
bcSession = boSession.GetBusComp("CMI User Session");
with (bcSession) {
NewRecord(NewBefore);
SetFieldValue("Employee Id",TheApplication().LoginId());
SetFieldValue("Session Stamp",gsLogSession);
WriteRecord();
gSessionId = GetFieldValue("Id");
}
createSession = false; //skip logic below to create/merge a guest session
firstMessage = true; //will always insert the input message rather than querying to update
//Reset the variable to check whether to merge the guest session. This allows a log buffer dump
gsMergeGuestSessions = "FALSE";
} else {
createSession = true;
//confirm that current session has not been created yet
bcSession = boSession.GetBusComp("CMI User Session");
with (bcSession) {
ClearToQuery();
SetSearchSpec("Session Stamp", gsLogSession);
ExecuteQuery(ForwardOnly);
found = FirstRecord();
if (found == true) {
gSessionId = GetFieldValue("Id");
createSession = false;
} else {
firstMessage = true;
}
}
}
}
logVars("CreateSession", createSession, "useGuestSession", useGuestSession, "First Message", firstMessage, 5);
if (createSession == true || useGuestSession == true) {
bcSession = boSession.GetBusComp("CMI User Session");
//Because EAI logins can trigger logging from the anonymous login, the response logging will trigger
//from a different session. Query for the most recent corresponding request log and update it
if (useGuestSession) {
boSessionFlat = TheApplication().GetBusObject("CMI User Session Flat");
bcSessionXMLFlat = boSessionFlat.GetBusComp("CMI User Session XML");
bcSessionXMLFlat.ActivateField("Parent Id");
bcSessionXMLFlat.ClearToQuery();
if (typeof(srcObject) != "undefined" && srcObject != null) bcSessionXMLFlat.SetSearchSpec("Source Object", srcObject);
if (typeof(ref1) != "undefined" && ref1 != null) bcSessionXMLFlat.SetSearchSpec("Reference Id 1", ref1);
bcSessionXMLFlat.SetSearchSpec("Response", "IS NULL");
bcSessionXMLFlat.SetSearchSpec("Employee Login", gsGuest);
bcSessionXMLFlat.SetSortSpec("Created (DESC)");
bcSessionXMLFlat.ExecuteQuery(ForwardBackward);
guestSessionFound = bcSessionXMLFlat.FirstRecord();
if (guestSessionFound == true) guestSessionId = bcSessionXMLFlat.GetFieldValue("Parent Id");
}
logVars("guestSessionFound", guestSessionFound, 5);
if (guestSessionFound == false && createSession == true) {
//Anonymous login session not found and there is no current session. Create a new one
with (bcSession) {
NewRecord(NewBefore);
SetFieldValue("Employee Id",TheApplication().LoginId());
SetFieldValue("Session Stamp",gsLogSession);
WriteRecord();
gSessionId = GetFieldValue("Id");
logVars("New Global Session Row Id", gSessionId, 5);
}
} else if (guestSessionFound == true && createSession == false) {
//Anonymous login session found and there is a current session.
//Link child records to the parent session for the Interface User and delete the guest session (faster than a merge)
while (guestSessionFound) {
bcSessionXMLFlat.SetFieldValue("Parent Id",gSessionId);
bcSessionXMLFlat.WriteRecord();
guestSessionFound = bcSessionXMLFlat.NextRecord();
}
with (bcSession) {
ClearToQuery();
SetSearchSpec("Id", guestSessionId);
SetSortSpec("");
ExecuteQuery(ForwardOnly);
guestSessionFound = FirstRecord();
if (guestSessionFound == true) DeleteRecord();
ClearToQuery();
SetSortSpec("");
SetSearchSpec("Id", gSessionId);
ExecuteQuery(ForwardOnly);
}
} else if (guestSessionFound == true && createSession == true) {
//Anonymous login session found and there is no current session. Update the guest session to EAI values
with (bcSession) {
ActivateField("Employee Id");
ActivateField("Session Stamp");
ClearToQuery();
SetSearchSpec("Id", guestSessionId);
SetSortSpec("");
ExecuteQuery(ForwardBackward);
found = FirstRecord();
if (found == true) {
SetFieldValue("Employee Id",TheApplication().LoginId());
SetFieldValue("Session Stamp",gsLogSession);
WriteRecord();
}
}
} else {
//Anonymous login session not found and there is a current session. Do Nothing
}
//Reset the variable to check whether to merge the guest session. This allows a log buffer dump
gsMergeGuestSessions = "FALSE";
}
var bcSessionXML = boSession.GetBusComp("CMI User Session XML");
var bcSessionXMLDtl = boSession.GetBusComp("CMI User Session XML Detail");
with (bcSessionXML) {
if (firstMessage) {
//This is an insert so no query needed to update an existing record
found = false;
} else if (useGuestSession && guestSessionFound) {
//If this is the first update after a guest session is used, the key will not match but there should only be one XML record
ClearToQuery();
SetSearchSpec("Created By Login", gsGuest);
SetSearchSpec("Parent Id", gSessionId);
SetSearchSpec("Request", "IS NOT NULL");
SetSearchSpec("Response", "IS NULL");
ExecuteQuery(ForwardBackward);
found = FirstRecord();
} else {
//This is a normal response update to an existing message record
ClearToQuery();
SetSearchSpec("Parent Id", gSessionId);
SetSearchSpec("Name", key);
SetSortSpec("");
ExecuteQuery(ForwardBackward);
found = FirstRecord();
}
if (found == false) {
NewRecord(NewBefore);
SetFieldValue("Name",key);
SetFieldValue("Parent Id",gSessionId);
logVars("XML Record Id", GetFieldValue("Id"), 5);
}
if (useGuestSession == true) SetFieldValue("Name", key.substring(0, 100));
if (typeof(request) != "undefined" && request != null) {
SetFieldValue("Request Time", TimeStamp("DateTimeFormatted"));
splitPayload(bcSessionXMLDtl, "Request", request, 131072)
}
if (typeof(response) != "undefined" && response != null) {
SetFieldValue("Response Time", TimeStamp("DateTimeFormatted"));
splitPayload(bcSessionXMLDtl, "Response", response, 131072)
}
// if (typeof(request) != "undefined" && request != null) trimPS(request, "Request", bcSessionXML, 131072);
// if (typeof(response) != "undefined" && response != null) trimPS(response, "Response", bcSessionXML, 131072);
if (typeof(dir) != "undefined" && dir != null) SetFieldValue("Direction", dir.substring(0, 30));
if (typeof(recId) != "undefined" && recId != null) SetFieldValue("Record Id", recId.substring(0, 15));
if (typeof(recBC) != "undefined" && recBC != null) SetFieldValue("Record BC", recBC.substring(0, 50));
if (typeof(status) != "undefined" && status != null) SetFieldValue("Status", status.substring(0, 30));
if (typeof(srcObject) != "undefined" && srcObject != null) SetFieldValue("Source Object", srcObject.substring(0, 50));
if (typeof(name) != "undefined" && name != null) SetFieldValue("Functional Name", name.substring(0, 50));
if (typeof(logText) != "undefined" && logText != null) SetFieldValue("Log Text", logText.substring(0, 131072));
if (typeof(userText) != "undefined" && userText != null) SetFieldValue("User Text", userText.substring(0, 255));
if (typeof(retCode) != "undefined" && retCode != null) SetFieldValue("Return Code", retCode.substring(0, 30));
if (typeof(ref1) != "undefined" && ref1 != null) SetFieldValue("Reference Id 1", ref1.substring(0, 100));
if (typeof(ref2) != "undefined" && ref2 != null) SetFieldValue("Reference Id 2", ref2.substring(0, 100));
if (typeof(ref3) != "undefined" && ref3 != null) SetFieldValue("Reference Id 3", ref3.substring(0, 100));
WriteRecord();
}
if (gsLogMode == "FILE") {
if (typeof(request) != "undefined" && request != null) PropSetToFile(key+"_Request", request);
if (typeof(response) != "undefined" && response != null) PropSetToFile(key+"_Response", response);
}
}
} catch(e) {
RaiseError(e);
} finally {
bcSessionXML = null;
bcSessionXMLFlat = null;
boSessionFlat = null;
bcSession = null;
boSession = null;
logUnstack("", 5);
}
}

CMI Utilities
logPS
function logPS() {
/* ***********************************
Created by Mik Branchaud on 09/20/11
Purpose: Log property sets to the session log. Defaults to log level 4
Usage: TheApplication().Utility.logPS(Inputs);
Arguments: 1 - PropertySet
2 - (OPTIONAL) Log Level - To log this event at a lower level
**************************************** */
try {
var Lvl = (arguments.length > 1 ? arguments[1] : 4);
var Inputs = arguments[0];
// Print out the contents of a property set.
if (gCurrentLogLvl >= Lvl) {
if (giPSDepth == 0) {
DumpBuffer();
gTraceType = "PS";
}
giPSDepth++; // Dive down a level
var InpChildCount, inprop, inpropval, inpropcnt;
var BlankLine = ' ';
var Indent = "".lPad(giIndent*giPSDepth, " ") + ToString(giPSDepth).lPad(2, "0") + ' ';
InpChildCount = Inputs.GetChildCount();
logStep(Indent + 'Value is ........ : "' + Inputs.GetValue() + '"', Lvl);
logStep(Indent + 'Type is ........ : "' + Inputs.GetType() + '"', Lvl);
logStep(Indent + 'Child count ..... : ' + ToString(InpChildCount), Lvl);
var PropCounter = 0;
inprop = Inputs.GetFirstProperty();
while (inprop != "") { // Dump the properties of this property set
PropCounter++;
inpropval = Inputs.GetProperty(inprop);
var PropCountStr = ToString(PropCounter).lPad(2, "0");
logStep(Indent+'Prop '+PropCountStr+': <'+inprop.rPad(30," ")+'> / <'+inpropval+'>', Lvl);
inprop = Inputs.GetNextProperty();
}
// Dump the children of this PropertySet
if (InpChildCount != 0) {
for (var ChildNumber = 0; ChildNumber < InpChildCount; ChildNumber++) {
logStep(BlankLine, Lvl);
logStep(Indent + 'Child Property Set ' + ToNumber(ChildNumber + 1) + ' of ' + ToNumber(InpChildCount) + ' follows below.', Lvl);
// Recursive call for children, grandchildren, etc.
logPS(Inputs.GetChild(ChildNumber), Lvl);
}
}
giPSDepth--; // Pop up a level
}
} finally {
Inputs = null;
if (giPSDepth == 0) {
DumpBuffer();
gTraceType = "GENERIC";
}
}
}

CMI Utilities
logRequest
function logRequest(Inputs,Outputs)
{
/* ***********************************
Created by Mik Branchaud on 09/20/11
Purpose: Log interface request from/to an external interface in the session log
Usage: In Web Service definition, operations applet, set the Request Filter BS to 'CMI Utilities'
and the method to logRequest. Clear the cache
Arguments: 1 - SoapMessage will implicily be passed as a child property set
**************************************** */
try {
logStack("logRequest", 5);
var soapEnv, soapBody, divePS;
var bodyType="";
var msgType="";
var parseResults = new Object();
var key = TheApplication().Utility.TimeStamp();
var max = 3;
var dives = 0;
logVars("Inputs Child Count", Inputs.GetChildCount(), 5);
if(Inputs.GetChildCount() > 0) {
try { // Try to process the message to get functional data
// Get the SOAP envelope from the SOAP hierarchy
soapEnv = Inputs.GetChild(0); //Like env:Envelope
for (var i=0; i < soapEnv.GetChildCount(); i++) {
bodyType = soapEnv.GetChild(i).GetType(); //Like env:Body
logVars("soapEnv Child Type", bodyType, 5);
if (bodyType.toUpperCase() == "BODY" || bodyType.substr(bodyType.indexOf(":")+1).toUpperCase() == "BODY") {
soapBody = soapEnv.GetChild(i);
for (var j=0; j < soapBody.GetChildCount(); j++) {
msgType = soapBody.GetChild(j).GetType(); //Full Port name of the WS
logVars("Body Child Type", msgType, 5);
if (msgType.indexOf(":") >= 0) msgType = msgType.substr(msgType.indexOf(":")+1); //strip namespace
if (msgType.indexOf(" ") >= 0) msgType = msgType.substr(0, msgType.indexOf(" ")); //strip namespace declaration
if (msgType.indexOf("_") >= 0) msgType = msgType.substr(0, msgType.lastIndexOf("_"));//strip port operation
divePS = soapBody.GetChild(j); //.GetChild(0)
while (divePS.GetType().indexOf("ListOf") < 0 && dives <= max) {
logVars("Current Dive Type", divePS.GetType(), 5);
if (divePS.GetChildCount() > 0) {
divePS = divePS.GetChild(0);
dives++;
} else dives = max + 1;
}
if (divePS.GetType().indexOf("ListOf") >= 0) parseInterface(divePS, parseResults);
else parseInterface(soapBody, parseResults);
}
break;
}
}
} catch(e) {
//If an error occurs while parsing, just try to write the message whole
}
if (msgType != "") {
msgType = msgType.replace(/_spc/g, "");
key = msgType+"_"+key;
}
TheApplication().SetProfileAttr("InterfaceKeyInbound", key)
logInterface(key, soapEnv, null, null, parseResults.recId, parseResults.recBC, "Pending", msgType, null, null, null, null, parseResults.ref1);
} // Inputs.GetChildCount()
Outputs.InsertChildAt(soapEnv,0);
} catch(e) {
RaiseError(e);
} finally {
divePS = null;
soapBody = null;
soapEnv = null;
parseResults = null;
logUnstack(msgType, 5);
}
}

CMI Utilities
logResponse
function logResponse(Inputs,Outputs)
{
/* ***********************************
Created by Mik Branchaud on 09/20/11
Purpose: Log interface response from/to an external interface in the session log
Usage: In Web Service definition, operations applet, set the Response Filter BS to 'CMI Utilities'
and the method to logResponse. Clear the cache
Arguments: 1 - SoapMessage will implicily be passed as a child property set
**************************************** */
try {
logStack("logResponse", 5);
//TheApplication().TraceOn("/opt/siebel81/siebsrvr/enterprises/SBA_81/edad669/log/XTrace-Resp-"+TheApplication().LoginName()+".log", "Allocation", "All");
var soapEnv, soapBody, divePS;
var bodyType="";
var msgType="";
var parseResults = new Object();
var fault=null;
var key = TheApplication().GetProfileAttr("InterfaceKeyInbound");
var max = 3;
var dives = 0;
if(Inputs.GetChildCount() > 0) {
try { // Try to process the message to get functional data
// Get the SOAP envelope from the SOAP hierarchy
soapEnv = Inputs.GetChild(0);
logVars("soapEnv Child Count", soapEnv.GetChildCount(), 5);
for (var i=0; i < soapEnv.GetChildCount(); i++) {
bodyType = soapEnv.GetChild(i).GetType();
logVars("soapEnv Child Type", bodyType, 5);
if (bodyType.toUpperCase() == "BODY" || bodyType.substr(bodyType.indexOf(":")+1).toUpperCase() == "BODY") {
soapBody = soapEnv.GetChild(i);
for (var j=0; j < soapBody.GetChildCount(); j++) {
msgType = soapBody.GetChild(j).GetType();
logVars("Body Child Type", msgType, 5);
if (msgType.indexOf(":") >= 0) msgType = msgType.substr(msgType.indexOf(":")+1)
if (msgType.indexOf(" ") >= 0) msgType = msgType.substr(0, msgType.indexOf(" "))
if (msgType.indexOf("_") >= 0) msgType = msgType.substr(0, msgType.lastIndexOf("_"))
if (msgType.toUpperCase() == "FAULT") fault = soapBody.GetChild(j).GetProperty("faultstring");
else {
divePS = soapBody.GetChild(j);
while (divePS.GetType().indexOf("ListOf") < 0 && dives <= max) {
logVars("Current Dive Type", divePS.GetType(), 5);
if (divePS.GetChildCount() > 0) {
divePS = divePS.GetChild(0);
dives++;
} else dives = max + 1;
}
if (divePS.GetType().indexOf("ListOf") >= 0) parseInterface(divePS, parseResults);
}
}
break;
}
}
} catch(e) {
//If an error occurs while parsing, just try to write the message whole
}
logVars("key", key, "Fault", fault, 5);
if (key == "") {
key = TheApplication().Utility.TimeStamp();
if (msgType != "") {
msgType = msgType.replace(/_spc/g, "");
key = msgType+"_"+key;
}
}
if (fault != null) {
logInterface(key, null, soapEnv, null, parseResults.recId, parseResults.recBC, "error", null, null, fault);
} else {
var recId = (parseResults.recId != "" ? parseResults.recId : null);
var recBC = (parseResults.recBC != "" ? parseResults.recBC : null);
var ref1 = (parseResults.ref1 != "" ? parseResults.ref1 : null);
logInterface(key, null, soapEnv, null, recId, recBC, "Complete", msgType, null, null, null, null, ref1);
}
} // Inputs.GetChildCount()
Outputs.InsertChildAt(soapEnv,0);
} catch(e) {
RaiseError(e);
} finally {
divePS = null;
soapBody = null;
soapEnv = null;
parseResults = null;
logUnstack(msgType, 5);
}
}

CMI Utilities
logStack
function logStack() {
/* ***********************************
Created by Mik Branchaud on 09/20/11
Purpose: Indents the session log, increments the function stack and displays the object/method. For Write,
Invoke, and Delete methods, also displays the row id. Defaults to log level 1
Usage: TheApplication().Utility.logStack("FunctionName", this);
Arguments: 1 - Name of the Method
2 - (OPTIONAL) Object Reference - used to append the name and row id where appropriate
3 - (OPTIONAL) Boolean - True (default) indicates the stack will be displayed in the log
- False will add the function to the stack but not log it. this is useful
PreInvoke/PreSet so if an error occurs function info will be captured
4 - (OPTIONAL) Log Level - To log this event at a lower/higher level
**************************************** */
gsLogCurObjMethod = arguments[0];
gsLogCurAction = "Stack";
//TheApplication().Trace("logStack - gsLogCurObjMethod "+gsLogCurObjMethod)
var display = "";
var output = true
gsLogCurObjName = "";
var recordId = "";
var suffix = "";
var Lvl = 1;
for (var i=1; i <= arguments.length - 1; i++) {
if (typeof(arguments[i])=="object") {
gsLogCurObjName = arguments[i].Name();
//Business Services and BCs with no record in context will cause an error here. It can be ignored
try { recordId = arguments[i].GetFieldValue("Id");
gsLogCurRecordId = recordId;
} catch(e) {}
} else if (typeof(arguments[i])=="bool") output = arguments[i];
else if (typeof(arguments[i])=="number") Lvl = arguments[i];
}
if (gsLogCurObjMethod.indexOf("Write") >= 0 || gsLogCurObjMethod.indexOf("Delete") >= 0 || gsLogCurObjMethod.indexOf("Invoke") >= 0 )
suffix = (recordId == "" ? "" : " for Id "+gsLogCurRecordId);
display = (gsLogCurObjName == "" ? gsLogCurObjMethod : gsLogCurObjName+"." + gsLogCurObjMethod + suffix)
display = (output == true ? display : "> " + display);
gaFunctionStack.push(display);
gaFunctionStackLog.push(Lvl);
gsIndent = "".rPad(giIndent*gaFunctionStack.length, ' ');
giErrorStack=0;
//TheApplication().Trace("gCurrentLogLvl: "+gCurrentLogLvl+" - Lvl: "+Lvl);
if (gCurrentLogLvl >= Lvl) {
//TheApplication().Trace("Function: "+display);
if (output == true) {
//If a stack happens in a PreEvent, add the prevent lines to the buffer count. The PreEvent log lines will be written in the logStep call since the
//preceeding PreEvent is not empty
giLogLines += giPreEventLines;
giPreEventLines = 0;
//keep the log compact for Set/PreSet events
if (gsLogCurObjMethod.substring(0,3) == "Set" || gsLogCurObjMethod.substring(0,6) == "PreSet") {
logStep(">- "+display, Lvl);
gLastLogLength = display.length + 3;
} else {
logStep(">".rPad(100, "-"), Lvl);
logStep("Function: "+display, Lvl);
gLastLogLength = display.length + 10;
//if a stack entered into the log, set variable to mark the beginning. If no additional entries are made before
//the next unstack, then just append the stack entry with the return rather than making an unstack entry to
//conserve space
gLastLogAction = "Stack";
}
gLastLogObject = gsLogCurObjName;
gLastLogMethod = gsLogCurObjMethod;
}
}
gsLogCurAction = "";
}

CMI Utilities
logStartStack
function logStartStack () {
/* ***********************************
Created by Mik Branchaud on 09/20/11
Purpose: Indents the session log, increments the function stack and displays the object type/object name/
method. Different visual indicator from logStack. Defaults to log level 1
Usage: TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
Arguments: 1 - Object Type
2 - Name of the Object
3 - Name of the method
4 - (OPTIONAL) Log Level - To log this event at a lower/higher level
**************************************** */
//TheApplication().Trace("logStack - objName.gsLogCurObjMethod = "+objName+"."+gsLogCurObjMethod)
var Lvl = (arguments.length > 3 ? arguments[1] : 1);
gsLogCurObjMethod = (arguments.length > 2 ? arguments[2] : "");
gsLogCurObjName = arguments[1];
gsLogCurObjType = arguments[0];
var duplicate = false;
gsLogCurAction = "StartStack";
switch (gsLogCurObjType) {
case "DVM":
case "Workflow Process":
//Since vanilla services return errors beween the PreInvoke and Invoke without triggering the catch of either
//reexecuting the same process after fixing a problem will result in a duplicate stack with no unstack
//therefore check the stack and only allow once
for (var i=0; i <= gaFunctionStack.length; i++) {
if (gaFunctionStack[i] == "== "+gsLogCurObjType+"."+gsLogCurObjName+"."+gsLogCurObjMethod) {
duplicate = true;
break;
}
}
break;
case "Navigate":
//this type is used to log view navigation. Do not create a stack entry at all as there will be no unstack
duplicate = true;
break;
}
if (!duplicate) {
gaFunctionStack.push("== "+gsLogCurObjType+"."+gsLogCurObjName+"."+gsLogCurObjMethod);
gaFunctionStackLog.push(Lvl);
gsIndent = "".rPad(giIndent*gaFunctionStack.length, ' ');
gStack.Type = gsLogCurObjType;
gStack.Name = gsLogCurObjName;
giErrorStack=0;
}
//TheApplication().Trace("gCurrentLogLvl: "+gCurrentLogLvl+" - Lvl: "+Lvl);
if (gCurrentLogLvl >= Lvl) {
switch (gsLogCurObjType) {
case "DVM":
if (!duplicate) {
logStep("--> "+gsLogCurObjType+"."+gsLogCurObjName+"."+gsLogCurObjMethod, Lvl);
}
break;
case "Workflow Process":
if (!duplicate) {
logStep("".rPad(100, "-"), Lvl);
logStep("".rPad(100, "-"), Lvl);
logStep(gsLogCurObjType+": "+gsLogCurObjMethod, Lvl);
}
break;
case "Navigate":
//Clear the current record ID so that sessions are not tied to every record the user navigates to
gsLogCurRecordId = "";
logStep(">>>>> NAVIGATE to "+gsLogCurObjName);
break;
default:
logStep("".rPad(100, "-"), Lvl);
logStep("".rPad(100, "-"), Lvl);
logStep(gsLogCurObjType+": "+gsLogCurObjName, Lvl);
logStep("Method: "+gsLogCurObjMethod, Lvl);
}
}
gLastLogAction = "Stack";
gLastLogObject = gsLogCurObjName;
gLastLogMethod = gsLogCurObjMethod;
gsLogCurAction = "";
gsLogCurObjType = "";
}

CMI Utilities
logStep
function logStep () {
/* ***********************************
Created by Mik Branchaud on 09/20/11
Purpose: Log a custom expression to the session log. Defaults to log level 3
Usage: TheApplication().Utility.logStep("Found ("+rowId+")");
Arguments: 1 - Expression
2 - (OPTIONAL) Log Level - To log this event at a lower/higher level.
3 - (OPTIONAL) Boolean - False (default) writes every call to this function to a new line
- True will append the text to the previous line
**************************************** */
var logLevel = (arguments.length > 1 ? arguments[1] : 3);
if ((logLevel == 0)||(gCurrentLogLvl >= logLevel)) {
var text = arguments[0];
var append = (arguments.length > 2 ? arguments[2] : false);
//Add a blank line after a stack/unstack entry if this is not an empty stack and not a view Navigation
if (gLastLogAction != "Step" && !append && gsLogCurObjType != "Navigate") text = "\n"+text;
var stamp = TimeStamp("DateTimeMilli")+" "+gsIndent;
var cr = (giLogLines == 0 && giPreEventLines == 0 && gsLogMode == "DB" ? "" : "\n");
var prefix = (append ? "" : cr + stamp);
//TheApplication().Trace("append: "+append+" - Last Type: "+gsLogCurObjType+" - Last Log: "+gLastLogAction+" - Lines: "+giLogLines+"/"+giPreEventLines+" - Last/Current: "+gLastLogObject+" ("+gLastLogMethod.indexOf("PreWrite")+"/"+gLastLogMethod.indexOf("Write")+") / "+gsLogCurObjName+" ("+gsLogCurObjMethod.indexOf("PreWrite")+"/"+gsLogCurObjMethod.indexOf("Write")+") - logStep: "+text);
//Cache the log lines of the PreWrite event to conditionally write them only if more information is written in this event
if (gsLogCurObjMethod.indexOf("PreWrite") == 0 && giPreEventLines <= maxPreEventLines) {
if (!append) giPreEventLines++;
gsPreEventCache += prefix + text.replace(/\n/g, "\n"+stamp);
} else {
//If processing the same object, the Write Event immediately succeeding the PreWrite, and only the Stack lines have been
//logged for the PreWrite, then do not log the prewrite information since it will be duplicated when logging for the Write
if (giPreEventLines <= 2 && gLastLogMethod.indexOf("PreWrite") == 0 &&
gLastLogObject == gsLogCurObjName && gsLogCurObjMethod.indexOf("Write") == 0) {
gsPreEventCache = "";
if (giLogLines == maxPreEventLines) prefix = (gsLogMode == "DB" ? "" : "\n")+stamp; //If the preevent cache starts a new buffer segment, insure there is no leading CR
} else {
gsLogCache += gsPreEventCache;
gsPreEventCache = "";
}
//Delay the buffer dump for EAI sessions until after they are merged with the guest session
//If this Step is called from a Stack, delay the dump so that if there are no lines before the unstack, the append return (<<)
//will concatenate to the Stack line
if (giLogLines >= giLogBuffer && gsLogCurAction != "Stack" && gsMergeGuestSessions != "TRUE") {
if (gsLogMode == "DB") {
//If a Transaction is in progress, hold all Logging until it is complete. Controlled by 'EAI Transaction Service'
if (!gHoldBuffer) {
logInsert(gsLogCache+prefix+text.replace(/\n/g, "\n"+stamp));
giLogLines = 0;
gsLogCache = "";
} else {
giLogLines++;
gsLogCache += prefix + text.replace(/\n/g, "\n"+stamp);
}
} else {
logWrite(gsLogCache+prefix +text.replace(/\n/g, "\n"+stamp));
giLogLines = 0;
gsLogCache = "";
}
} else {
giLogLines++;
gsLogCache += prefix + text.replace(/\n/g, "\n"+stamp);
}
}
gLastLogAction = "Step";
}
}

CMI Utilities
logUnstack
function logUnstack() {
/* ***********************************
Created by Mik Branchaud on 09/20/11
Purpose: Outdents the session log, decrements the function stack, displays the object/method left and
returning to. Defaults to log level 1
Usage: TheApplication().Utility.logUnStack(retValue);
Arguments: 1 - (OPTIONAL) variable being returned
2 - (OPTIONAL) Log Level - To log this event at a lower/higher level. Must specify argument 1
to use ("", 2)
**************************************** */
var text = (arguments.length > 0 ? arguments[0] : "");
var stackLength = gaFunctionStack.length;
var objMethod = gaFunctionStack.pop();
var stackLogLvl = gaFunctionStackLog.pop();
var Lvl = (arguments.length > 1 ? arguments[1] : stackLogLvl);
var outputString = "";
gsLogCurAction = "Unstack";
//if Session logging level is valid, there are functions remaining in the stack, and the stacked function did not set display to false
//TheApplication().Trace("Unstack: "+objMethod+" gLastLogAction: "+gLastLogAction+" stackLength: "+stackLength+" Lvl: "+Lvl+" text: "+text);
if ((gCurrentLogLvl >= Lvl)&&(stackLength>0)&&(objMethod.substring(0,2) != "> ")) {
if (text != "") outputString = " - Return: "+ToString(text);
//TheApplication().Trace("Unstack: "+objMethod+" gLastLogAction: "+gLastLogAction);
if (gLastLogAction != "Stack") {
logStep("---End "+objMethod+outputString, Lvl); //remove line break +"\n"
}
}
stackLength = gaFunctionStack.length;
gsIndent = "".rPad(giIndent*stackLength, ' ');
//if Session logging level is valid...
if (gCurrentLogLvl >= Lvl) {
//if there are functions remaining in the stack, and the stacked function did not set display to false
//TheApplication().Trace("objMethod.substring(0,2): "+objMethod.substring(0,2)+" stackLength: "+stackLength);
if (stackLength>0&&(objMethod.substring(0,2) != "> ")) {
//If no logging has occurred since the last stack, save logging space by making the stack/unstack a single line
if (gLastLogAction == "Stack") {
logStep(outputString.rPad(100 - gLastLogLength, "<"), Lvl, true);
} else {
logStep("<<-Returning to Function "+gaFunctionStack[stackLength-1], Lvl);
}
gLastLogAction = "Unstack";
} else if (objMethod.substring(0,2) != "> ") {
//There are no functions in the stack but still might want to print a Return value
//If no logging has occurred since the last stack, save logging space by making the stack/unstack a single line
if (gLastLogAction == "Stack") {
logStep(outputString.rPad(100 - gLastLogLength, "<"), Lvl, true);
}
gLastLogAction = "Unstack";
}
//limit number of records in session log table so only dump the buffer, triggering an insert at the end of Commits & function calls
if ((gIntermediateBufferDump == "TRUE") &&
((objMethod.indexOf(".Delete") >= 0 ||
(objMethod.indexOf(".Write") >= 0 && stackLength <= 1) ||
objMethod.indexOf("Invoke") >= 0 || objMethod.indexOf("==") >= 0))) {
DumpBuffer();
}
}
gsLogCurAction = "";
}

CMI Utilities
logVars
function logVars () {
/* ***********************************
Created by Mik Branchaud on 09/20/11
Purpose: Log field/value pairs to the session log. Defaults to log level 3
Usage: TheApplication().Utility.logVars("Variable 1", var1, "Variable 2", var2);
Arguments: 1 - Functional Description of the expression
2 - Expression
.... (repeat in pairs)
n - (OPTIONAL) Log Level - To log this event at a lower/higher level.
**************************************** */
var Args = arguments.length;
var iLvl = (Args % 2 == 0 ? 0 : arguments[Args - 1]);
if ((iLvl == 0)||(gCurrentLogLvl >= iLvl)) {
var iParams = (Args % 2 == 0 ? Args : Args - 1);
var sProp, sValue;
for (var i=0; i < iParams; i++) {
sProp = arguments[i++]+": ";
sValue = arguments[i];
logStep(sProp.lPad(giPadVars,".")+sValue, iLvl);
}
}
}

CMI Utilities
logWrite
function logWrite() {
var fp;
for (var i=0; i < arguments.length; i++) {
//Log text to a file name with path derived from System parameter
switch (gWriteMode) {
case "Path":
try {
fp = Clib.fopen(gsOutPutFileName, "a");//
Clib.fputs(arguments[i], fp);
Clib.fclose(fp);
} catch(e) {
//an error could occur if the path is not accessible or invalid, so log to just the filename in the siebel root (BIN)
try {
fp = Clib.fopen(gsFileName, "a");//
Clib.fputs(arguments[i], fp);
Clib.fclose(fp);
gWriteMode = "FileName";
} catch(e) {
//an error could occur if ...
try {
TheApplication().TraceOn(gsOutPutFileName, "Allocation", "All");
TheApplication().Trace(arguments[i]);
gWriteMode = "TracePath";
} catch(e) {
TheApplication().TraceOn(gsFileName, "Allocation", "All");
TheApplication().Trace(arguments[i]);
gWriteMode = "TraceFileName";
}
}
}
break;
case "FileName":
fp = Clib.fopen(gsFileName, "a");//
Clib.fputs(arguments[i], fp);
Clib.fclose(fp);
break;
case "TracePath":
case "TraceFileName":
TheApplication().Trace(arguments[i]);
break;
}
}
fp = null;
}

CMI Utilities
parseInterface
function parseInterface(ListOfIC, oReturn) { //Input ListOfIC is a ListOf...
//Called from logRequest and logResponse to parse a message and get the row id or reference ids of different
//objects
try {
logStack("parseInterface", 5);
if (ListOfIC.GetChildCount() > 0) {
var IC = ListOfIC.GetChild(0); //Integration Component Instance
var icNameSpace = "";
var intCompType = IC.GetType();
var propName;
var stop = false;
var childIC;
var childFlds;
if (intCompType.indexOf(":") >= 0) {
icNameSpace = intCompType.substr(0, intCompType.indexOf(":")+1);
intCompType = intCompType.substr(intCompType.indexOf(":")+1);
}
logVars("Integration Component", intCompType, "Namespace", icNameSpace, 5);
//For these types, dive an additional level
switch(intCompType) {
case "ATPCheckInterfaceRequestOrders":
IC = IC.GetChild(0);
intCompType = IC.GetType();
if (intCompType.indexOf(":") >= 0) {
icNameSpace = intCompType.substr(0, intCompType.indexOf(":")+1);
intCompType = intCompType.substr(intCompType.indexOf(":")+1);
}
logVars("Integration Component", intCompType, "Namespace", icNameSpace, 5);
break;
}
for (var flds = 0; flds < IC.GetChildCount(); flds++) { //Loop through Fields
propName = IC.GetChild(flds).GetType();
switch (intCompType) {
case "InsClaims":
case "INSClaims":
oReturn.recBC = "INS Claims";
if (propName == icNameSpace+"Id") {
oReturn.recId = IC.GetChild(flds).GetValue();
stop = true;
}
break;
case "DecisionServiceRequest":
oReturn.recBC = "Service Request";
if (propName == icNameSpace+"DecisionID") {
oReturn.recId = IC.GetChild(flds).GetValue();
stop = true;
}
break;
case "ATPHeader":
oReturn.recBC = "Quote";
if (propName == icNameSpace+"HeaderRowId") {
oReturn.recId = IC.GetChild(flds).GetValue();
stop = true;
}
break;
case "OrganizationPaymentProfile":
oReturn.recBC = "Account";
if (propName == icNameSpace+"PersonId") {
oReturn.recId = IC.GetChild(flds).GetValue();
stop = true;
}
break;
case "Quote":
case "SWIQuote":
oReturn.recBC = "Quote";
if (propName == icNameSpace+"Id") {
oReturn.recId = IC.GetChild(flds).GetValue();
stop = true;
}
break;
case "CmiParentServiceRequest":
oReturn.recBC = "Service Request";
if (propName == icNameSpace+"Id"){
oReturn.recId = IC.GetChild(flds).GetValue();
stop = true;
}
break;
case "Account":
oReturn.recBC = "Account";
if (propName == icNameSpace+"Id" || propName == icNameSpace+"RowId") {
oReturn.recId = IC.GetChild(flds).GetValue();
stop = true;
}
break;
case "InternalProduct":
oReturn.recBC = "Internal Product";
if (propName == icNameSpace+"Id") {
oReturn.recId = IC.GetChild(flds).GetValue();
stop = true;
}
break;
case "ProductDefinition":
oReturn.recBC = "Internal Product";
if (propName == icNameSpace+"ProductId") {
oReturn.recId = IC.GetChild(flds).GetValue();
stop = true;
}
break;
case "ProductIntegration":
oReturn.recBC = "Internal Product";
if (propName == icNameSpace+"ListOfProductDefinition") {
childIC = IC.GetChild(flds).GetChild(0);
for (childFlds = 0; childFlds < childIC.GetChildCount(); childFlds++) { //Loop through Fields
propName = childIC.GetChild(childFlds).GetType();
if (propName == icNameSpace+"Id" || propName == icNameSpace+"ProductId") {
oReturn.recId = childIC.GetChild(childFlds).GetValue();
stop = true;
}
if (stop) break;
}
}
break;
case "SWIOrder":
oReturn.recBC = "Order Entry - Orders";
if (propName == icNameSpace+"Id") {
oReturn.recId = IC.GetChild(flds).GetValue();
stop = true;
}
break;
default:
logVars("Integration Component", intCompType, "Default", icNameSpace+"Id", 4);
if (propName.indexOf("Id") >= 0) {
oReturn.recId = IC.GetChild(flds).GetValue();
stop = true;
}
oReturn.recBC = intCompType;
stop = true;
}
if (stop) break;
}
}
} catch(e) {
RaiseError(e);
} finally {
childIC = null;
IC = null;
logUnstack("", 5);
}
}

CMI Utilities
splitPayload
function splitPayload(bc, fieldName, ps, maxLength)
{
try {
logStack("splitPayload", 5);
var psIn = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();
var bsService = TheApplication().GetService ("XML Converter (Data in Child PropSet)");
psIn.SetProperty("EscapeNames", "False");
var text:String = "";
var stripPS = false;
var textPS = "";
psIn.AddChild(ps);
bsService.InvokeMethod("PropSetToXML", psIn, psOut);
textPS = ToString(psOut);
logVars(fieldName+" textPS.length", textPS.length);
while (textPS.length > 0) {
bc.NewRecord(NewAfter);
bc.SetFieldValue("Field", fieldName);
bc.SetFieldValue("Log Text", textPS.substring(0, maxLength));
//Service adds a Prefix that needs to be removed
text = bc.GetFieldValue("Log Text");
text = text.lTrim();
if (text.substring(0, 14) == "PropertySet [ ") {
stripPS = true;
text = text.substring(14);
}
textPS = textPS.substring(maxLength, textPS.length);
logVars(fieldName+" textPS.length", textPS.length);
//If the Text is broken up across multiple records, need to remove the trailing ] from the last record
if (stripPS && textPS.length < maxLength) {
text = text.rTrim("]");
}
bc.SetFieldValue("Log Text",text);
bc.WriteRecord();
}
} catch (e) {
throw(e);
} finally {
psOut = null;
psIn = null;
bsService = null;
logUnstack("", 5);
}
}

CMI Utilities
stripErrorMessage
function stripErrorMessage(Inputs, Outputs)
{
try {
logStack("stripErrorMessage", 4);
//Set User Error Message
var sValue = Inputs.GetProperty("Error Message");
var sReturn, sSearch;
Outputs.SetProperty("Error Message", sValue);
Outputs.SetProperty("Message", "");
logVars("Error Message", sValue, 4);
if (sValue.indexOf("Error invoking") >= 0) {
//Strip workflow structure specific messaging
sReturn = sValue.substring(sValue.indexOf("returned the following error:")+30);
logVars("Strip Prefix", sReturn, 4);
//Strip trailing error codes
sReturn = sReturn.replace(/\(SBL-...-.....\)/ig, "");
logVars("Return Message", sReturn, 4);
sSearch = sValue.substring(sValue.indexOf("record with search specification")+33,
sValue.indexOf(" returned the following error:")+1);
logVars("Message Key", sReturn, 4);
Outputs.SetProperty("Message", sSearch);
}
} catch(e) {
RaiseError(e);
} finally {
logUnstack("", 4);
}
}

CMI Utilities
StringToDate
function StringToDate() {
//Use: Frame.StringToDate(sDate: A string with format "mm/dd/yyyy" or "mm/dd/yyyy hh:mi:ss"
//Returns: a Date Object
var sDate = arguments[0];
var aDateTime = new Array();
aDateTime = sDate.split(" ");
sDate = aDateTime[0];
var aDate = sDate.split("/");
if (aDateTime.length==1) return (new Date(ToNumber(aDate[2]), ToNumber(aDate[0])-1, ToNumber(aDate[1])));
else {
var ArTime = aDateTime[1];
var aTime = ArTime.split(":");
//new Date(iYear, iMonth, iDay)
if (aTime[0]=="00" && aTime[1]=="00" && aTime[2]=="00")
return (new Date(ToNumber(aDate[2]), ToNumber(aDate[0])-1, ToNumber(aDate[1])));
else {
return (new Date(ToNumber(aDate[2]), ToNumber(aDate[0])-1, ToNumber(aDate[1]),
ToNumber(aTime[0]), ToNumber(aTime[1]), ToNumber(aTime[2])));
}
}
aDateTime = null;
aDate = null;
aTime = null;
}

CMI Utilities
SetSysPref
function SetSysPref( sPreference, sValue ) {
//Use: Frame.SetSysPref( sPreference: the preference name in the system preference view,
// sValue: the value of the preference )
var boPref = TheApplication().GetBusObject("System Preferences");
var bcPref = boPref.GetBusComp("System PreferencesUpd");
with (bcPref) {
ClearToQuery();
ActivateField("Value");
SetSearchSpec("Name", sPreference);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) SetFieldValue("Value", sValue);
else {
NewRecord(NewBefore);
SetFieldValue("Name", sPreference);
SetFieldValue("Value", sValue);
WriteRecord();
}
}
bcPref = null;
boPref = null;
}

CMI Utilities
UTF8fromString
function UTF8fromString(utfString)
{
// For Binary, Message must be in Value and can not be moved
try
{
var psIn = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();
var bsService = TheApplication().GetService ("Transcode Service");
psIn.SetProperty("ConversionMode", "StringToEncoding");
psIn.SetProperty("TargetEncoding", "UTF-8");
psIn.SetValue(utfString);
bsService.InvokeMethod("Convert", psIn, psOut);
}
catch(e) {
RaiseError(e);
} finally {
psIn = null;
psOut = null;
bsService = null;
}
return(psOut);
}

CMI Utilities
RefreshLogPrefs
function RefreshLogPrefs(mode)
{
if (mode == "Init") {
//Preference to log all interface requests and responses
gsTraceIntfaceReqResp = GetSysPref("CMI Trace eScript Req-Resp");
switch (gsTraceIntfaceReqResp.toUpperCase()) {
case "": case "NO": case "N": case "FALSE":
gsTraceIntfaceReqResp = "FALSE";
break;
default:
gsTraceIntfaceReqResp = "TRUE";
}
//Log Buffer is the number of lines more than which the log cache will be written out
giLogBuffer = GetSysPref("CMI Log Buffer");
giLogBuffer = (giLogBuffer == "" ? "100" : giLogBuffer);
//Get the System Preference Log Level. Get the Log Level set for this user (if provided)
//and then set the log level for this session
gSysLogLevel = GetSysPref("CMI Current Log Level");
gSysLogLevel = (gSysLogLevel == "" ? "0" : gSysLogLevel);
//In the thick client and when troubleshooting it is sometimes helpful to write the script log out after every
//record write or method invokation to insure data in the buffer relevant to the error is not lost. To optimize
//performance this can be turned off. Turning off will reduce the linking between session logs and the affected
//record
gIntermediateBufferDump = GetSysPref("CMI Intermediate Buffer Dump");
gIntermediateBufferDump = (gIntermediateBufferDump == "" ? "TRUE" : gIntermediateBufferDump.toUpperCase());
}
if (TheApplication().GetProfileAttr("CMI User Log Level") != "")
gCurrentLogLvl = TheApplication().GetProfileAttr("CMI User Log Level");
else gCurrentLogLvl = gSysLogLevel;
}

CMI Utilities
BCFlushObjects
function BCFlushObjects()
{
logStack("Bc_FlushObjects", 1);
for (var bo in storeBOs) {
bo = null;
}
for (var bc in storeBCs) {
bc = null;
}
storeBOs = [];
storeBCs = [];
logUnstack("",5);
}

CMI Utilities
BCGetArray
function BCGetArray() {
//--------------------------------------------------------------------------------------
//14/01/2010 Query any BC, return zero to many records (array)
//arguments:
// BoName.BcName: String || BcName:BusComp
// Id/Search Expression: String
// Field/Fields: (String) or (Array of Strings) [field, field2, ... fieldn] (w/ optional datatype)
// <Optional> ResetContext: Boolean
// <Optional> SelectMultiple: Boolean
//returns:
// Array with:
// 0 to many records (Object)
// {field1:val1, field2:val2, field3:val3... fieldn:valn}
//----------------------------------------------------------------------------------------*/
// logStack("BCGetArray",5);
var aReturn = [];
var sSearch = arguments[1];
var bResetContext = (arguments.length >= 4 ? arguments[3] : false) ;
var bSelectMultiple = (arguments.length == 5 ? arguments[4] : true) ;
var bIsRecord = false;
var iRowCount = 0;
var aFields = [];
var oBo:BusObject = null;//
var oBc:BusComp = null;//
//if fieldname given convert to array and add system fields, else (array given) append system fields
if (typeof(arguments[2])=="string") {
// don't add empty string
if (arguments[2].length>0) aFields = [arguments[2]].concat(["Id","Created:Date","Updated:Date"]);
else aFields = ["Id", "Created:Date", "Updated:Date"];
}
else aFields = arguments[2].concat(["Id", "Created:Date", "Updated:Date"]);
// logVars("aFields.length",aFields.length,"aFields",aFields, 5);
try {
// logVars("Search",arguments[1],"Reset Context",bResetContext,"BC Type",typeof(arguments[0]), 5);
// if a BC.BO pair given instantiate objects, otherwise use passed in object
if (typeof(arguments[0])=="string") {
// get BusObject Name and BusComp name
var a_sBoDotBc = arguments[0].split(".");
var sBoName = a_sBoDotBc[0];
var sBcName = a_sBoDotBc[1];
// if (bResetContext) this.BCFlushObjects();
// see if we already have the BO in the 'pool' (or have been told to reset context)
// if not in the pool create and add, so available for next time
if (storeBOs[sBoName] == null || bResetContext) {
oBo = TheApplication().GetBusObject(sBoName);
storeBOs[sBoName] = oBo;
}
else oBo = storeBOs[sBoName];
// same for Bc
if (storeBCs[sBcName] == null || bResetContext) {
oBc = oBo.GetBusComp(sBcName);
storeBCs[sBcName] = oBc;
}
else oBc = storeBCs[sBcName];
}
else {
oBc = arguments[0];
// logStep("Grabbed BusComp " + oBc.Name() + " from the function call.",5);
}
with(oBc) {
// activate all required fields. Array will contain passed fields plus system fields
// Id, Created and Updated
// --> the replace is to remove any of the type values, e.g. :Date
for (var i=0; i<aFields.length; i++) {
if (aFields[i].indexOf(":") == -1) aFields[i] += ":String";
aFields[i] = aFields[i].split(":");
ActivateField(aFields[i][0]);
}
ClearToQuery();
SetViewMode(AllView);
// either query using Id or expression if provided
(arguments[1].indexOf("[")==-1) ? SetSearchSpec("Id", arguments[1]) : SetSearchExpr(arguments[1]);
ExecuteQuery(ForwardOnly);
bIsRecord = FirstRecord();
while(bIsRecord==true) {
var aRow = {};
for (i=0; i<aFields.length; i++) {
var vValue;
// see if typing is being used
switch (aFields[i][1]) {
case "Date":
vValue = new Date();
vValue = vValue.setFromString(GetFormattedFieldValue(aFields[i][0]));
break;
case "Number":
vValue = ToNumber(GetFieldValue(aFields[i][0]));
break;
case "Boolean":
vValue = (GetFieldValue(aFields[i][0])=="N") ? false : ToBoolean(GetFieldValue(aFields[i][0]));
break;
case "String":
default:
vValue = GetFieldValue(aFields[i][0]);
break;
}
// if any of the field names have spaces subsitute with _
// so their values can be accessed using the . operator
// on the object returned
aRow[aFields[i][0].spaceToUnderscore()]= vValue;
}
// move on to next record
bIsRecord = NextRecord() && bSelectMultiple;
// increment iRowCount *after* assigning that record
// to the array of records
aReturn[iRowCount++] = aRow;
aRow = null;
}
}
}
catch(e) {
RaiseError(e);
}
finally {
// logUnstack(aReturn,5);
oBc = null;
oBo = null;
}
return aReturn;
}

CMI Utilities
CallWF
function CallWF() {
// Use : Frame.CallWF (Object Id : string
// ProcessName : Name of Workflow Process to call
// Repeat Pass Through Field : Workflow process property name
// Repeat Pass Through Value : Workflow process property value
// Returns : A date object, after adding/subtracting iDays, iHrs, iMin and iSec to the srcDate
try {
logStack("CallWF", 5);
var iArgs = arguments.length;
var sArguments = "";
logVars("# of Arguments", iArgs, 5);
var sRowId = (iArgs > 0 ? arguments[0] : TheApplication().GetProfileAttr("Object Id")) ;
var sProcessName = (iArgs > 1 ? arguments[1] : TheApplication().GetProfileAttr("ProcessName"));
logVars("Object Id", sRowId, "Process Name", sProcessName, 5);
sArguments += "'"+arguments[0]+"','"+arguments[1]+"','', '', '', ''";
for (var i = 2; i<iArgs; i++) sArguments += ",'"+arguments[i].replace(/'/g,'"')+"'";
logVars("Arguments", sArguments, 5);
var sCommand = "CallWFDetail("+sArguments+")";
eval(sCommand);
// Frame.CallWFDetail(arguments);
}
catch(e) {
RaiseError(e);
}
finally {
logUnstack("", 5);
}
}

CMI Utilities
CallWFDetail
function CallWFDetail() {
// Use : Frame.CallWFDetail (RowId : string
// ProcessName : Name of Workflow Process to call
// Login : LoginName of active user if asyncronous (OPTIONAL)
// Mode : Auto, Schedule, Async, Sync(OPTIONAL)
// Server : (OPTIONAL) Logical application server to run job on
// Component : (OPTIONAL) Alias of the server component to run. WfProcMgr by default
// Repeat DynamicName_# : Workflow process property name
// Repeat DynamicValue_# : Workflow process property value
try {
logStack("CallWFDetail", 5);
var iArgs = arguments.length;
var iPT = 1;
var iMaxPT = 20;
var sPropertyName, sPropertyValue, iDyn, sArgMode;
var sLogin = "";
var sRowId = "";
var sProcessName = "";
var sComp = (arguments[5] == "" ? "WfProcMgr" : arguments[5]) ;
var sMode = "";
var sServer = "";
var sValue = "";
var Inputs = TheApplication().NewPropertySet();
var psInputs = TheApplication().NewPropertySet();
var psChild = TheApplication().NewPropertySet();
var psOutputs = TheApplication().NewPropertySet();
var bsService;
with (psChild) {
//Added below lines to pass any child property set from the calling WF for example, SiebelMessage
/* for(var i=0; i < Inputs.GetChildCount() ;++i) {
sPropertyName = Inputs.GetChild(i).GetFirstProperty();
sPropertyValue = Inputs.GetChild(i).GetProperty(sPropertyName);
Log.stepVars("Message Property", sPropertyName, "Message Value", sPropertyValue, 5);
Inputs.GetChild(i).RemoveProperty(sPropertyName);
Inputs.GetChild(i).SetProperty("MessageName"+i, sPropertyValue)
AddChild(Inputs.GetChild(i));
}*/
logVars("typeof(arguments[0])",typeof(arguments[0]), "iArgs", iArgs,5);
if (iArgs > 2) {
sArgMode = "FunctionArgs";
sLogin = arguments[2];
sComp = arguments[5];
sMode = arguments[3];
sServer = arguments[4];
SetProperty("ProcessName", arguments[1]);
SetProperty("Object Id", arguments[0]);
logVars("Login", sLogin, "Mode", sMode, "Server", sServer,5);
while ((iPT < (iMaxPT*2)) && (iPT <= iArgs - 6)) {
SetProperty(arguments[iPT+5], arguments[iPT+6]);
logVars(arguments[iPT+5], arguments[iPT+6], 5);
iPT++;
iPT++
}
}
else if ((typeof(arguments[0]) == "object")&&(arguments[0].GetProperty("ProcessName") != "")) {
sArgMode = "PropertySet";
Inputs = arguments[0].Copy();
Inputs.SetType("Input Arguments");
// Log.FlatPropSet(Inputs, 5);
sPropertyName = Inputs.GetFirstProperty();
while (sPropertyName) {
if (sPropertyName == "ProcessServer") sServer = Inputs.GetProperty(sPropertyName);
else if (sPropertyName == "ProcessMode") sMode = Inputs.GetProperty(sPropertyName);
else if (sPropertyName == "Component") sComp = Inputs.GetProperty(sPropertyName);
else if (sPropertyName.indexOf("DynamicName_") >= 0) {
iDyn = sPropertyName.substring(sPropertyName.indexOf("_")+1, sPropertyName.length);
logVars("Dynamic Index", iDyn, 5);
SetProperty(Inputs.GetProperty(sPropertyName),
Inputs.GetProperty("DynamicValue_"+iDyn));
}
else if (sPropertyName.indexOf("DynamicValue_") < 0)
SetProperty(sPropertyName, Inputs.GetProperty(sPropertyName));
logVars(sPropertyName, Inputs.GetProperty(sPropertyName).substring(0, 50), 5);
sPropertyName = Inputs.GetNextProperty();
}
}
else {
sArgMode = "ProfileAttr";
sLogin = TheApplication().GetProfileAttr("ActiveLogin");
sMode = TheApplication().GetProfileAttr("ProcessMode");
sComp = TheApplication().GetProfileAttr("Component");
sServer = TheApplication().GetProfileAttr("ProcessServer");
SetProperty("ProcessName", TheApplication().GetProfileAttr("ProcessName"));
SetProperty("Object Id", TheApplication().GetProfileAttr("Object Id"));
logVars("Login", sLogin, "Mode", sMode, "Server", sServer,5);
while ((iPT < iMaxPT) && (TheApplication().GetProfileAttr("PassThrough"+iPT) != "")) {
sValue = TheApplication().GetProfileAttr("PassThrough"+iPT);
SetProperty(sValue.substring(0, sValue.indexOf(",")),
sValue.substring(sValue.indexOf(",")+1, sValue.length));
logVars(sValue.substring(0, sValue.indexOf(",")), sValue.substring(sValue.indexOf(",")+1, sValue.length), 5);
}
}
if (sLogin != "") SetProperty("ActiveLogin", sLogin);
else SetProperty("ActiveLogin", TheApplication().LoginName());
}
logVars("Mode", sMode, "Arguments Mode", sArgMode, "Component", sComp, 5);
if (sMode == "Local") {
logPS(psChild, 5);
with(psOutputs) {
SetProperty("Process Instance Id", "");
SetProperty("Error Code", "");
SetProperty("Error Message", "");
SetProperty("Siebel Operation Object Id", "");
if (psChild.GetProperty("Object Id") == "") SetProperty("Object Id", "");
}
bsService = TheApplication().GetService("Workflow Process Manager");
bsService.InvokeMethod("RunProcess", psChild, psOutputs);
logPS(psOutputs, 5);
if (sArgMode == "PropertySet") arguments[1] = psOutputs.Copy();
}
else {
with (psInputs) {
if (sServer != "") SetProperty("ServerName", sServer);
if (sMode != "") SetProperty("Mode", sMode);
else SetProperty("Mode", "Auto");
if (sComp != "") SetProperty("Component", sComp);
else SetProperty("Component", "WfProcMgr");
AddChild(psChild);
}
logPS(psInputs, 5);
bsService = TheApplication().GetService("Server Requests");
bsService.InvokeMethod("SubmitRequest", psInputs, psOutputs);
logPS(psOutputs, 5);
}
}
catch(e) {
RaiseError(e);
}
finally {
logUnstack("", 5);
psChild = null;
psInputs = null;
psOutputs = null;
bsService = null;
}
}

CMI Utilities
ComputerName
function ComputerName()
{
try {
var computerName = TheApplication().GetProfileAttr("ComputerName");
if(computerName == "") {
var wshShell = COMCreateObject("WScript.Shell");
computerName = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%");
TheApplication().SetProfileAttr("ComputerName", computerName);
}
}
catch(e) {
RaiseError(e);
}
return (computerName);
}

CMI Utilities
ConcatenateField
function ConcatenateField(Inputs, Outputs) {
//Inputs: bo.bc "boName.bcName"
// FieldName
// SearchExpr BC Search Expression (Optional)
var retValue = "";
var found = false;
var search = Inputs.GetProperty("SearchExpr");
try {
var arSplit = Inputs.GetProperty("bo.bc").split(".");
var bcQuery:BusComp;
if (arSplit[0] == "ACTIVE")
bcQuery = TheApplication().ActiveBusObject().GetBusComp(arSplit[1]);
else
bcQuery = TheApplication().GetBusObject(arSplit[0]).GetBusComp(arSplit[1]);
var delimeter = (Inputs.GetProperty("delimeter") != "" ? Inputs.GetProperty("delimeter") : "\n");
with (bcQuery) {
if (search != "") {
ClearToQuery();
arSplit = Inputs.GetProperty("SearchExpr").split("&quot;");
search = arSplit.join("'");
SetSearchExpr(search);
ActivateField(Inputs.GetProperty("FieldName"));
SetViewMode(AllView);
ExecuteQuery(ForwardOnly);
}
found = FirstRecord();
while(found) {
retValue += GetFieldValue(Inputs.GetProperty("FieldName"));
found = NextRecord();
if (found) retValue += delimeter;
}
Outputs.SetProperty("Out", retValue);
}
} catch(e) {
TheApplication().RaiseError(e);
} finally {
bcQuery = null;
arSplit = null;
}
}

CMI Utilities
DateToString
function DateToString () {
//Use: Frame.DateToString ( dDate : Date Object )
//Returns: A string with the format "mm/dd/yyyy" or "mm/dd/yyyy hh:mi:ss"
var dDate = arguments[0];
var sFormat = (arguments.length == 2 ? arguments[1] : "DateTime");
var sMon = ToString(dDate.getMonth()+1);
if (sMon.length==1) sMon = "0" + sMon;
var sDay = ToString(dDate.getDate());
if (sDay.length==1) sDay = "0" + sDay;
var sHrs = ToString(dDate.getHours());
if (sHrs.length==1) sHrs = "0" + sHrs;
var sMin = ToString(dDate.getMinutes());
if (sMin.length==1) sMin = "0" + sMin;
var sSec = ToString(dDate.getSeconds());
if (sSec.length==1) sSec = "0" + sSec;
if ((sHrs == "00" && sMin == "00" && sSec == "00") || (sFormat.toUpperCase() == "DATE"))
return(sMon+"/"+sDay+"/"+dDate.getFullYear());
else return(sMon+"/"+sDay+"/"+dDate.getFullYear()+" "+sHrs+":"+sMin+":"+sSec);
}

CMI Utilities
DumpBuffer
function DumpBuffer () {
//TheApplication().Trace("*** DumpBuffer ("+gsLogMode+"/"+gsMergeGuestSessions+"/"+gHoldBuffer+"): "+gsLogCache);
//Delay the buffer dump for EAI sessions until after they are merged with the guest session
if (gsMergeGuestSessions != "TRUE") {
//Database mode
if ((gsLogMode == "DB")&&(gsLogCache!="")) {
//If a Transaction is in progress, hold all Logging until it is complete. Controlled by 'EAI Transaction Service'
if (!gHoldBuffer) {
//Occasionally update current Employee/System Preference log settings
RefreshLogPrefs();
logInsert(gsLogCache);
giLogLines = 0;
gsLogCache = "";
}
} else {
//File Mode
if ((gsOutPutFileName != "")&&(gsLogCache!="")) {
//Occasionally update current Employee/System Preference log settings
RefreshLogPrefs();
logWrite(gsLogCache);
giLogLines = 0;
gsLogCache = "";
}
}
}
}

CMI Utilities
ExtendObjects
function ExtendObjects() {
// Created: 06/30/2010
// Description: Add any additions to base objects here
// Note1: Avoid adding methods to either Object object or Array objets - this will lead the
// function to be shown as an element if an "Array" is accessed using the for .. in
// construct
// Note2: JavaScript/ECMAScript supports the following:
// if (!<Item>.prototype.<method>) to check if the method has already been added to the
// class - eScript fallsover if this is attempted, so no checking can be done to see
// does the method exist before adding it
//
// History:
// Date Author Description
// ------------------------------------------------------------------------------------------
//Log.Stack("ExtendObjects",5);
//TheApplication().Trace("eScript Framework - ExtendObjects");
String.prototype.lPad = function(PadLength, PadChar) {
//Use: String.lPad(Number of Characters, Character to Pad)
//Returns: string with the PadChar appended to the left until the string is PadLength in length
if ((PadLength + 1) - this.length > 0)
return(Array((PadLength + 1) - this.length).join(PadChar)+this);
else return(this);
}
String.prototype.rPad = function(PadLength, PadChar) {
//Use: String.rPad(Number of Characters, Character to Pad)
//Returns: string with the PadChar appended to the right until the string is PadLength in length
if ((PadLength + 1) - this.length > 0)
return(this + Array((PadLength + 1) - this.length).join(PadChar));
else return(this);
}
String.prototype.rTrim = function() {
//Use: String.rTrim()
//Returns string trimmed of any space characters at the end of it
if (arguments.length == 0) return(this.replace(/\s*$/, ""));
else {
var i = 0;
while (this.charAt(this.length - i - 1) == arguments[0] && this.length > 0) i++;
return(this.substring(0, this.length - i));
}
}
String.prototype.lTrim = function() {
//Use: String.lTrim()
//Returns string trimmed of any white space characters at the beginning of it
if (arguments.length == 0) return(this.replace(/^\s*/, ""));
else {
var i = 0;
while ((this.charAt(i) == arguments[0]) && (this.length>0)) {
i++;
}
return(this.substring(i, this.length));
}
}
String.prototype.trim = function() {
//Use: String.trim()
//Returns string trimmed of any white space (or inputed) characters at the beginning or end
if (arguments.length == 0) return(this.replace(/^\s+|\s+$/g, ""));
else {
var i = 0;
var iBegin = 0;
var iEnd = this.length - 1;
while ((this.charAt(i) == arguments[0] && this.length>0)||
(this.charAt(this.length - i - 1) == arguments[0] && this.length>0)) {
if (this.charAt(i) == arguments[0]) iBegin = i+1;
if (this.charAt(this.length - i - 1) == arguments[0]) iEnd = this.length - i - 1;
i++;
}
return(this.substring(iBegin, iEnd));
}
}
String.prototype.spaceToUnderscore = function() {
return(this.replace(/\s+/g, "_"));
}
String.prototype.underscoreToSpace = function() {
return(this.replace(/_+/g, " "));
}
String.prototype.hasSpace = function() {
return this.match(/\s/);
}
String.prototype.escape = function() {
return("'"+this.replace(/'/g, "''")+"'");
}
String.prototype.QADDate = function() {
//Use: String.QADDate() : A string with the format "mm/dd/yyyy" or "mm/dd/yyyy hh:mm:ss"
//Returns: yyyy-mm-dd
if (this == "") return "";
else {
var sDate = this.substring(0,10);
var arDate = sDate.split("/");
return arDate[2] + "-" + arDate[0] + "-" + arDate[1];
}
}
String.prototype.QADTime = function() {
//Use: String.QADTime() : A string with the format "mm/dd/yyyy hh:mm:ss"
//Returns: Time in 24 hour format
if (this == "") return("00:00");
else if (this.length > 10) {
var arTime = this.substring(11,19).split(":");
if (arTime.length >= 2) {
var sHours = arTime[0];
if (sHours.length == 1) {sHours = "0" + sHours;}
var sMinutes = arTime[1];
if (sMinutes.length == 1) {sMinutes = "0" + sMinutes;}
var sSeconds = arTime[2];
if (sSeconds.length == 1) {sSeconds = "0" + sSeconds;}
return(sHours + ":" + sMinutes);
} else return("00:00");
} else return("00:00");
}
String.prototype.validEmail = function() {
if (this.match(/^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i)
== null) return(false);
else return(true)
}
Date.prototype.setFromString = function(pV) {
var aTs = pV.split(" ");
var aD = aTs[0].split("/");
var aT = (aTs.length > 1) ? aTs[1].split(":") : [0,0,0];
this.setFullYear(aD[2]);
this.setMonth(aD[1]-1, aD[0]);
this.setDate(aD[0]);
// return(new Date(aD[2], aD[1]-1, aD[0]);
this.setHours(aT[0], aT[1], aT[2]);
}
Date.prototype.add = function( iDays, iHrs, iMin, iSec, nSign ) {
//Use: Date.add(iDays, iHrs, iMin, iSec : Integer Numbers
// nSign : 1 or -1 {1 to ADD to the srcDate, -1 to SUBTRACT from the srcDate} )
//Returns: A date object, after adding/subtracting iDays, iHrs, iMin and iSec to the srcDate
var retDate = this;
retDate.setDate(retDate.getDate()+nSign*iDays);
retDate.setHours(retDate.getHours()+nSign*iHrs);
retDate.setMinutes(retDate.getMinutes()+nSign*iMin);
retDate.setSeconds(retDate.getSeconds()+nSign*iSec);
return(retDate);
}
/* PropertySet.prototype.setBool = function(propName, propVal) {
//Use: PropertySet.setBool(propName : property name
// propVal : Y, or a non Y value
//Returns: Property set with specified property set to TRUE or FALSE
if (sPropVal.toUpperCase() == "Y") this.SetProperty(sPropName,"TRUE");
else this.SetProperty(sPropName,"FALSE");
}
PropertySet.prototype.setInteger = function(propName, propVal) {
//Use: PropertySet.setBool(propName : property name
// propVal : a number value that might be null
//Returns: Property set with specified property set to an integer or 0
if (isNaN(sPropVal)) this.SetProperty(sPropName,"0");
else this.SetProperty(sPropName,Math.round(sPropVal));
}
PropertySet.prototype.setLeftOf = function(propName, propVal, expr) {
//Use: PropertySet.setBool(propName : property name
// propVal : a string with a character
// expr : specified character string
//Returns: Property set with specified property set to string to the left of the specified
// character. If character does not exist, than original string
if (sPropVal.indexOf(expr) != -1)
this.SetProperty(sPropName,sPropVal.substr(0,sPropVal.indexOf(expr)));
else this.SetProperty(sPropName,sPropVal);
}
PropertySet.prototype.setRightOf = function(propName, propVal, expr) {
//Use: PropertySet.setBool(propName : property name
// propVal : a string with a character
// expr : specified character string
//Returns: Property set with specified property set to string to the right of the specified
// character. If character does not exist, than original string
if (sPropVal.indexOf(expr) != -1)
this.SetProperty(sPropName,sPropVal.substr(sPropVal.indexOf(expr)+1));
else this.SetProperty(sPropName,sPropVal);
}
PropertySet.prototype.setUpperNotNull = function(propName, propVal) {
//Use: PropertySet.setBool(propName : property name
// propVal : text or empty string
//Returns: Property set with specified property set only if not empty
if (sPropVal != "") this.SetProperty(sPropName,sPropVal.toUpperCase());
}
PropertySet.prototype.setNotNull = function(propName, propVal) {
//Use: PropertySet.setBool(propName : property name
// propVal : text or empty string
//Returns: Property set with specified property set only if not empty
if (sPropVal != "") this.SetProperty(sPropName,sPropVal);
}
*/
}

CMI Utilities
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
var retValue = CancelOperation;
var param_1 = "";
var param_2 = "";
var param_3 = "";
var workFlowError = false;
if(Inputs.GetProperty("WorkflowError") != "") {
workFlowError = Inputs.GetProperty("WorkflowError").substring(0,1).toUpperCase() == "N" ? false : true;
if(workFlowError)
Outputs.SetProperty("Status","Success");
}
switch(MethodName) {
case "Cascade":
var sPropertyName = Inputs.GetFirstProperty();
var index;
var psChild = TheApplication().NewPropertySet();
while (sPropertyName) {
if (sPropertyName.indexOf("FieldName") >= 0) {
//Field Value pairs are matched by insuring the Suffix trailing FieldName matches that trailing FieldValue
if (sPropertyName == "FieldName") index = "";
else index = sPropertyName.substring(9, sPropertyName.length);
psChild.SetProperty(Inputs.GetProperty(sPropertyName), Inputs.GetProperty("FieldValue"+index));
logVars(Inputs.GetProperty(sPropertyName), Inputs.GetProperty("FieldValue"+index), 4);
}
sPropertyName = Inputs.GetNextProperty();
}
cascade("", Inputs.GetProperty("BO Name"), Inputs.GetProperty("BC Name"), Inputs.GetProperty("Search Expression"),
false, "", psChild);
break;
case "stripErrorMessage":
stripErrorMessage(Inputs, Outputs);
break;
case "logInterface":
logInterface(Inputs, Outputs);
break;
case "logRequest":
logRequest(Inputs, Outputs);
break;
case "logResponse":
logResponse(Inputs, Outputs);
break;
/* case "insertError":
insertError(Inputs.GetProperty("type"),
Inputs.GetProperty("grandParentId"),
Inputs.GetProperty("parentId"),
Inputs.GetProperty("childId"),
Inputs.GetProperty("interfaceName"),
Inputs.GetProperty("method"),
Inputs.GetProperty("errorCode"),
Inputs.GetProperty("errorMessage"));
break;
*/ case "PropSetToFile":
PropSetToFile(Inputs.GetProperty("FileName"), Inputs.GetChild(0));
break;
case "AddAttachment":
AddAttachment(Inputs,Outputs);
break;
case "ComputerName":
Outputs.SetProperty("ComputerName", ComputerName());
break;
case "TimeStamp":
param_1 = Inputs.GetProperty("Mode");
param_2 = TimeStamp(param_1);
Outputs.SetProperty("TimeStamp", param_2);
break;
case "Eval":
logStack(this.Name()+".PreInvoke."+MethodName);
var expression = Inputs.GetProperty("Expression");
var Var1 = Inputs.GetProperty("Var1");
var Var2 = Inputs.GetProperty("Var2");
logVars("Expression", expression, "Var1", Var1, "Var2", Var2);
var value = eval(expression);
Outputs.SetProperty("Value", value);
logUnstack(value);
break;
case "Upper":
Outputs.SetProperty("Out", Inputs.GetProperty("In").toUpperCase());
break;
case "ConcatenateField":
ConcatenateField(Inputs,Outputs)
break;
default:
retValue = ContinueOperation
}
} catch(e) {
if(workFlowError)
Outputs.SetProperty("Status","Error");
Outputs.SetProperty("ErrorMessage", (e.errText == undefined || e.errText == null ? e.toString() : e.errText));
if(!workFlowError)
RaiseError(e, this.Name());
}
return (retValue);
}

CMI Utilities
GetSysPref
function GetSysPref( preference ) {
//Use: Frame.GetSysPref( preference: the preference name in the system preference view )
//Returns: the value in the system preference view for this preference name
var aPref = BCGetArray("System Preferences.System Preferences",
"[Name] = '"+preference+"'", ["Value"]);
if (aPref.length > 0) return(aPref[0].Value);
else return("");
}

CMI Utilities
Init
function Init()
{
try {
//TheApplication().TraceOn("/opt/siebel81/siebsrvr/enterprises/SBA_81/edad669/log/XTrace-"+TheApplication().LoginName()+".log", "Allocation", "All");
//TheApplication().TraceOn("D:\\Users\\ku060\\Documents\\LOG\\Trace-"+TheApplication().LoginName()+".log", "Allocation", "All");
//TheApplication().Trace("LoginName: "+TheApplication().LoginName());
//MJB 6/13/11 Initialize the logging framework. This will extend base objects such as String and Date
//as well as determine the path of the session escript log file and the degree of logging
var language = TheApplication().InvokeMethod("LANGUAGE");
giErrorStack = 0;
ExtendObjects();
//TheApplication().Trace("string test: ".rPad(30,"."));
//Get the system preference for log mode. Value of "DB" stores to CX_SESSION. Default is "File"
gsLogMode = GetSysPref("CMI Framework Log Mode");
gsLogMode = (gsLogMode == "" ? "FILE" : gsLogMode.toUpperCase());
if (gsLogSession == null || typeof(gsLogSession) == "undefined") gsLogSession = TimeStamp("DateTimeMilli");
gsGuest = GetSysPref("CMI Guest Login");
gsGuest = (gsGuest == "" ? "SBLCRMANON_PROXY" : gsGuest.toUpperCase());
gsMergeGuestSessions = GetSysPref("CMI Framework Merge Guest");
gsMergeGuestSessions = (gsMergeGuestSessions == "" ? "TRUE" : gsMergeGuestSessions.toUpperCase());
gsMergeGuestSessions = (gsMergeGuestSessions == "TRUE" && TheApplication().LoginName()=="SIEBINT" ? "TRUE" : "FALSE");
RefreshLogPrefs("Init");
gsLogPath = GetSysPref("CMI Framework Log Path");
try {
var os;
os = Clib.getenv("OS");
} catch(e) { os = "UNIX Based"; }
var client = TheApplication().GetProfileAttr("IsStandaloneWebClient")
//TheApplication().Trace("client: "+client);
try {
gsFileName = "Trace-"+TheApplication().LoginName()+"-"+gsLogSession+".txt"
//If using thick client, use the siebel file structure log directory
if (client == "TRUE") {
gsLogPath = Clib.getenv("SIEBEL_LOG_DIR");
gsLogPath = (gsLogPath == "" ? "..\\Log" : gsLogPath);
gsLogPath = gsLogPath.replace(/\\$/, ""); //Remove trailing backslash if used
gsLogPath = gsLogPath + "\\";
gsLogMode = GetSysPref("CMI Framework Remote Log Mode");
gsLogMode = (gsLogMode == "" ? "FILE" : gsLogMode.toUpperCase());
//Developers will be identified by a blank Employee Type so that logs will be written to file
if (TheApplication().GetProfileAttr("CMI Employee Type Code") == "") gsLogMode = "FILE";
giLogBuffer = 10;
gIntermediateBufferDump = "TRUE";
// gsLogPath = "D:\\Users\\"+TheApplication().LoginName()+"\\Documents\\LOG\\";
} else if (os.substring(0, 7) == "Windows") {
//if Windows OS assume the path is the dynamicly determined Siebel_Home\Log directory, or ..\log
gsLogPath = gsLogPath.replace(/\\$/, ""); //Remove trailing backslash if used
gsLogPath = gsLogPath.replace(/\x47/, "\\"); //switch invalid OS directory seperators
gsLogPath = "..\\Log\\";
} else {
gsLogPath = gsLogPath.replace(/\x47$/, ""); //Remove trailing backslash if used
gsLogPath = gsLogPath.replace(/\\/, "/"); //switch invalid OS directory seperators
gsLogPath = gsLogPath+"/";
}
gsOutPutFileName = gsLogPath+gsFileName;
} catch(e) {
gsLogPath = "";
gsOutPutFileName = gsFileName;
}
logStep("Language: "+language, 1);
logStep("Session Log Level: "+gCurrentLogLvl, 1);
logStep("Operating System: "+os, 1);
logStep("Log File Name: "+gsOutPutFileName, 1);
//TheApplication().Trace("Log File Name: "+gsOutPutFileName);
//TheApplication().Trace("gsMergeGuestSessions: "+gsMergeGuestSessions);
// DumpBuffer("Init");
} catch(e) {
//TheApplication().Trace("Error");
throw(e);
} finally {
//TheApplication().TraceOff();
}
}

CMI Utilities
GetSessionId
function GetSessionId()
{
try {
var boSession:BusObject = TheApplication().GetBusObject("CMI User Session");
var bcSession:BusComp;
if (gSessionId == "") {
bcSession = boSession.GetBusComp("CMI User Session");
with (bcSession) {
NewRecord(NewBefore);
SetFieldValue("Employee Id",TheApplication().LoginId());
SetFieldValue("Session Stamp",gsLogSession);
WriteRecord();
gSessionId = GetFieldValue("Id");
}
}
} catch(e) {
throw(e);
} finally {
bcSession = null;
boSession = null;
}
return (gSessionId);
}

CMI Utilities
IntObjToPropSet
function IntObjToPropSet(psIntObj)
{
try
{
var psOut = TheApplication().NewPropertySet();
var bsService = TheApplication().GetService ("EAI Integration Object to XML Hierarchy Converter");
// bsService.InvokeMethod("IntObjHierToPSHier", psIntObj, psOut);
psIntObj.SetProperty("UseSiebelMessageEnvelope", "False");
bsService.InvokeMethod("IntObjHierToXMLHier", psIntObj, psOut);
if(psOut.GetChildCount() > 0)
{
var psChild = psOut.GetChild(0);
if(psChild.GetChildCount() > 0)
psOut = psChild.GetChild(0);
}
}
catch(e) {
RaiseError(e);
} finally {
bsService = null;
}
return(psOut);
}

CMI Utilities
PickField
function PickField(bcBusComp, pickField, searchField, searchValue)
{
/*****************************************************************
* Description: Generic Pick Function
*****************************************************************/
try {
var pickErr = "";
var bcPick = bcBusComp.GetPicklistBusComp (pickField);
searchValue = "\"" + searchValue + "\"";
bcPick.ActivateField(searchField);
bcPick.InvokeMethod ("SetAdminMode", "TRUE");
bcPick.ClearToQuery();
bcPick.SetSearchSpec(searchField, searchValue);
bcPick.ExecuteQuery(ForwardOnly);
if (bcPick.FirstRecord()) bcPick.Pick();
else pickErr = searchValue + " not found in PickList for " + pickField + ".";
} catch (e) {
pickErr = logError(e);
} finally {
bcPick = null;
}
return (pickErr);
}

CMI Utilities
PropSetElement2Attrib
function PropSetElement2Attrib(parent)
{
try
{
var result = TheApplication().NewPropertySet();
var i;
for(i = 0;i < parent.GetChildCount(); i++)
{
var psChild = parent.GetChild(i);
if(psChild.GetType() != "")
result.SetProperty(psChild.GetType(), psChild.GetValue());
}
}
catch(e) {
RaiseError(e);
} finally {
result = null;
psChild = null;
}
return(result);
}

CMI Utilities
PropSetFromBinaryXML
function PropSetFromBinaryXML(psIn)
{
// For Binary, Message must be in Value and can not be moved
try
{
var psOut = TheApplication().NewPropertySet();
var bsService = TheApplication().GetService ("XML Converter (Data in Child PropSet)");
psIn.SetProperty("EscapeNames", "False");
bsService.InvokeMethod("XMLToPropSet", psIn, psOut);
}
catch(e) {
RaiseError(e);
} finally {
psIn = null;
psOut = null;
bsService = null;
}
if(psOut.GetChildCount() > 0)
return(psOut.GetChild(0));
else
return(TheApplication().NewPropertySet());
}

CMI Utilities
PropSetFromXML
function PropSetFromXML(xmlMessage)
{
try
{
var psIn = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();
var bsService = TheApplication().GetService ("XML Converter (Data in Child PropSet)");
psIn.SetProperty("EscapeNames", "False");
psIn.SetValue(xmlMessage);
bsService.InvokeMethod("XMLToPropSet", psIn, psOut);
} catch(e) {
RaiseError(e);
} finally {
psIn = null;
psOut = null;
bsService = null;
}
return(psOut);
}

CMI Utilities
PropSetGetChild
function PropSetGetChild(parent, type)
{
var result = null;
var i, j;
for(i = 0;i < parent.GetChildCount(); i++)
{
if(parent.GetChild(i).GetType() == type)
return(parent.GetChild(i));
if(parent.GetChild(i).GetChildCount() > 0 )
{
for(i = 0;i < parent.GetChildCount(); i++)
{
var psChild = parent.GetChild(i);
result = PropSetGetChild(psChild, type);
if(result != null)
return(result);
}
}
}
return(result);
}

CMI Utilities
PropSetGetElement
function PropSetGetElement(parent, elementName)
{
var result = "";
var i;
for(i = 0;i < parent.GetChildCount(); i++)
{
if(parent.GetChild(i).GetType() == elementName)
{
result = parent.GetChild(i).GetValue();
break;
}
}
return(result);
}

CMI Utilities
PropSetToFile
function PropSetToFile(fileName, psSave)
{
try {
var psIn = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();
var bsService = TheApplication().GetService ("XML Converter (Data in Child PropSet)");
psIn.SetProperty("EscapeNames", "False");
psIn.AddChild(psSave);
bsService.InvokeMethod("PropSetToXML", psIn, psOut);
bsService = TheApplication().GetService ("EAI File Transport");
psOut.SetProperty("FileName", gsLogPath + fileName + ".xml");
bsService.InvokeMethod("Send", psOut, psIn);
}
catch(e) {
RaiseError(e);
} finally {
psOut = null;
psIn = null;
bsService = null;
}
}

CMI Utilities
RaiseError
function RaiseError() {
/* ***********************************
Created by Mik Branchaud on 09/20/11
Purpose: Log an error to the session log then raise an exception. Defaults to log level 0
Usage: TheApplication().Utility.RaiseError(e);
Arguments: 1 - exception
**************************************** */
//TheApplication().Trace("In RaiseError");
var oE = arguments[0];
var objectName = "";
var rowId = "";
var inGUI = TheApplication().GetProfileAttr("GUI_Context");
var stackLength = gaFunctionStack.length;
var objMethod = gaFunctionStack[stackLength-1];
var objDisplay = objMethod;
if (objectName != "") objDisplay = objectName+"."+objDisplay;
if (rowId != "") objDisplay = objDisplay + " ("+rowId+")";
gsIndent = "".rPad(giIndent*stackLength, " ");
if(!defined(oE.errText)) ge.errText = oE.toString();
else ge.errText = oE.errText;
ge.errText = ge.errText.substring(0, 500);
if(!defined(oE.errCode)) ge.errCode = "";
else ge.errCode = oE.errCode;
if (ToNumber(giErrorStack)==0) {
giErrorStack = stackLength;
logStep("".rPad(100, "*"),0);
logStep("*** - ERROR - "+objDisplay+" - "+ge.errCode,0);
logStep("*** "+ge.errText.replace(/\n/g, "\n"+"*** "),0);
logStep("".rPad(100, "*")+"\n",0);
/* try {
if ((inGUI.toUpperCase()=="FALSE")||(inGUI.toUpperCase()=="N")) InsertErrorInt(rowId);
else if (ge.errCode.match(/\(SBL-...-.....\)/)) { //custom message assumed to be functional - no need to log
switch (ge.errCode) {
case "22709":
case "22169":
break;
default:
// InsertErrorInt(rowId);
}
}
} catch(e) {
// throw(e)
}
*/
}
giErrorStack++;
DumpBuffer();
//Functional errors raised by validation routines should set this parameter to false to display only error
//text that is raised. True implies a system exception
TheApplication().RaiseErrorText(ge.errText);
}

CMI Utilities
RefreshActiveProfAttr
function RefreshActiveProfAttr()
{
try {
TheApplication().Utility.logStack("RefreshActiveProfAttr", this, true, 5);
TheApplication().Utility.logVars("Position Id", TheApplication().PositionId(), 5);
var svc:Service = TheApplication().GetService("CMI Show UserName BS");
svc.InvokeMethod("GetUserName", TheApplication().NewPropertySet(), TheApplication().NewPropertySet());
var boPosition:BusObject = TheApplication().GetBusObject("Position");
var boDivision:BusObject = TheApplication().GetBusObject("Internal Division");
var bcPosition:BusComp = boPosition.GetBusComp("Position");
var bcDivision:BusComp = boDivision.GetBusComp("Internal Division");
var divisionId = "";
var orgType = "";
with (bcPosition) {
ClearToQuery();
ActivateField("Division Id");
SetViewMode(AllView);
SetSearchSpec("Id", TheApplication().PositionId());
ExecuteQuery(ForwardOnly);
if (FirstRecord()) {
divisionId = GetFieldValue("Division Id");
TheApplication().Utility.logVars("Division/Position Id", divisionId+" / "+TheApplication().PositionId(), 5);
}
}
with (bcDivision) {
ClearToQuery();
ActivateField("CMI Default Inventory Location Parts");
ActivateField("CMI Default Inventory Location Parts Id");
ActivateField("CMI Default Inventory Location Service");
ActivateField("CMI Default Inventory Location Service Id");
ActivateField("CMI Default Inventory Location WG");
ActivateField("CMI Default Inventory Location WG Id");
ActivateField("CMI Default Inventory Location");
ActivateField("CMI Default Inventory Location Id");
ActivateField("CMI Ship To Site Id");
ActivateField("CMI Parts Virtual Inventory Location Id");
ActivateField("CMI Parts Virtual Inventory Location");
ActivateField("Currency Code");
ActivateField("CMI Rate List Id");
ActivateField("CMI Markup Multiplier");
ActivateField("CMI Distributor Code");
ActivateField("CMI Dist Mnemonic");
ActivateField("CMI Variance Tolerance Level");
ActivateField("Type");
SetViewMode(AllView);
SetSearchSpec("Id", divisionId);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) {
TheApplication().SetProfileAttr("CMI Default Inventory Location Parts Id", GetFieldValue("CMI Default Inventory Location Parts Id"));
TheApplication().SetProfileAttr("CMI Default Inventory Location Parts", GetFieldValue("CMI Default Inventory Location Parts"));
TheApplication().SetProfileAttr("CMI Default Inventory Location Service Id", GetFieldValue("CMI Default Inventory Location Service Id"));
TheApplication().SetProfileAttr("CMI Default Inventory Location Service", GetFieldValue("CMI Default Inventory Location Service"));
TheApplication().SetProfileAttr("CMI Default Inventory Location WG Id", GetFieldValue("CMI Default Inventory Location WG Id"));
TheApplication().SetProfileAttr("CMI Default Inventory Location WG", GetFieldValue("CMI Default Inventory Location WG"));
TheApplication().SetProfileAttr("CMI Default Inventory Id", GetFieldValue("CMI Default Inventory Location Id"));
TheApplication().SetProfileAttr("CMI Default Inventory Location", GetFieldValue("CMI Default Inventory Location"));
TheApplication().SetProfileAttr("CMI Branch Ship To Site Id", GetFieldValue("CMI Ship To Site Id"));
TheApplication().SetProfileAttr("CMI Default Service WIP", GetFieldValue("CMI Parts Virtual Inventory Location Id"));
TheApplication().SetProfileAttr("CMI Parts Virtual Inventory Location", GetFieldValue("CMI Parts Virtual Inventory Location"));
TheApplication().SetProfileAttr("CMI Division Currency Code", GetFieldValue("Currency Code"));
TheApplication().SetProfileAttr("CMI Rate List Id", GetFieldValue("CMI Rate List Id"));
TheApplication().SetProfileAttr("CMI Markup Multiplier", GetFieldValue("CMI Markup Multiplier"));
TheApplication().SetProfileAttr("CMI Distributor Code", GetFieldValue("CMI Distributor Code"));
TheApplication().SetProfileAttr("CMI Dist Mnemonic", GetFieldValue("CMI Dist Mnemonic"));
TheApplication().SetProfileAttr("CMI Variance Tolerance Level", GetFieldValue("CMI Variance Tolerance Level"));
TheApplication().SetProfileAttr("CMI Current Organization", GetFieldValue("Organization"));
TheApplication().SetProfileAttr("CMI Current Organization Id", GetFieldValue("Organization Id"));
orgType = GetFieldValue("Type");
orgType = TheApplication().InvokeMethod("LookupValue", "DIVISION_TYPE", orgType);
TheApplication().SetProfileAttr("Org.Type", orgType);
}
}
TheApplication().Utility.logVars("Active Inventory", TheApplication().GetProfileAttr("CMI Default Inventory Location"), 5);
} catch(e) {
TheApplication().Utility.RaiseError(e);
} finally {
svc = null;
bcPosition = null;
boPosition = null;
bcDivision = null;
boDivision = null;
TheApplication().Utility.logUnstack("", 5);
}
}

CMI Utilities
IntObjToFile
function IntObjToFile(fileName, psIn)
{
try
{
var psOut = TheApplication().NewPropertySet();
var bsService = TheApplication().GetService ("EAI XML Write to File");
psIn.SetProperty("FileName", "..\\log\\" + fileName + ".xml");
bsService.InvokeMethod("WriteEAIMsg", psIn, psOut);
psIn.RemoveProperty("FileName");
}
catch(e) {
RaiseError(e);
} finally {
psOut = null;
bsService = null;
}
}

CMI Warranty Credit Updates BS
CMICreateWarrantyVariance
/*************************************************************************************************************************
Created By : Damon Liu (JR430)
Created On : 2011-09-06
C&I Number : 4609
Functionality: New method to generate Warranty Variance as per S139
************************************************************************************************************************/
function CMICreateWarrantyVariance(sClaim) {
try {
TheApplication().Utility.logStack("CMICreateWarrantyVariance", this);
var sClaimBO:BusObject = TheApplication().GetBusObject("CMI Claims");
var sClaimBC:BusComp = sClaimBO.GetBusComp("INS Claims");
var sClaimPaymentBC:BusComp = sClaimBO.GetBusComp("INS Claims Payments");
var isClaimRec:bool;
var sWarVarianceTotal = ""; //Strong typing removed by KM326 on 08/10/2011 for C&I 4609 Bug
var sCurcyCd:String = "";
with(sClaimBC) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("CMI Warranty Variance Total");
ActivateField("Currency Code");
SetSearchSpec("Id", sClaim);
ExecuteQuery(ForwardOnly);
isClaimRec = FirstRecord();
TheApplication().Utility.logVars("Claim ("+sClaim+") found?", isClaimRec);
if(isClaimRec) {
sWarVarianceTotal = GetFieldValue("CMI Warranty Variance Total");
sCurcyCd = GetFieldValue("Currency Code");
}
//Added by KM326 for C&I 4609 Bug on 08/10/2011 to restrict Warranty Credit Variance creation when Amount is zero
TheApplication().Utility.logVars("Warranty Variance Total", sWarVarianceTotal);
if(sWarVarianceTotal != 0 && sWarVarianceTotal != null && sWarVarianceTotal != "") {
with(sClaimPaymentBC) {
ActivateField("Claim Id");
ActivateField("Payment Type Code");
ActivateField("Payment Status");
ActivateField("CMI Payment Credit Type");
ActivateField("Payment Amount");
ActivateField("Currency Code");
ClearToQuery();
ExecuteQuery(ForwardOnly);
NewRecord(NewAfter);
SetFieldValue("Claim Id", sClaim);
SetFieldValue("Payment Type Code", TheApplication().InvokeMethod("LookupValue", "CMI_PAYMENT_TYPE", "Warranty Credit Variance"));
SetFieldValue("CMI Payment Credit Type", TheApplication().InvokeMethod("LookupValue", "CMI_PAY_CDT_TYPE", "Consolidate"));
SetFieldValue("Payment Amount", sWarVarianceTotal);
SetFieldValue("Currency Code", sCurcyCd);
//Paymennt Status moved to last by KM326 to fix bug 4919 on 23-01-2012 as setting this earlier is causing Read-Only field errors
SetFieldValue("Payment Status", TheApplication().InvokeMethod("LookupValue", "FUNDRQ_STATUS", "Verified"));
WriteRecord();
}//end of with(sClaimPaymentBC)
} else if(sWarVarianceTotal == 0) {
sClaimBC.SetFieldValue("Status Code", TheApplication().InvokeMethod("LookupValue", "INS_CLAIM_STATUS", "Closed"));
sClaimBC.WriteRecord();
}
}//end of with(sClaimBC)
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sClaimPaymentBC = null;
sClaimBC =null;
sClaimBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Warranty Credit Updates BS
CMIUpdateClaimOrders
/*************************************************************************************************************************
Created By : Damon Liu (JR430)
Created On : 2011-09-06
C&I Number : 4609
Functionality: Method to updated Intersection BC between claims and orders as per S139
************************************************************************************************************************/
function CMIUpdateClaimOrders() {
try {
TheApplication().Utility.logStack("CMIUpdateClaimOrders", this);
var sOrderBO = TheApplication().GetBusObject("Order Entry (Sales)");
var sOrderBCOrderBO = sOrderBO.GetBusComp("Order Entry - Orders");
var sOrderLineItemsBC = sOrderBO.GetBusComp("Order Entry - Line Items");
var sBO = TheApplication().GetBusObject("CMI Claims");
var sOrderBC = sBO.GetBusComp("Order Entry - Orders");
var sClaimBO = TheApplication().GetBusObject("CMI Claims");
var sClaimBC = sClaimBO.GetBusComp("INS Claims");
var sClaimOrderBC = sClaimBO.GetBusComp("CMI Claim Orders");
var sClaimId = TheApplication().GetProfileAttr("CMIClaimId");
var sNoEarlyCredit = TheApplication().GetProfileAttr("CMINoEarlyCredit");
var isRec;
var isClaimRec;
var sOrderId = "";
var sCMIShipToProfileId = "";
var curRec;
with(sOrderBC) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("CMI Primary Claim Id");
ActivateField("CMI Ship To Profile Id");
ActivateField("CMI Business Unit");
//Added SortSpec by KM326 for C&I 4609 Bug on 08/10/2011
SetSortSpec("Created(DESCENDING)");
SetSearchSpec("CMI Primary Claim Id", sClaimId);
SetSearchSpec("Status", TheApplication().InvokeMethod("LookupValue", "FS_ORDER_STATUS", "Pending"));
ExecuteQuery(ForwardBackward);
isRec = FirstRecord();
TheApplication().Utility.logVars("Order for Claim ("+sClaimId+") found?", isRec);
if(isRec) {
SetFieldValue("CMI Business Unit", TheApplication().InvokeMethod("LookupValue", "CMI_BUSINESS_UNIT", "Distribution"));
WriteRecord(); //CMI DBU Realease # 2 CRP3 for bug # 202 for defaulting BU by ki795 on 1-Oct
sOrderId = GetFieldValue("Id");
//Added by KM326 to fix Bug 197 on 28-09-2011
sCMIShipToProfileId = GetFieldValue("CMI Ship To Profile Id");
}
}
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();
}
with(sClaimBC)
{
SetViewMode(AllView);
ClearToQuery();
ActivateField("CMI Early Credit");
SetSearchSpec("Id", sClaimId);
ExecuteQuery(ForwardOnly);
isClaimRec = FirstRecord();
if(isClaimRec)
{
TheApplication().Utility.logVars("Early Credit", sNoEarlyCredit.valueOf());
if(sNoEarlyCredit.valueOf() == "Y") {
SetFieldValue("Status Code", TheApplication().InvokeMethod("LookupValue", "INS_CLAIM_STATUS", "Pending Customer Credit"));
} else {
SetFieldValue("CMI Early Credit", TheApplication().InvokeMethod("LookupValue", "CMI_EARLY_CREDIT", "Issued")); // by ki795 for bug # 147 as the early credit value should be set to "Issued" only when early credit is set as create.
}
WriteRecord();
}
}
//Added by KM326 to fix Bug 197
sOrderBCOrderBO.SetViewMode(AllView);
sOrderBCOrderBO.ClearToQuery();
sOrderBCOrderBO.ActivateField("Id");
sOrderBCOrderBO.SetSearchSpec("Id", sOrderId);
sOrderBCOrderBO.ExecuteQuery(ForwardBackward);
TheApplication().Utility.logVars("Order ("+sOrderId+") Found?", sOrderBCOrderBO.FirstRecord());
if(sOrderBCOrderBO.FirstRecord()) {
with(sOrderLineItemsBC) {
SetViewMode(AllView);
ClearToQuery();
ActivateField("Order Header Id");
ActivateField("CMI Ship To Profile Id");
SetSearchSpec("Order Header Id", sOrderId);
ExecuteQuery(ForwardBackward);
curRec = FirstRecord();
while(curRec)
{
SetFieldValue("CMI Ship To Profile Id", sCMIShipToProfileId);
WriteRecord();
curRec = NextRecord();
}
}
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
sClaimBC = null;
sClaimOrderBC = null;
sClaimBO = null;
sOrderBCOrderBO = null;
sOrderLineItemsBC = null;
sOrderBO = null;
sClaimOrderBC = null;
sOrderBC = null;
sBO = null;
TheApplication().Utility.logUnstack();
}
}

CMI Warranty Credit Updates BS
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//CMI DBU: Added Try/Catch block as per code review comments, by jq486, 19 Oct 2011.
try {
TheApplication().Utility.logStartStack("Business Service", this.Name(), MethodName);
var retVal = CancelOperation;
if (MethodName == "CMIUpdateClaimOrders"){
CMIUpdateClaimOrders();
} else if (MethodName == "CMICreateWarrantyVariance") {
var sClaim = TheApplication().GetProfileAttr("CMIWarCreditClaimId");
CMICreateWarrantyVariance(sClaim);
}
} catch(e){
TheApplication().Utility.RaiseError(e);
} finally {
TheApplication().Utility.logUnstack(retVal);
}
return(retVal);
}

CMI Wholegoods Quote BS
Service_PreInvokeMethod
/*************************************************************************************************************************
Created By :
Created On : 11th Dec 2010
Method Name: function BusComp_PreInvokeMethod (MethodName) == "AddToQuoteTotal"
Functionality: AddToQuoteTotal method will be triggered when the user change the check box "CMI Add To Quote Total from CMI Wholegoods Quote Item List Applet
ConvertToOrder method will be triggered when the user change the check box "CMI Convert To Order from CMI Wholegoods Quote Item List Applet
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
//Try- Catch block added as part of Code clean-up by JW919 on 08/22/2011
try
{
if(MethodName == "AddToQuoteTotal")
{
AddToQuoteTotal(Inputs, Outputs);
return (CancelOperation);
}
if (MethodName == "ConvertToOrder")
{
ConvertToOrder(Inputs, Outputs);
return (CancelOperation);
}
return (ContinueOperation);
}
catch(e)
{
TheApplication().RaiseErrorText("Exception raised in BS:"+this.Name()+". Exception:"+e.toString());
}
}

CMI Wholegoods Quote BS
AddToQuoteTotal
/*************************************************************************************************************************
Created By :
Created On : 11th Dec 2010
Method Name: function BusComp_PreInvokeMethod (MethodName) == "AddToQuoteTotal"
Functionality: when the parent quote item change the check box "CMI Add To Quote Total",
the child quote item check box "CMI Add To Quote Total" will be change.
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function AddToQuoteTotal(Inputs, Outputs)
{
try
{
var oBO = TheApplication().ActiveBusObject()
var oBC = oBO.GetBusComp("Quote Item");
var oBOQuote = TheApplication().GetBusObject("Quote");
var oBCQuoteItem = oBOQuote.GetBusComp("Quote Item");
oBC.ActivateField("CMI Add To Quote Total");
var sAddToQuoteFlg = oBC.GetFieldValue("CMI Add To Quote Total");
var sConvertToQuoteFlg = oBC.GetFieldValue("CMI Convert To Order");
var sRowId = oBC.GetFieldValue("Id");
with(oBCQuoteItem)
{
InvokeMethod("SetAdminMode", "TRUE");
SetViewMode(AllView);
ActivateField("Parent Quote Item Id");
ActivateField("CMI Add To Quote Total");
ClearToQuery();
SetSearchSpec("Parent Quote Item Id",sRowId);
ExecuteQuery(ForwardOnly);
var HasRecord = FirstRecord();
while (HasRecord)
{
SetFieldValue("CMI Add To Quote Total", sAddToQuoteFlg);
WriteRecord();
HasRecord = NextRecord();
}
InvokeMethod("SetAdminMode", "FALSE");
}
if(sAddToQuoteFlg == "N")
{
oBC.SetFieldValue("CMI Convert To Order",sAddToQuoteFlg);
}
oBC.InvokeMethod("RefreshBusComp");
oBC.InvokeMethod("ExpandAll");
}
catch(e)
{
throw(e);
}
finally
{
oBCQuoteItem = null;
oBOQuote = null;
oBC = null;
oBO = null;
}
}

CMI Wholegoods Quote BS
ConvertToOrder
/*************************************************************************************************************************
Created By :
Created On : 11th Dec 2010
Method Name: function BusComp_PreInvokeMethod (MethodName) == "AddToQuoteTotal"
Functionality: when the parent quote item change the check box "CMI Convert To Order",
the check box "CMI Add To Quote Total" will be change,and the child quote item
check box "CMI Convert To Order" and "CMI Add To Quote Total" will be change.
Input: NA
Output: NA
Customization Approval #: NA
************************************************************************************************************************/
function ConvertToOrder(Inputs, Outputs)
{
try
{
var oBO = TheApplication().ActiveBusObject()
var oBC = oBO.GetBusComp("Quote Item");
var oBOQuote = TheApplication().GetBusObject("Quote");
var oBCQuoteItem = oBOQuote.GetBusComp("Quote Item");
oBC.ActivateField("CMI Convert To Order");
oBC.ActivateField("CMI Add To Quote Total");
var sAddToQuoteFlg = oBC.GetFieldValue("CMI Add To Quote Total");
var sConvertToQuoteFlg = oBC.GetFieldValue("CMI Convert To Order");
var sRowId = oBC.GetFieldValue("Id");
with(oBCQuoteItem)
{
InvokeMethod("SetAdminMode", "TRUE");
SetViewMode(AllView);
ActivateField("Parent Quote Item Id");
ActivateField("CMI Convert To Order");
ClearToQuery();
SetSearchSpec("Parent Quote Item Id",sRowId);
ExecuteQuery(ForwardOnly);
var HasRecord = FirstRecord();
while (HasRecord)
{
SetFieldValue("CMI Convert To Order", sConvertToQuoteFlg);
WriteRecord();
HasRecord = NextRecord();
}
InvokeMethod("SetAdminMode", "FALSE");
}
if(sConvertToQuoteFlg != "N")
{
oBC.SetFieldValue("CMI Add To Quote Total",sConvertToQuoteFlg);
}
oBC.InvokeMethod("RefreshBusComp");
oBC.InvokeMethod("ExpandAll");
}
catch(e)
{
throw(e);
}
finally
{
oBCQuoteItem = null;
oBOQuote = null;
oBC = null;
oBO = null;
}
}

CMI eMail Response Get Due Day
Service_PreInvokeMethod
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
try
{
if(MethodName == "GetDueDays")
{
var SysDate = Clib.time();
var sCurrentDate = Date.fromSystem(SysDate);
var sCurrentDay = ToString(sCurrentDate.getDay());
var sDays = 2;
switch (sCurrentDay)
{
case "1" :
case "2" :
case "3" :
case "0" :
break;
case "4" :
case "5" :
sDays = 4;
break;
case "6" :
sDays = 3;
break;
}
Outputs.SetProperty("Due Day", sDays);
return (CancelOperation);
}
}
catch(e)
{
throw(e);
}// end of catch
finally
{
SysDate = null;
sCurrentDate = null;
sCurrentDay = null;
sDays = null;
}
return (ContinueOperation);
}