+ Start a Discussion
MLeeMLee 

Detail Button Onclick JavaScript

Hello,
 
Can somebody please assist with the following query?
 
I have a custom object called "Meeting_Notes__c" that has an opportunity lookup on the page (not required). I would like to place a detail button that uses the JavaScript Onlick event at the top of the Meeting_Notes__c page.
 
If an opportunity has been entered I need to open the opprotunity edit page and update the opportunities "Next Step" and "Current Status" fields with data from the active meeting note record.
 
If there is not an opportunity I would like to alert the user that there is not a related opportunity and return to the active meeting note record.
 
This is what i have so far.
 
---------------------------------------------------------------------------------------------------------------------
 
{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
 
//establish connection to SF
var connection = sforce.connection;

//Query meeting note and retrieve related Opportunity ID
var meetingnoteId = "{!Meeting_Notes__c.Id}";
var qr = connection.query("Select Meeting_Notes__c.OpportunityId__c From Meeting_Notes__c
Where Meeting_Notes__c = '" + meetingnoteId + "'");
 
//Declare Opportunity variable
var meetingnoteOpp ="{!Meeting_Notes__c.OpportunityId__c}";
 
//If an opportunity is populated edit opportunity else alert user that there is not an opportunity
if (meetingnoteOpp != 'NULL')
 {
       open(https://tapp0.salesforce.com/{!Meeting_Notes__c.OpportunityId__c}/e?retURL=%{!Meeting_Notes__c.OpportunityId__c}&opp10={!Meeting_Notes__c.Next_Step__c}&00N30000001B3x7={!Meeting_Notes__c.Current_Status__c})
 }
else
 {
       alert("This is a test")
 }
)
 
--------------------------------------------------------------------------------------------
 
Thank you in advance - MLee
DrawloopDrawloop
{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}

var connection = sforce.connection;

var meetingnoteOpp = "{!Meeting_Notes__c.OpportunityId__c}";

if (meetingnoteOpp && meetingnoteOpp != "")
{
    var opp = new sforce.SObject("Opportunity");
    opp.Id = meetingnoteOpp;
    opp.NextStep = "new value";
    opp.CurrentStatus_Field__c = "new value";
    connection.update([opp]);
    alert("Done.");
}
else
{
    alert("There is no Opportunity related to this note.");
}