function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Erik LarameeErik Laramee 

javascript button triggering validation rule

Hey Folks, I have a validation rule on a field for NOT( ISCHANGED) ). I have a button that is triggering this rule when pressed even though the field has been changed. I can't figure out a way around it. Any ideas? This is the button:

{!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")} 

try { 
var newRecords = []; 
var c = new sforce.SObject("Request_for_Information_RFI__c"); 
c.id ="{!Request_for_Information_RFI__c.Id}"; 
c.Submit_RFI__c= true; 
c.Approval_Submitted__c= true; 
newRecords.push(c); 
result = sforce.connection.update(newRecords); 

if( result[0].getBoolean( "success" ) ) { 
window.location.reload(); 

else { 
alert( "An error has occurred. Error:" + result ); 


catch( e ) { 
alert( "An unexpected error has occurred. Error:" + e ); 
}
Best Answer chosen by Erik Laramee
Shruti SShruti S
In the button click, you are changing Submit_RFI__c and Approval_Submitted__c fields. But in your validation rule, you are checking for NOT(ISCHANGED) on some other field which is not getting changed on your button click. Hence you should modify your formula as below - 
AND(
	NOT( ISCHANGED( Field__c ) ),
	RecordTypeId = "01280000000U9s6",
	$User.ProfileId = "00e4C000000YMVM",
	NOT( ISCHANGED( Submit_RFI__c  ) ),
	NOT( ISCHANGED( Approval_Submitted__c  ) )
)
Please feel free to get back if you have any more doubts.

All Answers

SalesFORCE_enFORCErSalesFORCE_enFORCEr
Please share your validation rule.
Erik LarameeErik Laramee

Thanks, I will give that a shot. It's in use in our customer portal. If it's a customer portal profile and the record type, it should fire if Field__c is not changed.

AND(
NOT( ISCHANGED( Field__c ) ),
RecordTypeId = "01280000000U9s6",
$User.ProfileId = "00e4C000000YMVM" )

Shruti SShruti S
In the button click, you are changing Submit_RFI__c and Approval_Submitted__c fields. But in your validation rule, you are checking for NOT(ISCHANGED) on some other field which is not getting changed on your button click. Hence you should modify your formula as below - 
AND(
	NOT( ISCHANGED( Field__c ) ),
	RecordTypeId = "01280000000U9s6",
	$User.ProfileId = "00e4C000000YMVM",
	NOT( ISCHANGED( Submit_RFI__c  ) ),
	NOT( ISCHANGED( Approval_Submitted__c  ) )
)
Please feel free to get back if you have any more doubts.
This was selected as the best answer
Erik LarameeErik Laramee
Thank you Shruti! You have saved me much hand-wringing and hair tearing!!!