+ Start a Discussion
Baguiar2Baguiar2 

Get Id on NavigatetoURL link...

Hi there,

 

I have this button I've created that is supposed to submit a child object from an opportunity for approval. The submisison works As I manually test by entering the IDs on the URL, but I'm having an issue in getting the var "record", which is my MSA_requst__C object ID into the URL. here is the code:

 

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

var t1= new sforce.SObject("MSA_Requests__c" ); 
t1.Opportunity__c = "{!Opportunity.Id}"; 
result = sforce.connection.create([t1]); 

var resultMSA = sforce.connection.query("Select Id From MSA_Requests__c where Opportunity__C = '{!Opportunity.Id}' ");
var records = resultMSA.getArray("records");

for (var i=0; i<records.length; i++) {
    var record = records[i].id;
navigateToUrl('/p/process/Submit?id=record&retURL=%2F{!Opportunity.Id}');
}
if (!result[0].getBoolean("success")) 
{ 
alert("Failed to create MSA Request: " + result[0]); 
}

 on the NavigatetoURL , the id=record should be  the id of the MSA_request__C created.

 

Thanks for the help!!

 

B

Best Answer chosen by Admin (Salesforce Developers) 
Baguiar2Baguiar2

Found the issue. Had to "split" the URL due to the quotations... Should've thought of that.. :)

 

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

var t1= new sforce.SObject("MSA_Requests__c" ); 
t1.Opportunity__c = "{!Opportunity.Id}"; 
result = sforce.connection.create([t1]); 

if (!result[0].getBoolean("success")) 
{ 
alert("Failed to create MSA Request: " + result[0]); 
}
navigateToUrl('/p/process/Submit?id='+result[0].id+'&retURL=%2F{!Opportunity.Id}');