You need to sign in to do that
Don't have an account?
Whyser
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:
Controller:
How do I obtain the parameters in order to achieve this?
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?
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)