XERO JINT: Difference between revisions
WikiSysopdi (talk | contribs) No edit summary |
WikiSysopdi (talk | contribs) No edit summary |
||
| (14 intermediate revisions by the same user not shown) | |||
| Line 7: | Line 7: | ||
You can update XERO now from javascript code using the JINT functionality | You can update XERO now from javascript code using the JINT functionality | ||
//Insert a Xero contact record | |||
var xeroRecord = XeroRecord('contacts'); | |||
xeroRecord.Set("Name", "John Doe"); | |||
var id = xeroRecord.Insert(); | |||
di.display(id); | |||
//Insert a Xero quote record | |||
var xeroRecord = XeroRecord('quotes'); | |||
xeroRecord.Set("QuoteNumber", "QT-8888"); | |||
var xeroContact = XeroRecord('contacts'); | |||
xeroContact.Set("ContactID", "ab215683-f30f-49f1-afa2-54d9fa90217e"); | |||
xeroContact.Set("Name", "John Doe"); | |||
xeroRecord.setContact(xeroContact); | |||
xeroRecord.Set("Date", new Date()); | |||
var xeroLineItems = XeroRecord('lineitems'); | |||
xeroLineItems.Set("Description", "test-description"); | |||
xeroRecord.setLineItem(xeroLineItems); | |||
var id = xeroRecord.Insert(); | |||
di.display(id); | |||
//Insert a Xero invoice record | |||
<nowiki> | |||
var xeroRecord = XeroRecord('invoices'); | |||
xeroRecord.Set("InvoiceNumber", "IN-88888"); | |||
var xeroContact = XeroRecord('contacts'); | |||
xeroContact.Set("ContactID", "54233ac1-92eb-449b-b559-149c2fcb7366"); | |||
xeroContact.Set("Name", "John Doe"); | |||
xeroRecord.setContact(xeroContact); | |||
xeroRecord.Set("Type", "ACCREC"); | |||
var id = xeroRecord.Insert(); | |||
di.display(id); | |||
</nowiki> | |||
//Update a Xero contact record | |||
<nowiki> | |||
var xeroRecord = XeroRecord('contacts'); | |||
xeroRecord.Set("Name", "John Doe"); | |||
xeroRecord.Set("EmailAddress", "john@doej.com"); | |||
var id = '0523f206-2c4e-455d-9f15-006d4e6054b1'; | |||
xeroRecord.Update(id); | |||
//Update a Xero quote record (without lineitem) with using JINT | |||
<nowiki> | |||
var xeroRecord = XeroRecord('quotes'); | |||
xeroRecord.Set("Reference", "QT-88888"); | |||
var xeroContact = XeroRecord('contacts'); | |||
xeroContact.Set("ContactID", "0523f206-2c4e-455d-9f15-006d4e6054b1"); | |||
xeroContact.Set("Name", "John Doe"); | |||
xeroRecord.setContact(xeroContact); | |||
xeroRecord.Set("Date", new Date()); | |||
var id = '05a07235-cf69-452f-bd69-3d037b62acea'; | |||
xeroRecord.Update(id); | |||
</nowiki> | |||
//Update a Xero quote record (with lineitem - single) | |||
<nowiki> | |||
var xeroContact = XeroRecord('contacts'); | |||
xeroContact.Set("ContactID", "0523f206-2c4e-455d-9f15-006d4e6054b1"); | |||
xeroContact.Set("Name", "John Doe"); | |||
var xeroRecord = XeroRecord('quotes'); | |||
xeroRecord.Set("QuoteNumber", "QT-8000"); | |||
xeroRecord.setContact(xeroContact); | |||
var xeroLineItem = XeroRecord('lineitems'); | |||
xeroLineItem.Set("Description", "test-description"); | |||
xeroRecord.setLineItem(xeroLineItem); | |||
xeroRecord.Set("Date", new Date()); | |||
var id = xeroRecord.Insert(); | |||
di.display(id); | |||
</nowiki> | |||
//Update a Xero quote record (with lineitem - multiple) | |||
<nowiki> | |||
var xeroContact = XeroRecord('contacts'); | |||
xeroContact.Set("ContactID", "0523f206-2c4e-455d-9f15-006d4e6054b1"); | |||
xeroContact.Set("Name", "John Doe"); | |||
var xeroRecord = XeroRecord('quotes'); | |||
xeroRecord.Set("QuoteNumber", "QT-7777"); | |||
xeroRecord.setContact(xeroContact); | |||
var xeroLineItem1 = XeroRecord('lineitem'); | |||
xeroLineItem1.Set("Description", "test-description-1-1"); | |||
var xeroLineItem2 = XeroRecord('lineitem'); | |||
xeroLineItem2.Set("Description", "test-description-2-2"); | |||
xeroRecord.LineItems.Add(xeroLineItem1); | |||
xeroRecord.LineItems.Add(xeroLineItem2); | |||
xeroRecord.Set("Date", new Date()); | |||
var id = xeroRecord.Insert(); | |||
di.display(id); | |||
</nowiki> | |||
//Update a Xero invoice record | |||
<nowiki> | |||
var xeroRecord = XeroRecord('invoices'); | |||
xeroRecord.Set("Reference", "IN-5555"); | |||
var id = '5510fd79-206a-4ea1-a2f0-db1180a2c6c0'; | |||
xeroRecord.Update(id); | |||
</nowiki> | |||
//Archive a Xero contact record | |||
<nowiki> | |||
var xeroRecord = XeroRecord('contacts'); | |||
xeroRecord.Set("Name", "John Doe"); | |||
var id = '76912505-520c-4b1d-8739-24a98493508c'; | |||
xeroRecord.Delete(id); | |||
</nowiki> | |||
//Batch job => to update a Xero contact and Xero quote record | |||
<nowiki> | |||
var xeroBatch=XeroBatch(); | |||
var xeroRecord_contact = XeroRecord('contacts'); | |||
xeroRecord_contact.Set("EmailAddress", "js@doej.com"); | |||
xeroRecord_contact.id = '0523f206-2c4e-455d-9f15-006d4e6054b1'; | |||
xeroRecord_contact.mode="Update"; | |||
xeroBatch.add(xeroRecord_contact); | |||
var xeroRecord_quote = XeroRecord('quotes'); | |||
xeroRecord_quote.Set("Reference", "QT-77773"); | |||
var xeroContact = XeroRecord('contacts'); | |||
xeroContact.Set("ContactID", "0523f206-2c4e-455d-9f15-006d4e6054b1"); | |||
xeroContact.Set("Name", "John Doe"); | |||
xeroRecord_quote.setContact(xeroContact); | |||
xeroRecord_quote.Set("Date", new Date()); | |||
xeroRecord_quote.id = '05a07235-cf69-452f-bd69-3d037b62acea'; | |||
xeroRecord_quote.mode="Update"; | |||
xeroBatch.add(xeroRecord_quote); | |||
xeroBatch.process(); | |||
</nowiki> | |||
"Mode" can be "Insert" or "Update" | |||
--- | |||
Sample querying the Northwind database and populating XERO | |||
<nowiki> | |||
di.clear(); | |||
di.addserver(4); //sql northwind server | |||
var customers = di.querydb("select * from customers where ContactName like '%Maria%'"); | |||
di.addserver(6); //xero server | |||
for(var x=0;x<customers.Rows.Count;x++) | |||
{ | |||
var nameValue = customers.Rows[x]['ContactName']; | |||
di.display('ContactName: ' + nameValue); | |||
var record = di.querydb("contacts","Name='"+nameValue+"'"); | |||
di.display("record record count: " + record.Rows.Count); | |||
if(record == null || record.Rows.Count <= 0) | |||
{ | |||
di.display("Record not exist, so creating..."); | |||
var xeroRecord = XeroRecord('contacts'); | |||
xeroRecord.Set("Name",nameValue); | |||
var id = xeroRecord.Insert(); | |||
di.display("New Xero Record: "+id); | |||
} | |||
else | |||
{ | |||
di.display("Record already exist"); | |||
} | |||
} | |||
</nowiki> | |||
--- | |||
getGUID - This is used where you have a given key value and need the Guid ID. Only one result is returned so this depends on the named key value being unique. Otherwise use querydb. | |||
- Parameters (a) ENTITY(b) FILTER | - Parameters (a) ENTITY(b) FILTER | ||
Latest revision as of 10:07, 10 September 2025
There are specific commands in the Javascript Engine (JINT) relating to XERO Only.
XeroRecord
You can update XERO now from javascript code using the JINT functionality
//Insert a Xero contact record
var xeroRecord = XeroRecord('contacts');
xeroRecord.Set("Name", "John Doe");
var id = xeroRecord.Insert();
di.display(id);
//Insert a Xero quote record
var xeroRecord = XeroRecord('quotes');
xeroRecord.Set("QuoteNumber", "QT-8888");
var xeroContact = XeroRecord('contacts');
xeroContact.Set("ContactID", "ab215683-f30f-49f1-afa2-54d9fa90217e");
xeroContact.Set("Name", "John Doe");
xeroRecord.setContact(xeroContact);
xeroRecord.Set("Date", new Date());
var xeroLineItems = XeroRecord('lineitems');
xeroLineItems.Set("Description", "test-description");
xeroRecord.setLineItem(xeroLineItems);
var id = xeroRecord.Insert();
di.display(id);
//Insert a Xero invoice record
var xeroRecord = XeroRecord('invoices');
xeroRecord.Set("InvoiceNumber", "IN-88888");
var xeroContact = XeroRecord('contacts');
xeroContact.Set("ContactID", "54233ac1-92eb-449b-b559-149c2fcb7366");
xeroContact.Set("Name", "John Doe");
xeroRecord.setContact(xeroContact);
xeroRecord.Set("Type", "ACCREC");
var id = xeroRecord.Insert();
di.display(id);
//Update a Xero contact record
var xeroRecord = XeroRecord('contacts');
xeroRecord.Set("Name", "John Doe");
xeroRecord.Set("EmailAddress", "john@doej.com");
var id = '0523f206-2c4e-455d-9f15-006d4e6054b1';
xeroRecord.Update(id);
//Update a Xero quote record (without lineitem) with using JINT
<nowiki>
var xeroRecord = XeroRecord('quotes');
xeroRecord.Set("Reference", "QT-88888");
var xeroContact = XeroRecord('contacts');
xeroContact.Set("ContactID", "0523f206-2c4e-455d-9f15-006d4e6054b1");
xeroContact.Set("Name", "John Doe");
xeroRecord.setContact(xeroContact);
xeroRecord.Set("Date", new Date());
var id = '05a07235-cf69-452f-bd69-3d037b62acea';
xeroRecord.Update(id);
//Update a Xero quote record (with lineitem - single)
var xeroContact = XeroRecord('contacts');
xeroContact.Set("ContactID", "0523f206-2c4e-455d-9f15-006d4e6054b1");
xeroContact.Set("Name", "John Doe");
var xeroRecord = XeroRecord('quotes');
xeroRecord.Set("QuoteNumber", "QT-8000");
xeroRecord.setContact(xeroContact);
var xeroLineItem = XeroRecord('lineitems');
xeroLineItem.Set("Description", "test-description");
xeroRecord.setLineItem(xeroLineItem);
xeroRecord.Set("Date", new Date());
var id = xeroRecord.Insert();
di.display(id);
//Update a Xero quote record (with lineitem - multiple)
var xeroContact = XeroRecord('contacts');
xeroContact.Set("ContactID", "0523f206-2c4e-455d-9f15-006d4e6054b1");
xeroContact.Set("Name", "John Doe");
var xeroRecord = XeroRecord('quotes');
xeroRecord.Set("QuoteNumber", "QT-7777");
xeroRecord.setContact(xeroContact);
var xeroLineItem1 = XeroRecord('lineitem');
xeroLineItem1.Set("Description", "test-description-1-1");
var xeroLineItem2 = XeroRecord('lineitem');
xeroLineItem2.Set("Description", "test-description-2-2");
xeroRecord.LineItems.Add(xeroLineItem1);
xeroRecord.LineItems.Add(xeroLineItem2);
xeroRecord.Set("Date", new Date());
var id = xeroRecord.Insert();
di.display(id);
//Update a Xero invoice record
var xeroRecord = XeroRecord('invoices');
xeroRecord.Set("Reference", "IN-5555");
var id = '5510fd79-206a-4ea1-a2f0-db1180a2c6c0';
xeroRecord.Update(id);
//Archive a Xero contact record
var xeroRecord = XeroRecord('contacts');
xeroRecord.Set("Name", "John Doe");
var id = '76912505-520c-4b1d-8739-24a98493508c';
xeroRecord.Delete(id);
//Batch job => to update a Xero contact and Xero quote record
var xeroBatch=XeroBatch();
var xeroRecord_contact = XeroRecord('contacts');
xeroRecord_contact.Set("EmailAddress", "js@doej.com");
xeroRecord_contact.id = '0523f206-2c4e-455d-9f15-006d4e6054b1';
xeroRecord_contact.mode="Update";
xeroBatch.add(xeroRecord_contact);
var xeroRecord_quote = XeroRecord('quotes');
xeroRecord_quote.Set("Reference", "QT-77773");
var xeroContact = XeroRecord('contacts');
xeroContact.Set("ContactID", "0523f206-2c4e-455d-9f15-006d4e6054b1");
xeroContact.Set("Name", "John Doe");
xeroRecord_quote.setContact(xeroContact);
xeroRecord_quote.Set("Date", new Date());
xeroRecord_quote.id = '05a07235-cf69-452f-bd69-3d037b62acea';
xeroRecord_quote.mode="Update";
xeroBatch.add(xeroRecord_quote);
xeroBatch.process();
"Mode" can be "Insert" or "Update" ---
Sample querying the Northwind database and populating XERO
di.clear();
di.addserver(4); //sql northwind server
var customers = di.querydb("select * from customers where ContactName like '%Maria%'");
di.addserver(6); //xero server
for(var x=0;x<customers.Rows.Count;x++)
{
var nameValue = customers.Rows[x]['ContactName'];
di.display('ContactName: ' + nameValue);
var record = di.querydb("contacts","Name='"+nameValue+"'");
di.display("record record count: " + record.Rows.Count);
if(record == null || record.Rows.Count <= 0)
{
di.display("Record not exist, so creating...");
var xeroRecord = XeroRecord('contacts');
xeroRecord.Set("Name",nameValue);
var id = xeroRecord.Insert();
di.display("New Xero Record: "+id);
}
else
{
di.display("Record already exist");
}
}
--- getGUID - This is used where you have a given key value and need the Guid ID. Only one result is returned so this depends on the named key value being unique. Otherwise use querydb.
- Parameters (a) ENTITY(b) FILTER
- returns GUID value
EG
>var quoteid=di.getguid("Quotes", "QT-1234");
- di.getguid("Accounts", "Name_Value") => Will pass "Name" and will get "AccountID"
- di.getguid("BankTransactions", "Reference_Value") => Will pass "Reference" and will get "BankTransactionID"
- di.getguid("BrandingThemes", "Name_Value")=> Will pass "Name" and will get "BrandingThemeID"
- di.getguid("ContactGroups", "Name_Value")=> Will pass "Name" and will get "ContactGroupID"
- di.getguid("Contacts", "Name_Value")=> Will pass "Name" and will get "ContactID"
- di.getguid("CreditNotes", "CreditNoteNumber_Value")=> Will pass "CreditNoteNumber" and will get "CreditNoteID"
- di.getguid("Employees", "FirstName_Value")=> Will pass "FirstName" and will get "EmployeeID"
- di.getguid("ExpenseClaims", "Status_Value")=> Will pass "Status" and will get "ExpenseClaimID"
- di.getguid("Invoices", "InvoiceNumber_Value")=> Will pass "InvoiceNumber" and will get "InvoiceID"
- di.getguid("Items", "Name_Value")=> Will pass "Name" and will get "ItemID"
- di.getguid("ManualJournals", "Narration_Value")=> Will pass "Narration" and will get "ManualJournalID"
- di.getguid("Organisations", "Name_Value")=> Will pass "Name" and will get "OrganisationID"
- di.getguid("Payments", "Reference_Value")=> Will pass "Reference" and will get "PaymentID"
- di.getguid("PurchaseOrders", "PurchaseOrderNumber_Value")=> Will pass "PurchaseOrderNumber" and will get "PurchaseOrderID"
- di.getguid("Quotes", "QuoteNumber_Value")=> Will pass "QuoteNumber" and will get "QuoteID"
- di.getguid("Receipts", "ReceiptNumber_Value")=> Will pass "ReceiptNumber" and will get "ReceiptID"
- di.getguid("RepeatingInvoices", "Reference_Value")=> Will pass "Reference" and will get "RepeatingInvoiceID"