function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
WhyserWhyser 

Lightning Button Passing Multiple Parameters to External URL

Hi everyone, I'm relatively new to Lightning so please be gentle.

I'm in the process of trying to replace javascript buttons with Lightning buttons, and I've come across and Opportunity button that navigates to an external URL that passes along a variety of parameters:

I wanted to create a Lightning button that navigates to this URL with a confirmation dialog prior to navigation, so I created a Lightning Component to try to achieve this.

At the time of this post, I did not create any apex controllers for this.

Component:
 
<aura:component                 implements="force:lightningQuickActionWithoutHeader,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" 
				access="global" >
	
    <!-- Include Static Resources - if any -->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

</aura:component>

Controller:
doInit: function( cmp, event, helper )
{
  // Obtain Parameters for URL
  var OpportunityId = cmp.get("v.recordId");
  var CustomerId = [??]; // Used to be {!Account.CustomerID__c}
  var API_Session_ID = [??]; // Used to be {!API.Session_ID}
  var API_Partner_Server_URL = [??]; // Used to be {!API_Partner_Server_URL_70}
  var User_Company_Id = [??]; // Used to be {!User.Company_Id__c}

  // Navigate to URL
  var urlEvent = $A.get("e.force:navigateToURL");
  urlEvent.setParams({
      "url": 'https://www.[website].com/action?" + [Parameters=Values List above]
   });

  // Confirm prior to navigation
  if ( confirm ("You are about to initiate a transaction on [website], please ensure you examine all necessary fields as per documentation" ))
  {
    urlEvent.fire();
  }
  
}

How do I obtain the parameters in order to achieve this? 

 
WhyserWhyser
Sorry, I forgot to include in the Component
<aura:attribute name="recordId" type="String" />

 
John ag 8John ag 8
Using data attribute of jQuery.ajax() / $.ajax() function. The data can be specified in different ways.
Read the documentation here jQuery API Documentation
Below are some examples
by GET Method: MyUserID and MyEmailAddress are variables holding your data to pass to server.


$.ajax({
url: "ajax.aspx",
type: "get", //send it through get method
data: {
id: 4,
UserID: MyUserID,
EmailAddress: MyEmailAddress
},
success: function(response) {
//Do Something
},
error: function(xhr) {
//Do Something to handle error
}
});



by POST method:

$.ajax({
url: 'ajax.aspx',
type: 'POST',
data: jQuery.param({ id: "4", UserID : "myusreid", EmailAddress: "MyEmailAddress"}) ,
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
success: function (response) {
//Do Something
},
error: function () {
//Do Something
}
});

Thanks
Sajjao (http://sajjao.com/english/bedding.html" target="_blank)