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
Sudipta Ghosh 9Sudipta Ghosh 9 

Closing the Modal using X on the top right still creates a Task - e.force:createRecord

I am using e.force:createRecord to create Task. When the Task window opens I do nothing - just close it using X on the top right corner of the modal. But still it creates a Task. Any way to rectrict that

lightning:button class="form-control" aura:id="btnTask" label="Create Task" onclick="{!c.createTask}"/>
createTask : function (component, event, helper) {   
    var task= $A.get("e.force:createRecord");
    task.setParams({
        "entityApiName": "Task",
        "defaultFieldValues": {
            'Subject' :' Test Task' 
       }
            });
           createRecordEvent.fire();
}
AngrySlothAngrySloth
Without seeing the rest of your component markup it is hard to tell what is happening.  Are you using the Lightning Design System in your component to create your modal? If so what is your onclick event on the "X" icon button?  It should be a method in your component controller that simply toggles/removes the class 'slds-hide' on the '.slds-modal' element.
Sudipta Ghosh 9Sudipta Ghosh 9
@AngrySloth - This is not any my self designed modal. Isn't e.force:createRecord automatically creates a modal like page; here to create a Task.
This is all the code for my component and controller.

Regards
Sudipta
AngrySlothAngrySloth
Sorry Sudipta I misunderstood.  I think you need to change:

createRecordEvent.fire();

to

task.fire();

based on the code from the original post
Sudipta Ghosh 9Sudipta Ghosh 9
Applogies, I didn't change the variable name during post.  My updated code - don't think code has any issue but if e.force:createRecord provides any opportunity to handle the event.

lightning:button class="form-control" aura:id="btnTask" label="Create Task" onclick="{!c.createTask}"/>
createTask : function (component, event, helper) {   
    var task= $A.get("e.force:createRecord");
    task.setParams({
        "entityApiName": "Task",
        "defaultFieldValues": {
            'Subject' :' Test Task' 
       }
            });
           task.fire();
}