Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

function ExportCommTemplate(Inputs, Outputs)

{
/*
Author: Prashanth K
http://crmcog.com
Description:
Export communication templates to a directory. Takes searchspec
as argument.
Inputs:
SearchExpr - standard Siebel SearchExpr used to query for templa
tes
Directory - Directory in which the template subdirectory should
be created.
Will default to c:\temp - note that this may be on server.
Outputs:
Status - message indicating status
# Comm Templates - no. of comm templates processed
# Comm Template Items - no. of comm template items processed
# Errors - no. of files that errored out!
Note:
No implied warranties. Use at your own risk.
For all practical purposes, consider that I am a lunatic.

Revision History:
Date Author Description
===============================
*/
try {
var iComExists, iComItemExists;
var sId, sName, sDisplayText, sFileStatus, sFile, sSiebelFileName, sSieb
elFileExtn, sSeq;
var bcComItem;
var iComCount = 0, iComItemCount = 0, iErrCount = 0;
var sFileDelim = "^";
var oToday = new Date();
var sSearchExpr = Inputs.GetProperty("SearchExpr");
if (sSearchExpr == "") sSearchExpr = "[Id] = '72S-8T'"; //testing
var sDir = Inputs.GetProperty("Directory");
if (sDir == "") sDir = "c:\\temp";
sDir = sDir + "\\CommTemplates_" + oToday.getFullYear() + (oToday.getMon
th() + 1) + oToday.getDate() + oToday.getHours();
Clib.mkdir(sDir);
var boCom = TheApplication().GetBusObject("Comm Package");
var bcCom = boCom.GetBusComp("Comm Package");
with (bcCom) {
ClearToQuery();
SetViewMode(AllView);
SetSearchExpr(sSearchExpr);
ActivateField("Name");
ActivateField("Display Template Text");
ExecuteQuery(ForwardOnly);
iComExists = FirstRecord();
}
while (iComExists){
iComCount++;
sName = bcCom.GetFieldValue("Name");
sDisplayText = bcCom.GetFieldValue("Display Template Text");
sId = bcCom.GetFieldValue("Id");
if (sDisplayText != "") {
CreateFile(sDir + "\\" + sName + sFileDelim + "DisplayTe
xt.html", sDisplayText);
}
else {
bcComItem = boCom.GetBusComp("Comm Package Item");
with (bcComItem){
ClearToQuery();
SetViewMode(AllView);
ActivateField("Sequence Number");
ActivateField("CommFileName");
ActivateField("CommFileExt");
ExecuteQuery(ForwardOnly);
iComItemExists = FirstRecord();
} //with (bcComItem)
while(iComItemExists){
iComItemCount++;
sSiebelFileName = bcComItem.GetFieldValue("CommF
ileName");
sSiebelFileExtn = bcComItem.GetFieldValue("CommF
ileExt");
sSeq = bcComItem.GetFieldValue("Sequence Number"
);
try {
sFileStatus = bcComItem.InvokeMethod("Ge
tFile", "CommFileName");
}
catch(e) {
sFileStatus = "SevereError";
}
if (sFileStatus == "Error" || sFileStatus == "Ou
tOfDate" || sFileStatus == "SevereError") {
iErrCount++;
CreateFile(sDir + "\\" + sName + sFileDe
lim + sSeq + sFileDelim + sSiebelFileName + "." + sSiebelFileExtn + sFileDelim +
sFileStatus + ".txt", "[" + sFileStatus + "] Error in processing file.");
}
else {
sFile = sFileStatus.substring(sFileStatu
s.indexOf(",") + 1);
Clib.rename(sFile, sDir + "\\" + sName +
sFileDelim + sSeq + sFileDelim + sSiebelFileName + "." + sSiebelFileExtn);
}
iComItemExists = bcComItem.NextRecord();
} //while(iComItemExists)
} //else
iComExists = bcCom.NextRecord();
} //while (iComExists)
Outputs.SetProperty("Status", "Templates exported satisfying search crit
eria '" + sSearchExpr + "'");
Outputs.SetProperty("# Comm Templates", iComCount);
Outputs.SetProperty("# Comm Template Items", iComItemCount);
Outputs.SetProperty("# Errors", iErrCount);
} //try
catch(e){
Outputs.SetProperty("Status", "Error in processing templates. " + e.errT
ext);
throw(e);
}
finally{
bcComItem = null;
bcCom = null;
boCom = null;
oToday = null;
}
}

You might also like