Ask Search:
B2B AdministratorB2B Administrator 

javascript code for a custom button not working


I have created a button that when the user clicks on it the value of a checkbox field is changed to true.

I created a checkbox field in the credit request called IsEmailSend.When the user click the button "send contact information" I wrote a code that automatically changes this checkbox to true and then a workflow is fired and sends an email.

I have a problem with the code of the button. This is de code:


var update_CR = []; /*Declaring an array to pass the parameters */
var CR= new sforce.SObject("Credit_Request__c"); /* Declaring an object for the Credit request */
CR.Id='{!Credit_Request__c.Id}'; /*setting the ID of the object to the Id of the current credit request*/
CR.is_Email_Send__c = true; /* Setting the checkbox value as true */
update_CR.push(CR); /*pushing the updated object in queue*/
result_Update=sforce.connection.update(update_CR); /*updating the object*/
window.location.reload(); /* asking the page to refresh */

This button only updates the field IsEmailSend when Im logged as administrator, not when I am logged as any of my Sales Managers.

Could anyone help please?

Niket ChandaneNiket Chandane
Please check the access privileges for the field is_Email_Send__c and Object Credit_Request__c.
Charan VuyyuruCharan Vuyyuru
This looks every thing to be fine.

Check the permissions over the object for Sales Managers.




B2B AdministratorB2B Administrator
thanks for your help folks!

I forgot about the permissions!
Niket ChandaneNiket Chandane
 Thank you.
Alex PassoniAlex Passoni

that was very useful, I had the same needs for such button, but eventually need to show a pop-up -error -in the case the record does not update due to record validity rules. any suggestion ?

thanks in advance,
Alex PassoniAlex Passoni
I solved like this :

var newRecords = []; 

var c = new sforce.SObject("Opportunity"); ="{!Opportunity.Id}"; 
if (c.All_Data_Available__c == false){ 
alert("Some Data are missing - Cannot send order to Monitoring.<BR> Check Market, Environment, Documentation, Description") } 
else { 

c.Send_Now_to_Monitoring_Configuration__c = true; 
result = sforce.connection.update(newRecords); 
alert("The Email order to Monitoring was sent.") }