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
katy perrykaty perry 

need some urgent help, I am very new to ssalesofrce and I am fully confused with lightning. I have a javascript button to validate some fields and then will allow to take PDF of a visualforce page. Now I need to migrate this JS button to use in Lightning.

 need some urgent help,
I am very new to ssalesofrce and I am fully confused with lightning. I have a javascript button to validate some fields and then will allow to take PDF of a visualforce page. Now I need to migrate this JS button to use in Lightning. Please help me with this. 
Here is the JS button.

{!REQUIRESCRIPT("/soap/ajax/38.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/38.0/apex.js")}
 
        var PurchaseOrder = sforce.connection.query("SELECT Id, isPDFGenerated__c, ItemsCount__c, POReleaseDate__c, TotalQuantityPercentage__c FROM PurchaseOrders__c WHERE Id ='{!PurchaseOrders__c.Id}'");
        varPOrecords = PurchaseOrder.getArray("records");

        if(varPOrecords[0].isPDFGenerated__c == 'true' || varPOrecords[0].isPDFGenerated__c == true){ 
        alert("PDF already generated.\n\nPlease contact your Salesforce Admin to generate again."); 
        }
        else if(varPOrecords[0].ItemsCount__c == 0){ 
        alert("Purchase Order cannot be generated without items."); 
        }
        else if(varPOrecords[0].POReleaseDate__c == null || varPOrecords[0].POReleaseDate__c == ''){ 
        alert("Please enter Release Date."); 
        }
        else if(varPOrecords[0].TotalQuantityPercentage__c != 100){ 
        alert("Delivery Terms Total Quantity cannot be less than 100%"); 
        }                        
        else{
        if(confirm("Are you sure, you want to generate Purchase Order PDF?\n\nClick OK or Cancel.")){
        var result = sforce.apex.execute("GeneratePOPDF","saveGeneratePdf",{poId:varPOrecords[0].Id}); 
        window.location.reload();
        }
        }
sfdcMonkey.comsfdcMonkey.com
hi katy perry
javaScript button is not support in lightning experience
here is Lightning Alternatives to JavaScript Buttons
https://trailhead.salesforce.com/modules/lex_javascript_button_migration
read this trailhead moudle for understand it
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others , thanks :)
http://sfdcmonkey.com
Amit Singh 1Amit Singh 1
Hi Katy,

JavaScript button is not supported in lightning in order to make JavaScript button work in lightning you need to create Quick Action in lightning.

Below is the example for quick create Case with Component and Controller.js code.

Component Code. 
<aura:component controller="caseQuickCreateController"
                implements="force:lightningQuickAction,force:hasRecordId">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="accList" type="Account[]" />
    <aura:attribute name="isHidden" type="Boolean"/>
    <aura:iteration items="{!v.accList}" var="acc">
        <ui:outPutText value="{!acc.Id}"/>&nbsp; &nbsp;<ui:outPutText value="{!acc.Name}"/>
        &nbsp; &nbsp;<ui:outPutText value="{!acc.Industry}"/><br/>
    </aura:iteration><br/>
    <br/>
    <ui:inputText aura:id="name" /><br/> <br/>
    <ui:inputDate aura:id="date" /> <br/> <br/> 
    <ui:button label="Submit" press="{!c.showText}"/>
    <br/><br/>
    <aura:if isTrue="{!v.isHidden}">
        <ui:outputText value="This is hidden text which will show after clicking on the submit button"/>
    </aura:if>
    <br/>
    <br/>
    <lightning:buttonGroup >
        <lightning:button label="Refresh" iconName="action:refresh" onclick="{!c.refreshRecord}"/>
        <lightning:button label="Edit" iconName="utility:edit" onclick="{!c.editRecord}"/>
        <lightning:button label="Save" iconName="utility:emoji" />
        <lightning:button label="Create New Case" iconName="action:new_case" onclick="{!c.createRecord}"/>
    </lightning:buttonGroup>        
</aura:component>

JavaScript Code:
({
	doInit : function(component, event, helper) {
		var action = component.get("c.getCases");
        component.set("v.isHidden",false);
        action.setParams({
            "caseId" : component.get("v.recordId")
        });
        action.setCallback(this, function(response){
           var state = response.getState();
            //alert(state);
            if(component.isValid() && state ==='SUCCESS'){
                var caseList = response.getReturnValue();
                //alert(caseList);
                component.set("v.accList",caseList);
            }else{
                console.log('Error');
            }
        });
        $A.enqueueAction(action);
	},
    showText : function(component, event, helper){
        //alert('Clicked');
        component.set("v.isHidden",true);
        //$A.get("e.force:refreshView").fire();
    },
    editRecord : function(component, event, helper) {
        var editRecordEvent = $A.get("e.force:editRecord");
        editRecordEvent.setParams({
             "recordId": component.get("v.recordId")
       });
        editRecordEvent.fire();
    },
    refreshRecord : function(component, event, helper) {
        $A.get("e.force:refreshView").fire();
    },
    createRecord : function (component, event, helper) {
        var createRecordEvent = $A.get("e.force:createRecord");
        createRecordEvent.setParams({
            "entityApiName": "Case"
        });
        createRecordEvent.fire();
	}
})
Also, visit 
https://trailhead.salesforce.com/modules/lex_javascript_button_migration (https://trailhead.salesforce.com/modules/lex_javascript_button_migration" rel="nofollow" style="outline: 0px; color: rgb(4, 142, 198) !important; text-decoration: none !important;) Link read the trail head module which will help you to understand JavaScript alternative into Lightning,
 
Thanks,
Amit Singh.