+ Start a Discussion
Nelly78Nelly78 

Javascript button with password help!

Not sure where I am going wrong but I need a javascript button to make a checkbox true...easy enough and Ive done it loads....but here I want the user to be prompted for a password which they enter and then the checkbox is marked true if they have the password correct. I have been trying the code below but I keep getting Error: The Name field is required

var ans=prompt("Please enter password","");
if(ans=="123"){

var newRecords=[];
var q=new sforce.SObject("Quote");
q.id="{!Quote.Id}";
if({!Quote.Override_Docusign__c}==false){
q.Override_Docusign__c=true;
newRecords.push(q);
result=sforce.connection.update(newRecords);
window.location.reload();
}
else
{alert
("Override already marked true");
}
else{
alert("Incorrect Password")
}
Best Answer chosen by Nelly78
Ankit Gupta@ DeveloperAnkit Gupta@ Developer
Hi,

Try the below code snippet as reference:
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js")}
sforce.connection.sessionId = "{!$Api.Session_ID}"
var ans = prompt("Please enter password", "");
if (ans == "123")
{
var newRecords = [];
var q = new sforce.SObject("Quote");
q.id = "{!Quote.Id}";
if ({!Quote.Override_Docusign__c} == false)
{
    q.Override_Docusign__c = true;
    newRecords.push(q);
    result = sforce.connection.update(newRecords);
    window.location.reload();
}
else
{
  alert("Override already marked true");
}
}
else
{
  alert("Incorrect Password")
}

Regards
Ankit Gupta

All Answers

Ankit Gupta@ DeveloperAnkit Gupta@ Developer
Hi,

Try the below code snippet as reference:
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js")}
sforce.connection.sessionId = "{!$Api.Session_ID}"
var ans = prompt("Please enter password", "");
if (ans == "123")
{
var newRecords = [];
var q = new sforce.SObject("Quote");
q.id = "{!Quote.Id}";
if ({!Quote.Override_Docusign__c} == false)
{
    q.Override_Docusign__c = true;
    newRecords.push(q);
    result = sforce.connection.update(newRecords);
    window.location.reload();
}
else
{
  alert("Override already marked true");
}
}
else
{
  alert("Incorrect Password")
}

Regards
Ankit Gupta
This was selected as the best answer
Nelly78Nelly78
Hi Ankit!
Many thanks it works perfectly!!!