[SalesForce] Error in $A.getCallback() [Cannot read property ‘setParams’ of undefined]

This page has an error. You might just need to refresh it.
Error in $A.getCallback() [Cannot read property 'setParams' of undefined]
Failing descriptor: {markup://c:OMSiteVisitFormLightning}

Hi,I'm getting this error.I'm new to lightning.please help…

My component-

<div style="slds">
    <div class="slds-page-header" role="banner">
  <div class="slds-grid">

    <div class="slds-col">

      <p class="slds-text-heading--label"></p>

      <h1 class="slds-text-heading--medium">Site Visit Form</h1>

    </div>

  </div>

</div>
    <br/>

<div class="slds-form--horizontal">
    <div class="slds-form-element">
        <label class="slds-form-element__label" for="inputSample2">Lead ID</label>
        <div class="slds-form-element__control">
            <ui:inputText aura:id="LeadID" class="slds-input"/>
        </div>
    </div>

    <div class="slds-form-element">
        <label class="slds-form-element__label" for="inputSample2">Mobile No.</label>
        <div class="slds-form-element__control">
            <ui:inputText aura:id="MobileNo" class="slds-input"/>
        </div>
    </div>

    <div>
        <ui:button label="Print" press="{!c.PrintData}"/>
    </div>


</div>
</div>

helper :

({
    getPrintData : function(component,LeadID,MobileNo) {
        var action = component.get("c.print");
        action.setParams({ strLeadNo : LeadID,strMobileno : MobileNo});
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS")
            {
                var url = response.getReturnValue();
                this.navigate(component,url);
                alert('url'+url+'state'+state);
            }
            else if(state === "INCOMPLETE")
            {
                alert('Incomplete');
            }
            else if(state === 'ERROR')
            {
                var errors = response.getError();
                if(errors)
                {
                    if (errors[0] && errors[0].message) 
                    {
                        console.log("Error message : "+errors[0].message);
                    }
                    else
                    {
                        console.log("Unknown Error");
                    }
                }
            }
        });
       $A.enqueueAction(action);
    },

        navigate : function(component, event, helper) {
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({url});
        urlEvent.fire();
}
})

Controller –

public class OMVisitFormLightning 
{
    @AuraEnabled
    public static string print(string strLeadNo,string strMobileno)
    {
        list<Lead> lstLead;
        if(strMobileno != null && strMobileno != '')
        {
            system.debug('strLeadNo'+strLeadNo);
            system.debug('strMobileno'+strMobileno);
            lstLead = [select id, name, OM_Lead_Number__c, MobilePhone, OM_Project__c, OM_Project__r.OM_SM_User__c from  Lead where 
                              OM_Lead_Number__c =:strLeadNo and MobilePhone =: strMobileno];
            system.debug('strLlstLeadeadNo'+lstLead);
            if(lstLead != null && lstLead.size() > 0)
            {
                if(lstLead[0].OM_Project__c != null)
                {
                    if(lstLead[0].OM_Project__r.OM_SM_User__c != null)
                    {
                        lstLead[0].ownerid = lstLead[0].OM_Project__r.OM_SM_User__c;
                        try
                        {
                            update lstLead;
                            string URL = 'https://omkar--sfdev--c.cs6.visual.force.com/apex/omGuestProfileFormPdf?id='+lstLead[0].id;
                            return URL;
                            /*PageReference objReference = new PageReference('/apex/omGuestProfileFormPdf?id='+lstLead[0].id);
                            objReference.setRedirect(true);
                            return objReference; */
                        }
                        catch(exception e)
                        {
                            //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getmessage()));
                            return null;
                        }
                    }
                    else
                    {
                        //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No SM Found For this Project.'));
                        return null;
                    }
                }
                else
                {
                    //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Project found unser the lead.'));
                    return null;
                }

            }
            else
            {
                //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please Ensure that you have entered correct Mobile No. and Lead.'));
                return null;
            }
        }

        else
        {
            //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please Enter Required Details' ));
            return null;
        }
        return null;
    }
}

I want to pagereference to another page but instead getting the error.

$A.getCallback() [Cannot read property 'setParams' of undefined]
Failing descriptor: {markup://c:OMSiteVisitFormLightning}

Please help

Best Answer

Maybe you have to declare the event with aura:registerevent in the XML part of the component, to declare to your component that it can fire such event