Pick list

This example lists customers to display on a page in a pick list.

The callback variable is set to the function to be performed on the returned data. The read call on the ‘CUSTOMER’ object requests the ‘NAME’ field in JSON format. Finally, the select field provides a display point in the HTML.

<script>
var callback = function (responseText) {
    // Parse the response into a JavaScript object
    var CUSTOMER = JSON.parse(responseText);

    // Sort the array of results into alphabetical order by NAME
    CUSTOMER.sort((function (index) {
        return function (a, b) {
            return (a[index] === b[index] ? 0 : (a[index] < b[index] ? -1 : 1));
        };
    })('NAME')); // NAME is the sort by field name

    // Options variable to receive pick list values
    var options = '<option>-- Select Customer --</option>';

    // Add an option element for each customer record
    for (var i = 0; i < CUSTOMER.length; i++) {
        options += '<option value="' + CUSTOMER[i].NAME + '">' + CUSTOMER[i].NAME + '</option>';
    }

    // Load options in the 'pick_customer' element
    document.getElementById('pick_customer').innerHTML = options;
};
var s = new API_Session();
s.ip_read("CUSTOMER", "NAME", "", "json", "", callback);
</script>

<select name="select" size="1" id="pick_customer"></select>

GL Balance

This example returns a table for the GL Balance by Location for the account specified in the code. It is assumed there is a current reporting period with naming such as “Month Ended April 2014”.

<style>
    #scriptSection fieldset {
        padding: 30px;
        border: 1px solid #EEEEEE;
    }

    #scriptSection fieldset legend {
        font-weight: bold;
        padding-left: 20px;
        padding-right: 20px;
    }

    #scriptSection fieldset table td, #scriptSection fieldset table th {
        border-left: 1px solid #EEEEEE;
        padding-left: 20px;
        padding-right: 20px;
    }

    #scriptSection fieldset table th {
        border-bottom: 1px solid #EEEEEE;
    }

    #scriptSection fieldset table tr:hover td {
        background-color: #fEf98D;
    }
</style>
<div id="scriptSection">
<fieldset>
    <legend>Current Petty Cash Balance</legend>
    <div id="arGLBalanceHolder">
        <table>
            <thead>
            <tr>
                <td>Loading ...</td>
            </tr>
            </thead>
        </table>
    </div>
</fieldset>

<script>
jq(document).ready(function () {

    // Fetch and display the GL account balance
    var monthNames = ["January", "February", "March", "April", "May", "June",
        "July", "August", "September", "October", "November", "December"];
    var d = new Date();
    var month = monthNames[d.getMonth()];
    var year = d.getFullYear();
    var reportingPeriod = 'Month Ended ' + month + ' ' + year;
    var account = 1010;
    var api = new API_Session();

    var callback = function (data) {
        var holder = jq('div#arGLBalanceHolder');
        data = JSON.parse(data);
        if (data.length == 0) {
            holder.html('No data');
            return;
        }
        var tableContent = '<thead><tr><th>Account</th><th>Location</th><th>Amount</th></tr></thead><tbody>';
        for (var r = 0; r < data.length; r++) {
            tableContent += '<tr>';
            tableContent += '<td>' + data[r].ACCOUNTNO + '--' + data[r].ACCOUNTTITLE + '</td>';
            tableContent += '<td>' + data[r].LOCATIONID + '</td>';
            tableContent += '<td>' + Number(data[r].ENDBAL).toFixed(2) + '</td>';
            tableContent += '</tr>';
        }
        tableContent += '</tbody>';
        holder.html('<table>' + tableContent + '</table></br><p>(For ' + reportingPeriod + ')</p>');
    };

    api.ip_readByQuery(
        'glaccountbalance',
        'ACCOUNTNO,ACCOUNTTITLE,ENDBAL,LOCATIONID',
        "period = '" + reportingPeriod + "' AND accountno = '" + account + "'",
        10,
        'json',
        callback
    );
});
</script>
</div>

Pick List of Purchasing Transaction Types

<script>
var callback = function (responseText) {
    var xml = responseText,
        xmlDoc = jq.parseXML(xml),
        $xml = jq(xmlDoc);
    var select = jq('#pick_potransaction');

    $xml.find("type[typename='PODOCUMENT']").each(function () {
        var value = jq(this).text();
        if (value !== 'Purchasing Document') {
            select.append("<option value='" + value + "'>" + value + "</option>");
        }
    });

};
var s = new API_Session();
s.ip_inspect("*", "1", callback); // Returned as XML not JSON
</script>

<select name="select" size="1" id="pick_potransaction"></select>

Provide feedback