1

I keep getting this Uncaught ReferenceError: createLineItem is not defined for this line of code. It comes up in the console whenever I click on the "Create Line Item" button. I'm super uneducated with coding (slowly trying to learn) and I can't seem to figure out what the issue is.

Here is the code:

<apex:remoteObjects >
    <apex:remoteObjectModel name="Line_Items__c" fields="Id,Amount__c,Date_of_Transaction__c,Description__c,Individual_Account__c,P_Card_Expense__c,Stage__c,RecordTypeId"/>
</apex:remoteObjects>

<div class="mypage">
Amount:
<input type="text" id="amount"/>
Date of Transaction:
<input type="date" id="date"/>
P-Card Expense?:
<input type="checkbox" id="pcard"/>
Description:
<input type="text" id="description"/>
<button onclick="createLineItem()">Create Line Item</button>
</div>

<script>
function createLineItem(){
    var LineItemAmount = document.getElementById("amount").value;
    var LineItemDate = document.getElementById("date").value;
    var LineItemPCard = document.getElementById("pcard").value;
    var LineItemDescription = document.getElementById("description").value;
    var LineItemRecordType = "012o0000000pnHd";
    var LineItemAccount = {!Individual_Account__c.Id};
    var LineItemStage = "Pending Hard Copy";
    var LineItem = new SObjectModel.LineItem();
LineItem.create({Amount__c: LineItemAmount}, function(error, records) {
    if (error) {
        alert(error.message);
    } else {
        sforce.one.navigateToSObject(records[0]);
    }
});
};
</script>

Any help is appreciated!

  • Can you just remove <button onclick="createLineItem()">Create Line Item</button> and instead <input type="button" onclick="createLineItem()" value="Create Line Item"/> try once ? – Ratan Paul Mar 31 '16 at 15:28
2

One reason the function definition is not completing (and so the function is not available when the click happens) is because of missing quotes - add them here:

var LineItemAccount = "{!Individual_Account__c.Id}";

This:

var LineItemAccount = a085000000JJwBOAA1;

is not valid JavaScript but this (with quotes added) is valid:

var LineItemAccount = "a085000000JJwBOAA1";

Use your browser's "View Source" to see what is output by the Visualforce and check that it looks right. Also look in your browser's console for JavaScript errors. See e.g. How do I start to debug my own Visualforce/JavaScript?

1

Try removing the ; after the closing of the function createLineItem()

};(this one)

</script>

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.