We have an inbound EAI service based on a business service that processes a complex Contact message. One of the child elements in the Contact message is the personal address. We've observed that the inbound message, in an upsert, will insert a new address but not mark it as primary for the Contact. Siebel provides a property called "IsPrimaryMVG" which can be sent with the Address record as an element or attribute. However, since we cannot ask our integrated app to send this, nor should we, we have to ammend the incoming message on the fly. This was done by traversing the IOHierarchy and setting the property as follows:
/* Below Code is Required to Parse Opportunity Role & Opportunity Id from Given XML */
if (xmlOutputs.GetChildCount() > 0)
{
MessageElement = xmlOutputs.GetChild(0);
if (MessageElement.GetType() == "SiebelMessage")
{
ListElement = MessageElement.GetChild(0);
if (ListElement.GetType() == "ListOfContact")
{
ContactEle = ListElement.GetChild(0);
if (ContactEle.GetType() == "CEB WebV2 Contact Int")
{
OptyRole = ContactEle.GetProperty("Opty Role");
OptyEle = ContactEle.GetChild(0);
if (OptyEle.GetType() == "ListOf WebV2 Contact Int_Opportunity")
{
OptyIdEle = OptyEle.GetChild(0);
OpportunityId = OptyIdEle.GetProperty("Opty Id");
}
//mwd 090908 added to set address as primary
var PrimaryEle;
var AddrEle;
AddrEle = ContactEle.GetChild(1);
if (AddrEle.GetType() == "ListOf WebV2 Contact Int_Personal Address")
{
PrimaryEle = AddrEle.GetChild(0);
PrimaryEle.SetProperty("IsPrimaryMVG", "Y");
}
//end mwd 090908
}
}
}
}
Key lesson here is that the GetChild(0) is used.
Showing posts with label escript. Show all posts
Showing posts with label escript. Show all posts
Tuesday, September 9, 2008
Wednesday, September 3, 2008
bad ass upload script
One of our vague requirements was to build into Siebel some upload functionality. Basically an end user should be able to add a csv/txt attachment and have the contents of the file associated to a correspondence record as child records.
To build this, I started with the vanilla correspondence attachment buscomp. This gives us the ability to browse to a csv/txt file (or drag and drop) and have it associated to the Siebel file system. Everything else was custom:
0. add a button to read file and insert contacts
1. check the attachment for valid extension (csv or txt)
2. open the file in memory
3. read line by line
4. parse the line and write to Siebel buscomp fields
5. close the file
6. delete the temp file
7. log any errors
8. attach the log file to the same correspondence record
9. update the attachment record with file processing status
I'll go through each of these high level steps:
1. To check the validity of the file extension a simple function was added to check the attachment buscomp's extension field. If invalid, throw an error and do not proceed.
2. If the file was valid, we passed the attachment id to a business service asynchronously. This business service opens the file and does the processing. I added some nice touches such as multi-select so multiple files could be submitted from the correspondence attachment custom button but here are some key lessons from the development:
a. do not use clib functions b/c there is a known defect related to parsing special chars like accents and umlauts. Instead, use COMCreateObject("Scripting.FileSystemObject") and fso.OpenTextFile(sInputFile, 1)
b. fp.SkipLine() allows you to skip a header row, if your user specifies that one exists
c. fp.ReadLine() allows you take the entire row into memory and use "split" to parse
d. to loop through and write to the child buscomp here is some script:
for(var index = 1; index < sStringArray.length; index++)
{
trim(sStringArray[index]);
sStringArray[index].substring(0,254);
var sFieldName = "Field"+" "+index;
if (index < 11)
{
bcContactListContact.SetFieldValue(sFieldName,sStringArray[index]);
}
else
{
sStatus = "Completed with Error - Check Log for Details ";
Outputs.SetProperty("sStatus", sStatus);
Clib.fprintf(fpLog, "Contact: " + sStringArray[0] + " has too many values to load. Only the first 10 were loaded. \n");
}
}
bcContactListContact.WriteRecord();
e. to remove the temp file that is created on siebsrvr use Clib.remove(sInputFile);
f. to add a log file to the attachment buscomp use AttBC.InvokeMethod("CreateFile", sLogFile, "CorrFileName", "N");
To build this, I started with the vanilla correspondence attachment buscomp. This gives us the ability to browse to a csv/txt file (or drag and drop) and have it associated to the Siebel file system. Everything else was custom:
0. add a button to read file and insert contacts
1. check the attachment for valid extension (csv or txt)
2. open the file in memory
3. read line by line
4. parse the line and write to Siebel buscomp fields
5. close the file
6. delete the temp file
7. log any errors
8. attach the log file to the same correspondence record
9. update the attachment record with file processing status
I'll go through each of these high level steps:
1. To check the validity of the file extension a simple function was added to check the attachment buscomp's extension field. If invalid, throw an error and do not proceed.
2. If the file was valid, we passed the attachment id to a business service asynchronously. This business service opens the file and does the processing. I added some nice touches such as multi-select so multiple files could be submitted from the correspondence attachment custom button but here are some key lessons from the development:
a. do not use clib functions b/c there is a known defect related to parsing special chars like accents and umlauts. Instead, use COMCreateObject("Scripting.FileSystemObject") and fso.OpenTextFile(sInputFile, 1)
b. fp.SkipLine() allows you to skip a header row, if your user specifies that one exists
c. fp.ReadLine() allows you take the entire row into memory and use "split" to parse
d. to loop through and write to the child buscomp here is some script:
for(var index = 1; index < sStringArray.length; index++)
{
trim(sStringArray[index]);
sStringArray[index].substring(0,254);
var sFieldName = "Field"+" "+index;
if (index < 11)
{
bcContactListContact.SetFieldValue(sFieldName,sStringArray[index]);
}
else
{
sStatus = "Completed with Error - Check Log for Details ";
Outputs.SetProperty("sStatus", sStatus);
Clib.fprintf(fpLog, "Contact: " + sStringArray[0] + " has too many values to load. Only the first 10 were loaded. \n");
}
}
bcContactListContact.WriteRecord();
e. to remove the temp file that is created on siebsrvr use Clib.remove(sInputFile);
f. to add a log file to the attachment buscomp use AttBC.InvokeMethod("CreateFile", sLogFile, "CorrFileName", "N");
Subscribe to:
Posts (Atom)