Sample Scripts

Sample Scripts

The following sample scripts demonstrate different scenarios and editor features.
Click
Edit
on the top menu bar in the
Use template
section to use additional sample scripts. Each template has comments that describe the general purpose and blocks of code.
/** * Read all codes using ManyCode, order them alphabetically, separate with a comma and output over TCP. * Ensure that the Barcode Tool is in the first position in this job—otherwise, the code might return errors and not work. * Please do not remove 'export' keyword or this comment. * onResults function triggers on the results of each job run. * For more detailed information please refer to the documentation. * @param {IMainArguments} input_result - object with results of the job. * @returns {IMainResult} - object defining outputs per interface. */ export function onResults(input_result) { if (input_result.tool_results[0].decodes.length === 0) { // do not process when there are no decodes return {}; } const orderedDecodes = input_result.tool_results[0].decodes .map(decode => decode.value) // map array of decodes to array of decoded values .sort() // sort alphabetically .join(','); // join elements of array with a comma to a single string return { tcp_ip: orderedDecodes // output through tcp }; } /** * Capture barcodes with Manycode and compare 2 strings. If they're the same output the value, otherwise output "FAIL" through TCP and HID. * Please do not remove 'export' keyword or this comment. * onResults function triggers on the results of each job run. * For more detailed information please refer to the documentation. * @param {IMainArguments} input_result - object with results of the job.* @returns {IMainResult} - object defining outputs per interface. */ export function onResults(input_result) { // return fail because there are no decodes to compare if (input_result.tool_results[0].decodes.length < 2) { return { job_success: false, }; } // at this point we are certain that there are at least 2 decodes here due to the check above // assign first and second decode value to variables for readability const firstDecode = input_result.tool_results[0].decodes[0].value; const secondDecode = input_result.tool_results[0].decodes[1].value; // compare decodes and return the decode value through TCP and HID if they are equal // set job_success to true, because the job did get 2 reads and did run correctly if (firstDecode === secondDecode) { return { tcp_ip: firstDecode, hid: firstDecode, job_success: true, }; } // return "FAIL" because the first and second decode differ and job_success because the job did get 2 reads and did run correctly, // even though the decodes did not match return { tcp_ip: "FAIL", hid: "FAIL", job_success: true, // job success is true even though the decodes do not match - the job did run }; }