Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/Functions/Common/GetList/GetList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ import AbstractFunction from "../../AbstractFunction";

export default class GetList extends AbstractFunction {
public object: string;
/** Maximum number of items to return. */
public maxitems?: number;
/** List of fields to return in the response. */
public fields?: string[];
/** First item from total result set to include in response, zero-based integer. */
public start?: number;
/** Show entity private records if running this at top level. */
public showprivate?: boolean;
// TODO: write filter property on GetList
/** Limits the objects to return based on their field values. */
// public filter?: unknown;
/** Sorts the objects to return based on their field values. */
public sorts?: Array<Record<string, "asc" | "desc">>;

public writeXml(xml: IaXmlWriter): void {
xml.writeStartElement("function");
Expand All @@ -30,6 +43,45 @@ export default class GetList extends AbstractFunction {
xml.writeStartElement("get_list");
xml.writeAttribute("object", this.object);

if (this.maxitems != null) {
// The API supports a negative maxitem, so no validation performed
xml.writeAttribute("maxitems", this.maxitems);
}

if (this.start != null) {
// The API supports a negative start, so no validation performed
xml.writeAttribute("start", this.start);
}

if (this.showprivate != null) {
xml.writeAttribute("showprivate", this.showprivate);
}

// TODO: filter

if (this.fields != null && this.fields.length > 0) {
xml.writeStartElement("fields");
for (const field of this.fields) {
xml.writeElement("field", field, false);
}
xml.writeEndElement(); // fields
}

if (this.sorts != null && this.sorts.length > 0) {
xml.writeStartElement("sorts");
for (const sort of this.sorts) {
for (const field in sort) {
if (sort.hasOwnProperty(field)) {
xml.writeStartElement("sortfield");
xml.writeAttribute("order", sort[field]);
xml.writeText(field);
xml.writeEndElement(); // sortfield
}
}
}
xml.writeEndElement(); // sorts
}

xml.writeEndElement(); // get_list

xml.writeEndElement(); // function
Expand Down
4 changes: 4 additions & 0 deletions src/Xml/IaXmlWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export default class IaXmlWriter {
}
}

public writeText(value: string): void {
this._writer = this._writer.text(value);
}

public writeCustomFieldsImplicit(customFields: Array<[string, any]>) {
if (customFields != null && customFields.length > 0) {
for (const customFieldId in customFields) {
Expand Down
40 changes: 27 additions & 13 deletions test/Functions/Common/GetList/GetListTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,10 @@
* permissions and limitations under the License.
*/

import * as chai from "chai";
import GetList from "../../../../src/Functions/Common/GetList/GetList";
import XmlObjectTestHelper from "../../../Xml/XmlObjectTestHelper";

describe("GetList", () => {
before((done) => {
return done();
});
beforeEach((done) => {
return done();
});
afterEach((done) => {
return done();
});
after((done) => {
return done();
});
it("should get company info", () => {
const expected = `<?xml version="1.0" encoding="utf-8" ?>
<test>
Expand All @@ -41,6 +28,33 @@ describe("GetList", () => {
const record = new GetList("unittest");
record.object = "company_info";

XmlObjectTestHelper.CompareXml(expected, record);
});
it("should get attachment with all attributes", () => {
const expected = `<?xml version="1.0" encoding="utf-8" ?>
<test>
<function controlid="unittest">
<get_list object="supdoc" maxitems="1" start="10" showprivate="true">
<fields>
<field>recordno</field>
<field>supdocid</field>
</fields>
<sorts>
<sortfield order="asc">recordno</sortfield>
<sortfield order="desc">supdocid</sortfield>
</sorts>
</get_list>
</function>
</test>`;

const record = new GetList("unittest");
record.object = "supdoc";
record.maxitems = 1;
record.start = 10;
record.showprivate = true;
record.fields = ["recordno", "supdocid"];
record.sorts = [{ recordno: "asc" }, { supdocid: "desc" }];

XmlObjectTestHelper.CompareXml(expected, record);
});
});