+ Start a Discussion
Irish@accIrish@acc 

pop up window to ask user for input either yes/No

Hi I'd like to create a pop up window which will have to value either Yes or No and when the user click on "Yes" it creates the Record and when the user click on NO nothing will happen...

 

please help me on this...this I want to achieve in javascript

Best Answer chosen by Admin (Salesforce Developers) 
Naidu PothiniNaidu Pothini
if(window.confirm("test") == 'true')
{
  // have your code here
}
else
{
  // don't do anything.
}

 try this.

All Answers

souvik9086souvik9086

Hi,

 

You can use this

 

function confirmYesNo() {
var isCancel = confirm("Are you sure you want to create new record?");

if (isCancel){
CallApexMethod();
return true;
}

 

<apex:actionFunction name="CallApexMethod" action="{!addNewRecord}" >
</apex:actionFunction>

 

<apex:commandButton onclick="return confirmCancel()" title="Add New Record" Style="color:#fff;"/>

 

This is invoking apex method(addNewRecord) through javascript. And there is a confirmation screen will come after clicking the button. If you click Ok then it will call the apex method.

 

If this post solves your problem, kindly mark it as solution.

 

Thanks

 

Irish@accIrish@acc

How do i use this in my Code...
below is my code but it's not asking for confirmation ..I'd like to use a confirmation here before creating the record....

 

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

{!REQUIRESCRIPT("/soap/ajax/27.0/apex.js")}
var url = parent.location.href;

var prjid='{!Project__c.Id}';

var TaskId='{!Task__c.Id}';


result = sforce.connection.query("Select Status__c,id,Project__c from Task__c where Status__c not in ('Complete','Cancelled') and Project__c='"+prjid +"'");



var records = result.getArray("records");
var date = new Date('{!TODAY()}'); 
var i = records.length;
if(i>0)
   {
    
 
   window.alert("All Tasks need to be completed before the project can be closed.");
   parent.location.href = url;
}
else{
//creating Record here....
var createqod = new sforce.SObject("Quality_of_delivery__c"); 
createqod.Project__c = "{!Project__c.Id}"; 
createqod.Name = "{!Project__c.Name} " +" - "+"FINAL";
//createqod.Approved_Status__c="Pending input from Dev Specialist";
createqod.Number_of_Change_Requests__c=0;
createqod.date__c=date;
createqod.Final__c="True";
createqod.Dev_Lead__c="{!Project__c.Dev_Lead_UserId__c}";

sforce.connection.create([createqod]);
window.alert("A final Quality of Delivery and Root Cause records have been created for the project. It needs to be updated and approved by Dev Lead - only then the project will be closed");

var updateProjectState = new sforce.SObject("Project__c");
updateProjectState.id="{!Project__c.Id}";
updateProjectState.Project_state__c="In Closing";
sforce.connection.update([updateProjectState]);
parent.location.href = url;
}

 

asish1989asish1989

Hi
you need to write like this 

 

var prjid='{!Project__c.Id}';

var TaskId='{!Task__c.Id}';

change these two lines by this 
var prjid = {!GETRECORDIDS( $ObjectType.Project__c)};

var TaskId = {!GETRECORDIDS( $ObjectType.Task__c)}; 
alert(prjid);
alert(TaskId);

check whether id  displayed in the popup or not

 I have not checked your complite code, you need to do that

 if this post answers your question then please mark it as solutions so that It can be further referred .

If this post really helps you then hit kudos

 

  Thanks

Naidu PothiniNaidu Pothini
if(window.confirm("test") == 'true')
{
  // have your code here
}
else
{
  // don't do anything.
}

 try this.

This was selected as the best answer
Irish@accIrish@acc

This is exactly what I was looking for..thanks

but there is a change...True will be withou quote.