You need to sign in to do that
Don't have an account?

how to convert the Validation rule from Server side to client side using Java Script in salesforce
Hi ,
I have stuck with the Validation Rules using the Java Script , Can anyone help me out from this.
I have implemeted the Validation rule for the Server Side , but i have stuck with it in implemeting it in Java Script.
This is the Validation rule that i have implemented for Server Side for Multiple Stage and the same i want to implemet it in Client Side using the Java scripe
Here is the Server side Validation Rule
OR
(
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR( ISPICKVAL(CRM_Stage__c,"Stage 3: National/CEO Interviews")), CRM_Gender__c =""),
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR(ISPICKVAL(CRM_Stage__c,"Stage 4: Board Interviews")), CRM_Gender__c =""),
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR(ISPICKVAL(CRM_Stage__c,"Stage 5: Board Package Finalization")), CRM_Gender__c =""),
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR( ISPICKVAL(CRM_Stage__c,"Stage 6: Package Review")), CRM_Gender__c =""),
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR(ISPICKVAL(CRM_Stage__c,"Stage 7: Approved/Agreement Finalization")), CRM_Gender__c =""),
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR(ISPICKVAL(CRM_Stage__c,"Stage 8: Provisioning/On-Boarding")), CRM_Gender__c =""),
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR(ISPICKVAL(CRM_Stage__c,"Stage 9: On-Board")), CRM_Gender__c =""))
And here is my Java script cod efor Validation rule
else if(voptygender== "" && (voptystage == 'Stage 3: National/CEO Interviews'))
{
alert("Race is a required for Stage 3: National/CEO Interviews");
document.getElementById('{!$Component.formid.op.keyid.optyrace}').focus();
}
This is working for only one Stage , but when i have implemeted it for the Multiple Stages it is throwing error whe it is in blank stage that is fine , but when i have save it with without blank with Specified message it has to save it but still it is throwing error
Here is the Code that i have implented for the Multiple stages using Java Script
else if(voptygender == "" && (voptystage == 'Stage 3: National/CEO Interviews') || (voptystage == 'Stage 4: Board Interviews') || (voptystage == 'Stage 5: Board Package Finalization') || (voptystage == 'Stage 6: Package Review') || ( voptystage == 'Stage 7: Approved/Agreement Finalization') || (voptystage == 'Stage 8: Provisioning/On-Boarding') || ( voptystage== 'Stage 9: On-Board'))
{
alert("Gender is a required for Stage 3: National/CEO Interviews");
document.getElementById('{!$Component.formid.op.keyid.optygender}').focus();
}
Can Anyone correct me where exactly i gone wrong
Reagrds
Micky
I have stuck with the Validation Rules using the Java Script , Can anyone help me out from this.
I have implemeted the Validation rule for the Server Side , but i have stuck with it in implemeting it in Java Script.
This is the Validation rule that i have implemented for Server Side for Multiple Stage and the same i want to implemet it in Client Side using the Java scripe
Here is the Server side Validation Rule
OR
(
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR( ISPICKVAL(CRM_Stage__c,"Stage 3: National/CEO Interviews")), CRM_Gender__c =""),
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR(ISPICKVAL(CRM_Stage__c,"Stage 4: Board Interviews")), CRM_Gender__c =""),
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR(ISPICKVAL(CRM_Stage__c,"Stage 5: Board Package Finalization")), CRM_Gender__c =""),
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR( ISPICKVAL(CRM_Stage__c,"Stage 6: Package Review")), CRM_Gender__c =""),
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR(ISPICKVAL(CRM_Stage__c,"Stage 7: Approved/Agreement Finalization")), CRM_Gender__c =""),
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR(ISPICKVAL(CRM_Stage__c,"Stage 8: Provisioning/On-Boarding")), CRM_Gender__c =""),
AND(OR(RecordTypeId ="01250000000UKjw",RecordTypeId="01250000000UKjv", RecordTypeId ="01250000000UMZm"),OR(ISPICKVAL(CRM_Stage__c,"Stage 9: On-Board")), CRM_Gender__c =""))
And here is my Java script cod efor Validation rule
else if(voptygender== "" && (voptystage == 'Stage 3: National/CEO Interviews'))
{
alert("Race is a required for Stage 3: National/CEO Interviews");
document.getElementById('{!$Component.formid.op.keyid.optyrace}').focus();
}
This is working for only one Stage , but when i have implemeted it for the Multiple Stages it is throwing error whe it is in blank stage that is fine , but when i have save it with without blank with Specified message it has to save it but still it is throwing error
Here is the Code that i have implented for the Multiple stages using Java Script
else if(voptygender == "" && (voptystage == 'Stage 3: National/CEO Interviews') || (voptystage == 'Stage 4: Board Interviews') || (voptystage == 'Stage 5: Board Package Finalization') || (voptystage == 'Stage 6: Package Review') || ( voptystage == 'Stage 7: Approved/Agreement Finalization') || (voptystage == 'Stage 8: Provisioning/On-Boarding') || ( voptystage== 'Stage 9: On-Board'))
{
alert("Gender is a required for Stage 3: National/CEO Interviews");
document.getElementById('{!$Component.formid.op.keyid.optygender}').focus();
}
Can Anyone correct me where exactly i gone wrong
Reagrds
Micky
What is the error that you are getting, and on which line and which keyword you are getting the error.
Did you try debug logs?
As you said it is working fine for one stage, i believe the sysntax for ispick val - if else has to be checked once.
Regards,
Ashish
Use this code,
else if
(voptygender == "" &&
(
(voptystage== 'Stage 3: National/CEO Interviews') ||
(voptystage == 'Stage 4: Board Interviews') ||
(voptystage == 'Stage 5: Board Package Finalization') ||
(voptystage == 'Stage 6: Package Review') ||
(voptystage == 'Stage 7: Approved/Agreement Finalization') ||
(voptystage == 'Stage 8: Provisioning/On-Boarding') ||
(voptystage== 'Stage 9: On-Board')
)
)
{ alert("Gender is a required for Stage 3: National/CEO Interviews"); document.getElementById('{!$Component.formid.op.keyid. optygender}').focus(); }
Looks like, after the && it is checking only the first condition.
I added a extra set of braces to the 2nd conditioin, if any of the option returns true as a whole it will work.
Reply back if this goes through .
Regards,
Ashish