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
Sachin Bhalerao 17Sachin Bhalerao 17 

Attribute value is not capturing in controller.js file

Dear Team ,

Greetings !!!

In controller file this attribute value is not getting captured   var tempAccount = component.get('v.accObj');

I defined in component file in this way 

<aura:attribute name="accObj" type="Questions__c" default="{ 'sobjectType' : 'Questions__c',

                                                             'Name' : '',

                                                             'Does_Lightning_Component_uses_Javascript__c' : ''
                                                             }"/>



    <ui:inputText label="Name" value="{!v.accObj.Name}"/>

Please let me know where i am making mistake.

Thanks & Regards
Sachin Bhalerao
Best Answer chosen by Sachin Bhalerao 17
Devi ChandrikaDevi Chandrika (Salesforce Developers) 

Hi sachin,
If you want the attribute values you have to access them individually.
Try like this
var tempAccount = component.get('v.accObj');
var tempName = tempAccount.Name;

If you are not looking for this can you please share the complete code,so that i can help you.

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards

All Answers

Devi ChandrikaDevi Chandrika (Salesforce Developers) 

Hi sachin,
If you want the attribute values you have to access them individually.
Try like this
var tempAccount = component.get('v.accObj');
var tempName = tempAccount.Name;

If you are not looking for this can you please share the complete code,so that i can help you.

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards

This was selected as the best answer
Sachin Bhalerao 17Sachin Bhalerao 17
Hi Devi ,

Now m going to let you know the exact situation . M creating small project for optional test series in which user can select value from radio button and if this value get matched with default value of picklist in custom object data inserted in that field will be 1 . Plz have a look on sample code and snapshot of custom object 
Component

<aura:component controller="Matchpick" >
	 <aura:attribute name="options" type="List" default="[

       {'label': 'Yes', 'value': 'Yes'},
       {'label': 'No', 'value': 'No'},
       {'label': 'Sometime', 'value': 'Sometime'},  
       {'label': 'Partially', 'value': 'Partially'}, 
       ]"/>


  <aura:attribute name="optionChoosenRadio" type="Ques__c" default="{ 'sobjectType' : 'Ques__c',
                                                              'Quesone__c' : ''
                                                             }"/>
    
     <!-- <aura:attribute name="optionChoosenRadio" type="String" default="{ 'sobjectType' : 'Ques__c',
                                                              'Quesone__c' : ''
                                                             }"/>-->
    
    <!--<aura:attribute name="accObj" type="Ques__c" default="{ 'sobjectType' : 'Ques__c',
                                                              'Quesone__c' : ''
                                                             }"/>-->






 <div class = "slds-col slds-size--2-of-2 " style="display: inline;">
 <lightning:radioGroup name="radioGroup"
    label="Does Lightning Component uses Javascript"
    variant="label-inline"
    options="{!v.options }"
    value="{!v.optionChoosenRadio }"
    type="radio"
    required="true"/>
</div>

     <lightning:button label="Submit Ans" 
                                          class="slds-m-top--medium"
                                          variant="brand"
                                          onclick="{!c.handleChange}"/>   

</aura:component>

Apex class

public class Matchpick {
    
      @AuraEnabled
    public static Map<String, String> getques(){

        Map<String, String> options = new Map<String, String>();

        //get Account Industry Field Describe

        Schema.DescribeFieldResult fieldResult = Ques__c.Quesone__c.getDescribe();

        //get Account Industry Picklist Values

        List<Schema.PicklistEntry> pList = fieldResult.getPicklistValues();

        for (Schema.PicklistEntry p: pList) {

            //Put Picklist Value & Label in Map

            options.put(p.getValue(), p.getLabel());

        }

        return options;

    }
    
    
    
 @AuraEnabled //Save Questions Data

    Public static void createAccount(Ques__c objacc)
    {

        try{

            //Insert Questions Record

            insert objacc;

             

        }catch(Exception e){

            //throw exception message

            throw new AuraHandledException(e.getMessage());

        }

        finally {

        }

    }

}

Controller.js

({
	handleChange : function(component, event, helper) {
		//alert('hello');
		var a = component.get('v.options');
        

        var b = component.get('v.optionChoosenRadio');
       var c = component.get('v.accObj')
         helper.saveAccount(component, event);

	}
})

Helper.js

({
	 saveAccount : function(component, event) 
    {

        var acc = component.get("v.optionChoosenRadio");

        var action = component.get("c.createAccount");

        action.setParams({

            objacc : acc

        });

        action.setCallback(this,function(response){

            var state = response.getState();

            if(state === "SUCCESS"){
              var res = response.getReturnValue();
                alert('Record is Created Successfully');

            } else if(state === "ERROR"){

                var errors = action.getError();

                if (errors) {

                    if (errors[0] && errors[0].message) {

                        alert(errors[0].message);

                    }

                }

            }else if (status === "INCOMPLETE") {

                alert('No response from server or client is offline.');

            }

        });      

        $A.enqueueAction(action);

    }
})

User-added image

Thanks & Regards
Sachin Bhalerao
Sachin Bhalerao 17Sachin Bhalerao 17
M facing connection error problem . Plz have a look on snapshotUser-added image