• Mark Jaundoo
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

Is it possible to use a custom button to create a new record? I'd like to put the button on a custom object (Task Order__c) and have it create a new Opportunity, pulling information from the Task Order into the Opportunity fields. I would also like to be able to specify the record type of the new Opportunity. I have cobbled this together based on some examples I found of other buttons. Am I on the right track? Thanks in advance.

 

Here is what I am trying:

 

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
var newopportunity= new sforce.SObject("Opportunity");
newopportunity.Name = "my new opportunity";
newopportunity.Account="{!Task_Order__c.Account__c}";
newopportunity.StageName="Active";
newopportunity.CloseDate=new Date();
newopportunity.Student_Name__c="TBD";
var result = sforce.connection.create([newopportunity]);
window.location.reload();

 

Hi all -


I'm struggling with how to set a date field to today() using a custom button's on click javascript.

 

I'm using the button to set the value of two picklist values, set a date field to Today() and set a second date field to Today()+180.

 

When I first wrote it and tested it earlier in the week, it was executing but was setting the wrong dates. Today it just errors out.

 

 

{!requireScript("/soap/ajax/13.0/connection.js")} var QR= new sforce.SObject("Quote_Request__c"); QR.id = "{!Quote_Request__c.Id}"; var temp_dev_date=new Date(); temp_dev_date.setDate({!TODAY()}) var temp_val_date=new Date(); temp_val_date.setDate({!TODAY()}+180) QR.Delivered_Date__c=temp_dev_date; QR.Validity_Date__c=temp_val_date; QR.Customer_Requirements__c="Test update of auto close button."; QR.Status__c="Closed - Completed"; QR.Stage__c="Delivered"; var result = sforce.connection.update([QR]); if (result[0].getBoolean("success")) { // Refresh window window.location.reload(); } else { alert("something broke"); }

 

Appreciate any guidance or other approaches that could be used to accomplish this.