|
|
| Line 17: |
Line 17: |
|
| |
|
| ---- | | ---- |
|
| |
| function InsertRecord()
| |
| {
| |
| // Handle insert record actions here
| |
| }
| |
|
| |
| var m_subject="";
| |
| var m_message="";
| |
| function PostInsertRecord()
| |
| {
| |
| //pre- 7.0
| |
| //var personTable="person";
| |
|
| |
| var personTable="person,vPersonPE";
| |
| var casep_sql="select * from CaseProgress (nolock) where "+WhereClause;
| |
| var casep_rec=CRM.CreateQueryObj(casep_sql);
| |
| casep_rec.SelectSQL();
| |
|
| |
| if (casep_rec.eof==false)
| |
| {
| |
| var case_sql="select case_referenceid, case_description, Comp_PrimaryPersonId, Case_PrimaryPersonId from vsummarycase (nolock) where Case_CaseId="+casep_rec("case_caseid");
| |
|
| |
| var case_rec=CRM.CreateQueryObj(case_sql);
| |
| case_rec.SelectSQL();
| |
|
| |
| m_subject="New Tracking Note on Case: " + case_rec("case_referenceid") +"#Cases:"+case_rec("case_referenceid")+"#";
| |
| m_body=casep_rec("case_progressnote");
| |
|
| |
| if (case_rec("Comp_PrimaryPersonId")==case_rec("Case_PrimaryPersonId"))
| |
| {
| |
| if(case_rec("Comp_PrimaryPersonId")+""!="undefined")
| |
| {
| |
| //send one email
| |
| var pers_rec=CRM.FindRecord(personTable,"pers_personid="+case_rec("Comp_PrimaryPersonId")+" and Pers_sendEmailNotif='Y'");
| |
| if (pers_rec.eof==false)
| |
| {
| |
| sendEmail(pers_rec("pers_emailaddress"),pers_rec("pers_firstname")+ " "+pers_rec("pers_lastname"));
| |
| }
| |
| }
| |
| }else{
| |
| //send two emails
| |
| if(case_rec("Comp_PrimaryPersonId")+""!="undefined")
| |
| {
| |
| var pers_rec=CRM.FindRecord(personTable,"pers_personid="+case_rec("Comp_PrimaryPersonId")+" and Pers_sendEmailNotif='Y'");
| |
| if (pers_rec.eof==false)
| |
| {
| |
| sendEmail(pers_rec("pers_emailaddress"),pers_rec("pers_firstname")+ " "+pers_rec("pers_lastname"));
| |
| }
| |
| }
| |
| if(case_rec("Case_PrimaryPersonId")+""!="undefined")
| |
| {
| |
| var pers_rec2=CRM.FindRecord(personTable,"pers_personid="+case_rec("Case_PrimaryPersonId")+" and Pers_sendEmailNotif='Y'");
| |
| if (pers_rec2.eof==false)
| |
| {
| |
| sendEmail(pers_rec2("pers_emailaddress"),pers_rec2("pers_firstname")+ " "+pers_rec2("pers_lastname"));
| |
| }
| |
| }
| |
| }
| |
| }
| |
| }
| |
|
| |
|
| |
| function sendEmail(email1, name1)
| |
| {
| |
| ErrorStr+=email1+":"+name1+":" +m_subject+m_body+"=====";
| |
| return;
| |
|
| |
| var myMailObject = CRM.GetBlock("messageblock");
| |
| with (myMailObject)
| |
| {
| |
| DisplayForm = false;
| |
| mSubject = m_subject;
| |
| mBody = m_message;
| |
| mShowCC = true;
| |
| mShowBCC = true;
| |
| AddRecipient(email1,name1,"TO");
| |
| Mode=2;
| |
| Execute();
| |
|
| |
| if (mSentOK)
| |
| {
| |
| ErrorStr = "Email Sent";
| |
| }
| |
| else
| |
| {
| |
| ErrorStr = "There has been a problem: "+mErrorMessage;
| |
| }
| |
| }
| |
| }
| |
|
| |
| function UpdateRecord()
| |
|
| |
| {
| |
|
| |
| // Handle update record actions here
| |
|
| |
| }
| |
|
| |
|
| |
| function DeleteRecord()
| |
|
| |
| {
| |
|
| |
| // Handle delete record actions here
| |
|
| |
| }
| |
This sample shows you how to check if the field has been changed from one value to another
function UpdateRecord()
{
if (Values("case_AssignedUserId")+""=="undefined")
return; //bad update from crm..or field not changed
var CaseRec=CRM.CreateQueryObj("SELECT * FROM Cases WITH (NOLOCK) WHERE " + WhereClause);
CaseRec.SelectSQL();
if (CaseRec("case_assigneduserid")!=Values("Case_AssignedUserId"))
{
ErrorStr="field value has changed from "+CaseRec("case_assigneduserid") +" to "+Values("Case_AssignedUserId");
}
}