Hi MD
Here is the code for the Account OnSave (called "Company" in our case):
var validationErrors = false;
// 1.
try {
if (crmForm.new_profile.value== "4" &&
crmForm.new_mediacategory.value.length == 0) {
alert("If Profile is 'Media', Media Category must also be populated");
event.returnValue = false;
validationErrors = true;
}
} catch (ex) {
}
// 2.
try {
if(crmForm.customertypecode.value == "15" &&
crmForm.new_estimatedannualfees.value.length > 0) {
alert("If Relationship Type is 'Prospect', Estimated Annual Fees can not be
populated");
crmForm.new_estimatedannualfees.focus();
event.returnValue = false;
validationErrors = true;
}
} catch (ex) {
}
// 3.
try {
/* Special case, the Client Partner had white space in it, so I trim before
doing length comparisons, clearly JScript doesn't do trim, so the Regex is
the next neatest thing.
Special case 2. This does not apply to the create form, as the lookup
functionality doesn't work for non existent clients*/
var strResult;
var objRegex = new RegExp("(^\\s+)|(\\s+$)");
var strResult =
document.frames("IFRAME_ClientPartner").document.a ll("txtLink").innerText.replace(objRegex, "");
if ((crmForm.customertypecode.value == "13" ||
crmForm.customertypecode.value == "16") && (strResult.length == 0 ||
crmForm.new_primaryservice.value.length == 0) && (crmForm.FormType != 1 &&
crmForm.FormType != 5)) {
alert("Each Corporate Client must have a Client Partner, and a Primary
Service.\nThis includes 'Corporate Clients' and 'Corporate Responsibility'
Relationship Types.");
event.returnValue = false;
validationErrors = true;
}
} catch (ex) {
}
// 4.
try {
var clientPartner =
document.frames("IFRAME_ClientPartner").document.a ll("txtLink").innerText;
crmForm.new_clientpartner.value = clientPartner;
var PreviousClientPartner =
document.frames("IFRAME_PreviousClientPartner").do cument.all("txtLink").innerText;
crmForm.new_previousclientpartner.value = PreviousClientPartner;
var TaskPartner=
document.frames("IFRAME_TaskPartner").document.all ("txtLink").innerText;
crmForm.new_taskpartner.value = TaskPartner;
} catch (ex) {
}
// 5. Welcome Email
try {
if ((!validationErrors) && (crmForm.new_customertypecodeprevious.value ==
"Not Defined" &&
crmForm.customertypecode[crmForm.customertypecode.selectedIndex].text ==
"Corporate Client") || (crmForm.new_customertypecodeprevious.value == "Not
Defined" &&
crmForm.customertypecode[crmForm.customertypecode.selectedIndex].text ==
"Corporate Responsibility")) {
var entityId = crmForm.ObjectId;
var entityType = crmForm.ObjectTypeCode;
var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
oXmlDoc.async = false; // We want to wait for a response
oXmlDoc.load("http://crm/ispcustomlookup/StartWorkflow.aspx?strProcessName=CompanySendEmail ReminderTask&strEntityID="
+ entityId + "&strEntityType=" + entityType);
var oNode = oXmlDoc.selectSingleNode("result");
if (oNode.text == "error") {
alert("An error occured while creating the 'Send Email Reminder' task
for Marketing.\nPlease contact the System Administrator to ensure that this
error is resolved.");
} else {
alert("The 'Send Email Reminder' task has been assigned to Marketing.");
}
}
} catch (ex) {
}
//1 and //2 work fine. Thereafter, it basically does nothing.
And the code for the Contact OnSave:
var validationErrors = false;
// 1.
try {
if (crmForm.customertypecode.value == 6 &&
crmForm.new_internalclientcategory.value.length == 0) {
alert("If 'Internal Client' is selected as a Relationship Type, then
Internal Client Category must be populated");
event.returnValue = false;
validationErrors = true;
}
} catch (ex) {
}
// 2.
try {
if (crmForm.new_profile.value== "4" &&
crmForm.new_mediacategory.value.length == 0) {
alert("If Profile is 'Media', Media Category must also be populated");
event.returnValue = false;
validationErrors = true;
}
} catch (ex) {
}
// 3.
try {
if (crmForm.FormType == 1) //CRM_FORM_TYPE_CREATE
{
// Get the current Contact Name and Surname and encode it for safe
URL transmittal
var firstName = encodeURIComponent(crmForm.all.firstname.DataValue );
var lastName = encodeURIComponent(crmForm.all.lastname.DataValue) ;
//alert("extracted " + firstName + lastName);
var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
oXmlDoc.async = false; // We want to wait for a response
oXmlDoc.load("http://crm/ISPCustomLookup/DuplicateCheck.aspx?firstname=" +
firstName + "&lastname=" + lastName);
var oNode = oXmlDoc.selectSingleNode("result");
//alert(oNode.text);
if (oNode != null && oNode.text == "True")
{
if(!confirm("A Contact with this name and surname already
exists in the system.\nAre you sure that you like to create a duplicate
entry?"))
{
event.returnValue = false;
validationErrors = true;
}
}
}
} catch (ex) {
}
// 4. Client Partner
try {
var clientPartner =
document.frames("IFRAME_ClientPartner").document.a ll("txtLink").innerText;
crmForm.new_clientpartner.value = clientPartner;
var previousclientPartner =
document.frames("IFRAME_PreviousClientPartner").do cument.all("txtLink").innerText;
crmForm.new_previousclientpartner.value = previousclientPartner;
var taskPartner=
document.frames("IFRAME_TaskPartner").document.all ("txtLink").innerText;
crmForm.new_taskpartner.value = taskPartner;
} catch (ex) {
}
// 5. Private Client --> Client Partner Link
try {
// Special case, the Client Partner had white space in it, so I trim before
doing length comparisons, clearly JScript doesn't do trim, so the Regex is
the next neatest thing.
// Special case 2. This does not apply to the create form, as the lookup
functionality doesn't work for non existent clients
var strResult;
var objRegex = new RegExp("(^\\s+)|(\\s+$)");
var strResult =
document.frames("IFRAME_ClientPartner").document.a ll("txtLink").innerText.replace(objRegex, "");
if ((crmForm.customertypecode.value == "3") && (strResult.length == 0 ||
crmForm.new_primaryservice.value.length == 0) && (crmForm.FormType != 1 &&
crmForm.FormType != 5)) {
alert("Each Private Client must have a Client Partner, and a Primary
Service.\nThis includes the 'Private Client' Relationship Type.");
event.returnValue = false;
validationErrors = true;
}
} catch (ex) {
}
// 7. Welcome Email
try {
if ((!validationErrors) && (crmForm.new_customertypecodeprevious.value ==
"Not Defined" &&
crmForm.customertypecode[crmForm.customertypecode.selectedIndex].text ==
"Private Client")) {
// GRAB THE ID OF THE CURRENT ENTITY FROM THE ADDRESS BAR
var entityId = crmForm.ObjectId;
var entityType = crmForm.ObjectTypeCode;
var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
oXmlDoc.async = false; // We want to wait for a response
oXmlDoc.load("http://crm/ispcustomlookup/StartWorkflow.aspx?strProcessName=ContactSendEmail ReminderTask&strEntityID="
+ entityId + "&strEntityType=" + entityType);
var oNode = oXmlDoc.selectSingleNode("result");
if (oNode.text == "error") {
alert("An error occured while creating the 'Send Email Reminder' task
for Marketing.\nPlease contact the System Administrator to ensure that this
error is resolved.");
} else {
alert("The 'Send Email Reminder' task has been assigned to Marketing.");
}
}
} catch (ex) {
}
Thanks for your assistance.
Mahmood
"MD" wrote: