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
sfg1sfg1 

Bypass validation rule using Javascript

I have made 3 fields required using validation rule.I have javascript button for closing case. When these 3 fields are null and if i try to close the case by  clicking on javascript button, I am not able to close the case.
Now my requirement is either it should bypass the validation or populate 3 field values once i click on the javascript button.Please guide me in this.
Vishal_GuptaVishal_Gupta
Hi Dhana,

Can you share your javascript button code.

Thanks,
Vishal
AshesAshes
There are two ways:
1. you can use before update trigger to auto populate these values
2. On button click, by using id you can access those fields and auto populate the default values.
sfg1sfg1
Hi Vishal,
i am trying to close the Case as duplicate using javascript button.Now my requirement is before closing the case i need to fill 3 Date/time required fields Case Assigned,Workaround Provided and Restored.Please find my code.
{!REQUIRESCRIPT("/soap/ajax/16.0/connection.js")}
{!requireScript("/soap/ajax/19.0/function.js")}
{!requireScript("/soap/ajax/19.0/apex.js")}

var URL1 = "/apex/closeCaseAsDuplicate?arun_id={!Case.Id}";
var URL2 = "/{!Case.Id}";

if( {!ISPICKVAL(Case.Status , 'Closed')} )
{
alert('The Case you wish to Close As Duplicate is already Closed! Please choose a different case to close.');

}
else
{
if(confirm('You are about to Close this Case As a Duplicate - Are you sure?'))
{
window.location.href = URL1;
}
else
{
window.location.href = URL2;
}

}
 
Vishal_GuptaVishal_Gupta
Hi Dhana,

I think there is no need to navigate on new page to just closed a case, you can achieve it using following code in javascript button.
 
{!REQUIRESCRIPT("/soap/ajax/16.0/connection.js")}
{!requireScript("/soap/ajax/34.0/function.js")}
{!requireScript("/soap/ajax/34.0/apex.js")}

var URL = "/{!Case.Id}";

if( {!ISPICKVAL(Case.Status , 'Closed')} )
{
  alert('The Case you wish to Close As Duplicate is already Closed! Please choose a different case to close.');
}
else 
{
	if(confirm('You are about to Close this Case As a Duplicate - Are you sure?'))
	{
		var vCase = new sforce.SObject("Case");
		vCase.Id = '{!Case.Id}';
		vCase.Status = 'Closed';
		if('{!ISNULL(Case.CaseAssigned__c)}') //use your field api name here
		{
			vCase.CaseAssigned__c = new Date();//aassign your default value here
		}
		if('{!ISNULL(Case.WorkaroundProvided__c)}') //use your field api name here
		{
			vCase.WorkaroundProvided__c = new Date();//aassign your default value here
		}
		if('{!ISNULL(Case.Restored__c)}') //use your field api name here
		{
			vCase.Restored__c = new Date();//aassign your default value here
		}
		
		var caseArr = [];
		caseArr.push(vCase);

		var results = sforce.connection.update(caseArr); 
		if (results[0].getBoolean("success")) { 
		window.parent.open(url, "_self");
		} else { 
		alert("Failed to create Task " + results[0]); 
		}
	}
}
Please let me know if it will work for you.

Thanks,
Vishal
sfg1sfg1
Thanks for your  reply VIshal.
The reason i am navigating to new page is, there i will select duplicate case number.so that i can close the case. My Datetime datatype 3 fields should be in this format  8/26/2015 12:47 AM. Please help me in this.
Vishal_GuptaVishal_Gupta
Hi,

How you find duplicate Case on your new page, means what is the common between two duplicate cases. Is it name or some other logic.

I am asking this question because we can find the duplicate case in your javascript button code and can close as well.

Thanks,
Vishal
aneelu vaddadianeelu vaddadi
Can anyone will be able to help me with this scenario : when a close button clicked then closed notes required for all case types(RMA, Customer, Internal, external ) and there is one more requirement if case type is "depot" then closed notes , close date and actual resolution date should be required. how to acheive this. Any help is appreciated.