Tuesday, May 29, 2012

An error has occurred that has stopped this transaction from continuing

Reason 1:

This message appears due to 0 rows in PS_INSTALLATION Table.

Solution:

Insert a row in PS_INSTALLATION table and  restart the appservers.

Reason 2:

some error code in the events PreBuild, Activate, PostBuild or any FieldDefault.

Tuesday, May 22, 2012

Sending Multiple attachment using MCF Send mail method.

Below is the sample code to send multiple attachment in mail using MCF Send() mail method.

Local any &FromURL = "record://PV_ATT_DB_SRV/";
Local string &FILENAME;
Local Rowset &rwln1 = CreateRowset(Record.PV_ATTACHMENTS);
Local SQL &Sql1 = CreateSQL("select attachsysfilename from PS_PV_ATTACHMENTS a,ps_SPF_RESUME_ATT b where a.scm_attach_id=b.scm_attach_id and b.person_id=:1", "000000000000025", &FILENAME);

While &Sql1.Fetch(&FILENAME)
&attach = create PT_MCF_MAIL:MCFBodyPart();
Local string &ToFile = "C:/user/" | &FILENAME;
Local any &errorCode = GetAttachment(&FromURL, &FILENAME, &ToFile);

If &i = 1 Then
&multiattach = CreateArray(&attach);
&multiattach [&i] = &attach;
Else
&multiattach [&i] = &attach;
End-If;
&multiattach [&i].SetAttachmentContent(&ToFile, %FilePath_Absolute, &FILENAME, " ", "", "");
&mp.AddBodyPart(&multiattach [&i]);
End-While;

Local PT_MCF_MAIL:MCFBodyPart &test1 = create PT_MCF_MAIL:MCFBodyPart();
Local PT_MCF_MAIL:MCFBodyPart &eMail1 = create PT_MCF_MAIL:MCFBodyPart();

&eMail1.Text = &Message;
&mp.AddBodyPart(&eMail1);
&eMail.MultiPart = ∓
&res = &eMail.Send();

Local boolean &done;

Evaluate &res
When %ObEmail_Delivered
/* every thing ok */
&done = True;
MessageBox(0, "", 0, 0, "Email Sent Successfully");
Break;
When %ObEmail_NotDelivered
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Check &email.InvalidAddresses, &email.ValidSentAddresses */
/* and &email.ValidUnsentAddresses */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&done = False;
MessageBox(0, "", 0, 0, "Email Not delivered" | &eMail.InvalidAddresses | &eMail.ValidSentAddresses | &eMail.ValidUnsentAddresses);
Break;
When %ObEmail_PartiallyDelivered
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Check &email.InvalidAddresses, &email.ValidSentAddresses */
/* and &email.ValidUnsentAddresses */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&done = True;
MessageBox(0, "", 0, 0, "Email Partially delivered" | &eMail.InvalidAddresses | &eMail.ValidSentAddresses | &eMail.ValidUnsentAddresses);
Break;
When %ObEmail_FailedBeforeSending
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Get the Message Set Number, message number; */
/* Or just get the formatted messages from */
/* &email.ErrorDescription, email.ErrorDetails; */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&done = False;
MessageBox(0, "", 0, 0, "Email Failed Before Sending" | &eMail.ErrorDescription | &eMail.ErrorDetails);
Break;
End-Evaluate;

If &done = True Then
While &Sql1.Fetch(&FILENAME)
Local string &deleteFile = "C:/user/" | &FILENAME;
Local JavaObject &f = CreateJavaObject("java.io.File", &deleteFile);
&f.delete();
End-While;
End-If;
 
Note: This is sample code. This required to include necessary application package and to declare objects.

Saturday, May 5, 2012

Move and Delete files using PeopleCode

We can use the below java object and code to move or deleting files from some location.

Moving file:

Local JavaObject &source = CreateJavaObject("java.io.File", "/source/file.txt");
Local JavaObject &target = CreateJavaObject("java.io.File", "/target/file.txt");

&source.renameTo(&target);



Deleting file:

Local JavaObject &DelLoc = CreateJavaObject("java.io.File", "/source/file.txt");
&DelLoc.delete(); 
Alternate code for deleting file:
&tmpfile = GetFile(“c:\temp\file.txt”, “W”, “A”, %FilePath_Absolute);
&tmpfile.Delete();