AJAX SDK for JavaScript
- Overview
- API_Session
- ip_create
- ip_createXML
- ip_delete
- ip_inspect
- ip_getLastRequest
- ip_read
- ip_readByName
- ip_readByQuery
- ip_readMore
- ip_readRelated
- ip_readView
- ip_update
- ip_updateXML
Overview
Sage Intacct provides an SDK for AJAX via a single JavaScript class in a single file.
This file is included in Platform Services pages to facilitate calling functions. Simply call the API_Session
constructor to instantiate the class, then call functions in an on-page script (via Edit this page in the Sage Intacct UI). The SDK provides wrappers for the generic functions (3.0 versions).
API_Session
You must initiate an AJAX call with this constructor, which establishes an API session using the credentials of the current user.
var s = new API_Session();
Parameters
Name | Required | Type | Description |
---|---|---|---|
controlid | Optional | string | Control ID (Default: "foobar" ). |
uniqueid | Optional | boolean | Enforces uniqueness on controlid (Default:"false" ). |
ip_create
Generates a create
call. This function has no return value, but the provided example shows how to use a callback to print the response for console logging.
Creates a new item. Only the required fields are included in the array, but you can add more fields as needed.
<script>
function createBeforeSubmit(){
console.log("In createBeforeSubmit function");
var fieldsArray = {
'ITEMID': jq('#MY_ITEMID').val(),
'STATUS': 'active',
'NAME': jq('#MY_NAME').val(),
'ITEMTYPE': 'Non-Inventory'
};
var api = new API_Session();
var callback = function(responseText){
console.log(responseText)
}
api.ip_create('ITEM', fieldsArray, callback);
}
</script>
<style>
#myNewItem{
width:75%;
padding:20px;
margin:20px;
background: #CCCCCC;
}
</style>
<div id="myNewItem">
<p><label for="MY_ITEMID">Item ID<label> <input type="text" name="MY_ITEMID" id="MY_ITEMID" value="" size="15"/></p>
<p><label for="MY_NAME">Item Name<label> <input type="text" name="MY_NAME" id="MY_NAME" value="" size="30"/></p>
<p><button type="button" onclick="createBeforeSubmit()">Create Item</button></p>
</div>
Parameters
Name | Required | Type | Description |
---|---|---|---|
object | Required | string | Object name of the object to create. |
fieldsArray | Required | array | JSON array of field name/value pairs. |
callback | Optional | string | JavaScript callback function that receives the XML response returned by the server as parameter. |
ip_createXML
Generates a create
API call using XML content that you provide.
Parameters
Name | Required | Type | Description |
---|---|---|---|
xmlPayload | Required | string | XML text, which may include multiple objects to create. Provide the XML elements that go between <create></create> in the XML API create function as the payload. |
callback | Optional | string | JavaScript callback function that receives the XML response returned by the server as parameter. |
ip_delete
Generates a delete
API call.
Parameters
Name | Required | Type | Description |
---|---|---|---|
object | Required | string | Object name of the object(s) to delete. |
keys | Required | string | Comma-separated list of keys (typically RECORDNO ’s to delete). |
callback | Optional | string | JavaScript callback function that receives the XML response returned by the server as parameter. |
ip_inspect
Generates an inspect
API on the named object.
Parameters
Name | Required | Type | Description |
---|---|---|---|
object | Required | string | Object name of the object to inspect. |
detail | Optional | string | 1 provides detailed inspection output (Default: 0). |
callback | Optional | string | JavaScript callback function that receives the XML response returned by the server as parameter. |
ip_getLastRequest
Returns the last XML request sent to the server. This function can be used for debugging.
ip_read
Generates a read
API call.
Parameters
Name | Required | Type | Description |
---|---|---|---|
object | Required | string | Object name of the object(s) to get. |
fields | Required | string | Comma-separated list of fields or * for all. |
keys | Required | string | Comma-separated list of keys. |
returnFormat | Optional | string | xml , csv , or json (Default: xml). |
docparid | Optional | string | Used for SODOCUMENT and PODOCUMENT records to indicate the document type. Required for custom fields. |
callback | Optional | string | JavaScript callback function that receives the XML response returned by the server as parameter. |
ip_readByName
Generates a readByName
API call.
Parameters
Name | Required | Type | Description |
---|---|---|---|
object | Required | string | Object name of the object(s) to get. |
fields | Required | string | Comma-separated list of fields or * for all. |
keys | Required | string | Comma-separated list of keys. |
returnFormat | Optional | string | xml , csv , or json (Default: xml). |
callback | Optional | string | JavaScript callback function that receives the XML response returned by the server as parameter. |
ip_readByQuery
Generates a readByQuery
API call using XML content that you provide.
Parameters
Name | Required | Type | Description |
---|---|---|---|
object | Required | string | Object name of the object(s) to get. |
fields | Required | string | Comma-separated list of fields or * for all. |
query | Required | string | SQL-like query based on fields on the object. The following operators are supported: < , > , >= , <= , = , like , not like , in , not in , IS NOT NULL , IS NULL , AND , OR . Illegal XML characters must be properly encoded, and single quotes must be escaped with backslashes ('Jane\'s Deli' ). Joins are not supported. |
pagesize | optional | integer | Custom page size between 1 and 1000 items (Default: 100). |
returnFormat | Optional | string | xml , csv , or json (Default: xml). |
callback | Optional | string | JavaScript callback function that receives the XML response returned by the server as parameter. |
ip_readMore
Generates a readMore
API call.
Parameters
Name | Required | Type | Description |
---|---|---|---|
object | Required | string | Object name of the object. |
callback | Optional | string | JavaScript callback function that receives the XML response returned by the server as parameter. |
ip_readRelated
Generates a readRelated
API call.
Parameters
Name | Required | Type | Description |
---|---|---|---|
object | Required | string | Object name of the object. |
keys | Required | string | Comma-separated list of keys of the records from which related objects are found. |
relation | Required | string | Name of the relation to follow from the given record(s). |
fields | Required | string | Comma-separated list of fields or * for all. |
returnFormat | Optional | string | xml , csv , or json (Default: xml). |
callback | Optional | string | JavaScript callback function that receives the XML response returned by the server as parameter. |
ip_readView
Generates a readView
API call. This call typically relies on filters set in the view through the Sage Intacct UI, but you can set additional filters to incorporate dynamic information generated by your script.
Uses a filter:
<script>
var api = new API_Session();
var invoiceRecNo = "{!ARINVOICE.RECORDNO#text!}";
var arr = {"filterExpression" : {"field":"RARINVOICE", "operator":'is one of', "value":invoiceRecNo}};
api.ip_readView('collection_activity#147115@10570', arr, 100, 'json', function(data) {
alert(api.ip_getLastRequest());
displaySearchResults(data);
});
</script>
Parameters
Name | Required | Type | Description |
---|---|---|---|
view | Required | string | Expressed as object#viewOriginalID . |
filters | Optional | string | Expressed as {"filterExpression" : {"field":"FIELD_NAME", "operator":"OPERATOR TEXT", "value":"VALUE"}} , max 5 filter conditions . |
pagesize | Optional | integer | Custom page size between 1 and 1000 items (Default: 100). |
returnFormat | Optional | string | xml , csv , or json (Default: xml). |
callback | Optional | string | JavaScript callback function that receives the XML response returned by the server as parameter. |
ip_update
Generates an update
API call.
Shows an update operation:
<script>
var id = '{!object.id!}'; // Id of the current record of the object to update
var fmv = '{!object.test_field!}';
var s = new API_Session();
var arr = {"id":id, "test_field":fmv};
s.ip_update('object', arr);
</script>
Parameters
Name | Required | Type | Description |
---|---|---|---|
object | Required | string | Object name of the object. |
fieldsArray | Required | string | JSON array of fields: "field name":field value . |
callback | Optional | string | JavaScript callback function that receives the XML response returned by the server as parameter. |
ip_updateXML
Generates an update
API call using XML content that you provide.
Parameters
Name | Required | Type | Description |
---|---|---|---|
xmlPayload | Required | string | XML text, which may include multiple objects to create. Provide the XML elements that go between <update></update> in the XML API update function as the payload. |