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
Sven FrancornelSven Francornel 

Lightning Component Framework Specialist Step 7 issue

Hello,
I am experiencing an issue while verifying step 7 of the Lightning Component Framework Specialist superbadge.

User-added image
The boat id is being set correctly when I filling in the form and the created record also has the Boat__c field filled in. I have been trying several ways to get past the verification, but I haven't been able to get past it. Does anyone see what I am doing wrong? Below you are able to see the onInit function.
 
onInit : function(cmp, evt) {
        cmp.find("service").getNewRecord(
            "BoatReview__c", 
            null,       
            false,     
            $A.getCallback(function() {                                 
                var error = cmp.get("v.recordError");
                if(error || (rec === null)) {
                    console.log("Error initializing record template: " + error);
                    return;
                }
                else {
                    var rec = cmp.get("v.boatReview");
                    rec.Boat__c = cmp.get('v.boat').Id;
                	cmp.set('v.boatReview', rec);
                }                
            })
        );
	}



 
Best Answer chosen by Sven Francornel
David M. ReedDavid M. Reed
I was able to complete the step by setting the attributes like this:
component.set('v.boatReview.Boat__c', component.get('v.boat').Id);

All Answers

Brian KesslerBrian Kessler
Does your code actually save?
You've used "rec" on line 08 before I see it declared.
While that is technically legal in JavaScript, I'm not sure LockerService allows it.
Anyway, if it is allowed, the value will be null and you'll never reach your else clause.
You probably want to move line 13 between 06 and 08.

Speaking of the else, you shouldn't need line 15.
As you are getting an object, it is passed by reference.

 
Brian KesslerBrian Kessler
Regarding my last comment:

While you do NOT need line 15, the geniuses who created the Trailhead apparently don't know JavaScript well enough.
So, you need it to pass, even though it is useless code.
Sven FrancornelSven Francornel
Thanks for the reply. Sorry, I didn't pay enough attention when I copied my code in here. This won't work as you mentioned, I tried several way and it got messed up eventually.

I changed it back to what I originally had and what you suggested, but that also isn't working.
 
onInit : function(cmp, evt) {
        cmp.find("service").getNewRecord(
            "BoatReview__c", 
            null,       
            false,     
            $A.getCallback(function() {                                 
                var rec = cmp.get("v.boatReview");
                var error = cmp.get("v.recordError");
                if(error || (rec === null)) {
                    console.log("Error initializing record template: " + error);
                    return;
                }
                else {                    
                    rec.Boat__c = cmp.get('v.boat').Id;
                    cmp.set('v.boatReview', rec);
                }                
            })
        );
}

 
David M. ReedDavid M. Reed
I was able to complete the step by setting the attributes like this:
component.set('v.boatReview.Boat__c', component.get('v.boat').Id);
This was selected as the best answer
Sven FrancornelSven Francornel
@David, I copied your line into my code and I was able to pass the challenge. I am usually using "component" in the controller and "cmp" in the helper. Since I just copied your line into my code, it actually wouldn't work when I would be trying to submit the form. So I am changing "cmp" to "component" in my helper file now.

Many thanks for the help!
 
BijaySBijayS
Hi All,

i get error when i click on the Add Review tab:

Here is my helperJS:
({
	onInit : function(component, event, helper) {
      component.find("service").getNewRecord(
        "BoatReview__c",
        null,
        false,
        $A.getCallback(function() {
          var rec = component.get("v.boatReview");
          var error = component.get("v.recordError");    
          if (error || (rec === null)) {
            console.log("Error initializing record template: " + error);
          } else {
            rec.Boat__c = component.get("v.boat").Id;
            component.set("v.boatReview", rec);
            console.log("Record template initialized: " + rec.sobjectType);
          }
        })
      );
    }
})

User-added image

Looks like its not able to read the Boat__c id, although i am passing the attribute from BoatDetails.
<lightning:tab label="ADD REVIEW">
            <c:AddBoatReview boat="{!v.boat}" />
        </lightning:tab>

Not sure whats wrong here,

Any help would be highly appreciated.