-2

I'm trying to print the data object but the console is showing me only the word inside. I have attached an image of my current problem. The concept of this code is to get the value inside a input element and store inside an object. I'm currently using Ractive.js.

enter image description here

HTML:

<div class="form-element-container">
    <label>Company Name <span class="required">*</span></label>
    <input type="text" class="form-text full-width" placeholder="Enter the company name" id="accountName" value="{{leadData.accountName}}"/>
</div>


<div class="form-element-container default-cta-container">
    <a class="button cta" on-click="addLead">Create Account</a>
</div>

Javascript:

app.on('addLead', function(event) {
    var lmsleadData  = {}
    var data         = app.get('leadData');
    var proxy        = app.get('proxy');
    var endpoint     = 'account/leads/';
    var rt           = 'POST';
    var url          = proxy+'?endpoint='+endpoint+'&rt='+rt;

   function setvalueData(leadData, data) {
        var lmsleadData     = {
            "isProfiled": false,
            "isBaluarte": false,
            "isVertical": false,
            "isAffiliate": false,
            "isBranch": false,
            "id": 0,
            "dateRequested": "2017-01-12",
            "accountIdFk": 0,
            "accountLeadId": 0,
            "accountName": leadData.accountName,
            "assignedEmployeeIdFk": 0,
            "unitNumber": "34",
            "floorNumber": "30",
            "buildingName": "Test bldg name 34",
            "streetNumber": "123",
            "streetName": "Test street name",
            "barangayIdFk": 0,
            "cityTownIdFk": 0,
            "provinceIdFk": 0,
            "regionIdFk": 0,
            "leadsIdentifier": "Test leads",
            "salesRegion": "Test sales",
            "egApproval": "string",
            "smsId": "string",
            "dateComSmsId": "2017-01-12",
            "egRemarks": "string",
            "dateComGbuTag": "2017-01-12",
            "sgRemarks": "string",
            "taggingDetailsIdFk": 0,
            "profiling": "string",
            "dateCompletedGbuTag": "2017-01-12",
            "gbuTagidFk": 0,
            "longitude": 0,
            "latitude": 0,
            "numberOfEmployees": "string",
            "tier": "string",
            "industryTypeIdFk": 0,
            "gbuMigration": "string",
            "finalReco": "string",
            "motherAccountId": 0,
            "remarksFindings": "string",
            "finalCompanyName": "string",
            "accountCategoryIdFk": 0,
            "sourceLeadIdFk": 0,
            "baluarte": false,
            "vertical": false,
            "affiliate": false,
            "branch": false,
            "profiled": false,
        };
    };
    console.log(lmsleadData);
});
Leakim
  • 626
  • 1
  • 10
  • 19
clestcruz
  • 1,081
  • 3
  • 31
  • 75

2 Answers2

0

Remove var from the variable in the setvalueData function as it is creating a new scope variable, where you want to update the existing variable:

function setvalueData(leadData, data) {
    lmsleadData     = {
        "isProfiled": false,
        "isBaluarte": false,
        "isVertical": false,
        "isAffiliate": false,
        "isBranch": false,
        "id": 0,
        "dateRequested": "2017-01-12",
        "accountIdFk": 0,
        "accountLeadId": 0,
        "accountName": leadData.accountName,
        "assignedEmployeeIdFk": 0,
        "unitNumber": "34",
        "floorNumber": "30",
        "buildingName": "Test bldg name 34",
        "streetNumber": "123",
        "streetName": "Test street name",
        "barangayIdFk": 0,
        "cityTownIdFk": 0,
        "provinceIdFk": 0,
        "regionIdFk": 0,
        "leadsIdentifier": "Test leads",
        "salesRegion": "Test sales",
        "egApproval": "string",
        "smsId": "string",
        "dateComSmsId": "2017-01-12",
        "egRemarks": "string",
        "dateComGbuTag": "2017-01-12",
        "sgRemarks": "string",
        "taggingDetailsIdFk": 0,
        "profiling": "string",
        "dateCompletedGbuTag": "2017-01-12",
        "gbuTagidFk": 0,
        "longitude": 0,
        "latitude": 0,
        "numberOfEmployees": "string",
        "tier": "string",
        "industryTypeIdFk": 0,
        "gbuMigration": "string",
        "finalReco": "string",
        "motherAccountId": 0,
        "remarksFindings": "string",
        "finalCompanyName": "string",
        "accountCategoryIdFk": 0,
        "sourceLeadIdFk": 0,
        "baluarte": false,
        "vertical": false,
        "affiliate": false,
        "branch": false,
        "profiled": false,
    };
};
Kees van Lierop
  • 973
  • 6
  • 20
0

The variable is out of scope of the console.log(). Move the console.log() into the function

function setvalueData(...) {
  var lmsleadData     = {
  // ...
  console.log(lmsleadData);
}

Strictly speaking its also possible to make lmsleadData globally visible by omitting the var in front of the declaration. But global variables should be avoided whenever possible.

// ...
lmsleadData     = {
// ...

Also note that you never call setvalueData()

Björn
  • 471
  • 10
  • 15