Printing an Invoice
The following example, written in node.js, shows how to print a Sales Invoice.
const priority = require("priority-web-sdk")
console.log('Start running');
async function webSDK() {
// the config object should be adapted to your Priority environment
let config = {
url: "https://xxxx/xxxx/",
tabulaini: "tabxxx.ini",
language: 3,
profile: { company: "xxxxx" },
appname: "demo",
username: "xxxx",
password: "xxxx",
devicename: ""
};
const sdkMessage = (serverMessage) => {
console.log("This is an SDK message");
console.info(serverMessage);
};
try {
await priority.login(config);
console.log("Your are in!! Enjoy!");
// WWWSHOWAIV is for printing Sales Invoices. Other types of invoices
// use other printout programs.
let procedure = await priority.procStart("WWWSHOWAIV", "P", null);
procedure = await procedure.proc.inputOptions(1 , 1);
// Provide your own invoice number for testing puproses.
// The value of field 2 (Sort) must match the language you are working in
var data = {EditFields: [
{field: 1, op: 0, value: 'IN244B000001'},
{field: 2, op: 0, value: 'By Invoice/Memo Number'}
]};
procedure = await procedure.proc.inputFields(1 , data);
procedure = await procedure.proc.clientContinue();
procedure = await procedure.proc.continueProc();
console.log(procedure.Urls[0].url);
// logs out url of new rew report on the server
// Use it to grab the printout
await procedure.proc.cancel()
} catch (reason) {
sdkMessage(reason)
}
}
webSDK();
Sending a Digitally Signed Invoice
Very similar to the previous example, this time we send the Sales Invoice as an e-document to the customer.
const priority = require("priority-web-sdk")
console.log('Start running');
async function webSDK() {
let config = {
url: "https://xxxx/xxxx/",
tabulaini: "tabxxx.ini",
language: 3,
profile: { company: "xxxxx" },
appname: "demo",
username: "xxxx",
password: "xxxx",
devicename: ""
};
const sdkMessage = (serverMessage) => {
console.log("This is an SDK message");
console.info(serverMessage);
};
try {
await priority.login(config);
console.log("Your are in!! Enjoy!");
let procedure = await priority.procStart("WWWSHOWAIV", "P", null);
procedure = await procedure.proc.inputOptions(1 , 1);
var data = {EditFields: [
{field: 1, op: 0, value: 'IN244000013'},
{field: 2, op: 0, value: 'By Invoice/Memo Number'}
]};
procedure = await procedure.proc.inputFields(1 , data);
procedure = await procedure.proc.clientContinue();
procedure = await procedure.proc.documentOptions(1, -4, {pdf: 1, word: 0, mode: 'automail'});
procedure = await procedure.proc.continueProc();
console.log(procedure.Urls[0].url);
// logs out url of new rew report on the server
await procedure.proc.cancel()
} catch (reason) {
sdkMessage(reason)
}
}
webSDK();
Downloading a Digitally-Signed Invoice from Attachments
Digitally-signed invoices are automatically attached to the attachments of the relevant invoice record.
In this example we first send the e-document (duplicating the previous example), then access the attachments subform to download it in base64 format.
const priority = require("priority-web-sdk")
console.log('Start running');
async function webSDK() {
let config = {
url: "https://xxxx/xxxx/",
tabulaini: "tabxxx.ini",
language: 3,
profile: { company: "xxxxx" },
appname: "demo",
username: "xxxx",
password: "xxxx",
devicename: ""
};
const sdkMessage = (serverMessage) => {
console.log("This is an SDK message");
console.info(serverMessage);
};
try {
await priority.login(config);
console.log("Your are in!! Enjoy!");
let procedure = await priority.procStart("WWWSHOWAIV", "P", null);
procedure = await procedure.proc.inputOptions(1 , 1);
var data = {EditFields: [
{field: 1, op: 0, value: 'IN244000015'},
{field: 2, op: 0, value: 'By Invoice/Memo Number'}
]};
procedure = await procedure.proc.inputFields(1 , data);
procedure = await procedure.proc.clientContinue();
procedure = await procedure.proc.documentOptions(1, -4, {pdf: 1, word: 0, mode: 'automail'});
procedure = await procedure.proc.continueProc();
await procedure.proc.cancel()
// Accessing attachments starts here
console.log("Form start");
let mainFormHandler = await priority.formStart("AINVOICES", this.onError, this.onSuccess, '', 1);
let filter = {
or: 0,
ignorecase:1,
QueryValues: [{
field : "IVNUM",
fromval : "IN244000015",
op : "=",
sort : 0,
isdesc : 0
}]
};
await mainFormHandler.setSearchFilter(filter);
await mainFormHandler.getRows(1);
let subform = await mainFormHandler.startSubForm('EXTFILES', this.onError,null);
let filter_subform = {
or: 0,
ignorecase:1,
QueryValues: [{
field : "EXTFILENUM",
fromval : "1",
op : "=",
sort : 0,
isdesc : 0
}]
};
await subform.setSearchFilter(filter_subform);
let extfiles = await subform.getRows(1);
let filename = extfiles.EXTFILES[1].EXTFILENAME;
console.log("Filename:", filename);
const filedata = await subform.getFileDataUri(filename);
console.log("BASE64:", filedata);
} catch (reason) {
sdkMessage(reason)
}
}
webSDK();
Printing a Price Quotation
In this example, we print out a price quotation.
//Document example
const priority = require("priority-web-sdk")
console.log('Start running');
async function webSDK() {
// the config object should be adapted to your Priority environment
let config = {
url: "https://xxxx/xxxx/",
tabulaini: "tabxxx.ini",
language: 3,
profile: { company: "xxxxx" },
appname: "demo",
username: "xxxx",
password: "xxxx",
devicename: ""
};
const sdkMessage = (serverMessage) => {
console.log("This is an SDK message");
console.info(serverMessage);
};
try {
await priority.login(config);
console.log("Your are in!! Enjoy!");
let procedure = await priority.procStart("WWWSHOWCPROF", "P", null);
console.log(procedure)
procedure = await procedure.proc.inputOptions(1 , 1);
// Provide your own quotation number for testing puproses.
// The value of field 2 (Sort) must match the language you are working in
var data = {EditFields: [
{field: 1, op: 0, value: 'PQ24000089'},
{field: 2, op: 0, value: 'By Quote Number'}
]};
procedure = await procedure.proc.inputFields(1 , data);
procedure = await procedure.proc.continueProc();
console.log(procedure.Urls[0].url);
// logs out url of new rew report on the server
await procedure.proc.cancel()
} catch (reason) {
sdkMessage(reason)
}
}
webSDK();
Print a Sales Order Confirmation
In this example, we print out a confirmation for a sales order.
//Document example
const priority = require("priority-web-sdk")
console.log('Start running');
async function webSDK() {
// the config object should be adapted to your Priority environment
let config = {
url: "https://xxxx/xxxx/",
tabulaini: "tabxxx.ini",
language: 3,
profile: { company: "xxxxx" },
appname: "demo",
username: "xxxx",
password: "xxxx",
devicename: ""
};
const sdkMessage = (serverMessage) => {
console.log("This is an SDK message");
console.info(serverMessage);
};
try {
await priority.login(config);
console.log("Your are in!! Enjoy!");
let procedure = await priority.procStart("WWWSHOWORDER", "P", null);
console.log(procedure)
procedure = await procedure.proc.inputOptions(1 , 1);
// Provide your own quotation number for testing puproses.
// The value of field 2 (Sort) must match the language you are working in
var data = {EditFields: [
{field: 1, op: 0, value: 'SO24000089'},
{field: 2, op: 0, value: 'By Order Number'}
]};
procedure = await procedure.proc.inputFields(1 , data);
procedure = await procedure.proc.continueProc();
console.log(procedure.Urls[0].url);
// logs out url of new rew report on the server
await procedure.proc.cancel()
} catch (reason) {
sdkMessage(reason)
}
}
webSDK();