0

I am launching a Subtab using the Lightning Workspace API, and using an Aura pageReference object to specify that I want to create a new Task.

I want to pre-populate the WhatId on the Task when the new standard__object tab opens.

I set the WhatId in the state I want to pass into the pageReference object:

var workspaceAPI = component.find("workspace");
var recordId = component.get("v.recordId") // confirmed this is my intended WhatId recordId
workspaceAPI.getEnclosingTabId().then(function(enclosingTabId) {
    workspaceAPI.openSubtab({
            parentTabId: enclosingTabId,
            pageReference: 
            {    
                "type": "standard__objectPage",
                "attributes": {
                    "objectApiName": "Task",
                    "actionName": "new"
                },
                "state": {
                    "WhatId": recordId
                }
            }
        }).then(function(subtabId) {
            console.log("The new subtab ID is:" + subtabId);
        }).catch(function(error) {
            console.log("error");
        });
    })
.catch(function(error) {
    console.log(error);
});

But it doesn't appear to be passing the input as a query parameter - and when the new record lightning component opens in the subtab the Related: input field is blank.

0

I figured out the appropriate answer is to use the force:createRecord event:

var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
    "entityApiName": "Task",
    "defaultFieldValues": {
         // "WhatId": 
    }
});
createRecordEvent.fire();

Also, it appears that when fired from within a subtab this event will open a new subtab, I am not sure if it works the other way around.

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.