0

I have a JavaScript button which works fine in classic but doesn't show up in lightning, my guess that JavaScript buttons are not supported in lightning, I couldn't convert it using the converter since it is complicated, how can I write it to accomplish the same functionality, this is the button, it is called Pay Now (Partially):

{!requireScript("/soap/ajax/32.0/connection.js")} 

function isEmpty(val){ 
return (val === undefined || val == null || val.length <= 0) ? true : false; 
} 


var region = '{!PBSI__PBSI_Sales_Order__c.Stripe_Region__c }'; 

if(isEmpty(region)) 
{ 
region = '{!User.RegionText__c}'; 
} 

result = sforce.connection.query("Select Id from fw1__Payment_Processor__c WHERE Name='" + region + "'"); 
records = result.getArray("records"); 
if (result == null || result.size < 1) { 

/*alert('You need to setup the payment processor for this region (' + region + ') before making payment'); 
} else {*/
result=''
} 

var payment; 
payment = prompt('Please enter the payment amount.'); 
var RE = /^-{0,1}\d*\.{0,1}\d+$/; 
if(RE.test(payment)){ 

window.open('/apex/fw1__Payment?amount='+payment+'&accountId={!PBSI__PBSI_Sales_Order__c.PBSI__CustomerId__c}&lookupField=Sales_Order__c&lookupId={!PBSI__PBSI_Sales_Order__c.Id}&reference={!PBSI__PBSI_Sales_Order__c.Name}&contactId={!PBSI__PBSI_Sales_Order__c.PBSI__ContactId__c}&Currency={!PBSI__PBSI_Sales_Order__c.CurrencyIsoCode}&Lookupobject=PBSI__PBSI_Sales_Order__c&Description1={!PBSI__PBSI_Sales_Order__c.PBSI__Customer__c}&Description2=Final+Order+Value=+{!PBSI__PBSI_Sales_Order__c.Final_Order_Total_From_Quote2__c}&processor='+region+'&paidAmountField=Paid_Amount__c', '_blank', 'width=640,height=480'); 

} 
else{ 
alert('Invalid number'); 
}
6
  • Hey Roody Welcome to SFSE, What you have tried so far? – Rahul Gawale Nov 13 '18 at 9:27
  • I haven't tried anything, I will try to make a lightning component and put this logic inside its controller and see how it will work. – Roody Nov 13 '18 at 9:36
  • make that lightning component as lightning quick action, here is the link that might help you. – Rahul Gawale Nov 13 '18 at 9:50
  • I did that, and got this error: Action failed: c:PayNow$controller$doInit [requireScript is not defined] The required script is mentioned in line 1 from the code I wrote, it looks like it is not recognized. – Roody Nov 13 '18 at 12:20
  • Ok, you need not to add required script, for query part you have to move it to apex side : create @AuraEnabled method to make query and call it from your component, for inputs you need to use lightning:input tag. – Rahul Gawale Nov 13 '18 at 12:24
3

There are various guides/examples available for how to do this work. Two good ones I know of are:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.