3

On the Lightning for Outlook, I do have a record creation button component. Clicking on it gets the custom record type selection. Based on what we choose(radio button), force:createRecord event fires.

Ltng.cmp

<aura:iteration items="{!v.RTypeList}" var="rType"> 
   <span class="slds-radio">
        <input type="radio" aura:id = "radioId"  id="{!rType}" name="options" value="{!rType}" />
        <label class="slds-radio__label" for="{!rType}">
           <span class="slds-radio--faux"></span>
           <span class="slds-form-element__label">{!rType}</span>
        </label>
       </span>
  </aura:iteration>

NOTE: RTypeList contains all the record type labels(using controller class).

Cmp.Js

var rTypeLabel= document.querySelector('input[name="options"]:checked').value;
    var action = component.get("c.getRTypeId");

    action.setParams({
        "rTypeLabel": rTypeLabel
    });

    action.setCallback(this, function(response) {
    var state = response.getState();
    if (state === "SUCCESS") {
            var createRecordEvent = $A.get("e.force:createRecord");
            var RTID  = response.getReturnValue();
            createRecordEvent.setParams({
                "entityApiName": 'Account',
                "recordTypeId": RTID  
            });
            createRecordEvent.fire();

        } else if (state === "ERROR") {
           alert("ERROR! Please contact support!");
        }
     });
    $A.enqueueAction(action);

Controller.apxc

@AuraEnabled
public static Id getRTypeId(String rTypeLabel){
    System.debug('From Class: ' +rTypeLabel);
    if(rTypeLabel!= ''){
        Id rtypeid = Schema.SObjectType.Account.getRecordTypeInfosByName().get(recordTypeLabel).getRecordTypeId();        
        return rtypeid ;
    }
    return null;
}

Every time I run this component on an LightningAPP (to preview), debug log returns me the correct record type label. But when I run this same component on the "Lightning for Outlook", I get the log as "From Class: on" thus throwing me the error. Where I am doing wrong?

2

Well, after spending few extra hours than usual, I was able to fix it. The problem with my code lies within the document.querySelector. As per my <input type="radio" implementation, I do not need value, rather I need to query id. Like this:

var rTypeLabel= document.querySelector('input[name="options"]:checked').id

But hey, when I query 'value' instead of 'id', it worked well on Google Chrome(verified console) and I got the state as SUCCESS. But on the Internet Explorer and the Lightning For Outlook plugin, it didn't worked. So my trial-and-error with id worked on both. Hope someone who's stuck with this kind of issue find my post helpful.

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.