.model

Model Module is responsible for handling of CRUD operations of documents in the backend.

In addition, it handles the operations associated with documents such as tagging documents & assigning users to documents.

.getDoc() ☆

To get a single document using its type and name (identifier).

Input

GetDocParams

property

type

required

description

doctype

string

yes

The doctype of the document, e.g: 'Renovation Review'

docname

string

yes

The name (identifier) of the document, e.g: 'RE-00001'

forceFetch

boolean

no

Whether to fetch the document from the backend even if it exists in the local cache. Defaults to false

Output

RenovationDocument

The generic document RenovationDocument can be assigned to a custom doctype type, for instance, Renovation Review. This is possible because RenovationDocument contains Indexed Property.

Example

async-await

const documentResponse = await renovationInstance.model.getDoc({
doctype: "User",
docname: "test@abc.com"
});
if (documentResponse.success) {
// If the document was successfully retrieved
console.log("Document", documentResponse.data);
} else {
// If the document was not retrieved
console.log("Error", documentResponse.error);
}

Classic Promise

renovationInstance.model
.getDoc({
doctype: "User",
docname: "test@abc.com"
})
.then(documentResponse => {
if (documentResponse.success) {
// If the document was successfully retrieved
console.log("Document", documentResponse.data);
} else {
// If the document was not retrieved
console.log("Error", documentResponse.error);
}
});

Sample Response

{
"success": true,
"httpCode": 200,
"data": {
"doctype": "User",
"name": "test@abc.com",
"owner": "test@abc.com",
"creation": "2020-02-27 23:22:34.929267",
"modified": "2020-04-11 18:44:31.803200",
"modified_by": "test@abc.com",
"parent": null,
"parentfield": null,
"parenttype": null,
"idx": 616,
"docstatus": 0,
"enabled": 1,
"email": "test@abc.com",
"first_name": "test@abc.com",
"middle_name": "testing_save_doc",
"last_name": null,
"full_name": "test@abc.com",
"send_welcome_email": 1,
"unsubscribed": 0,
"username": "test_abc",
"language": "en",
"time_zone": null,
"override_as_global": 0,
"user_image": null,
"role_profile_name": null,
"gender": null,
"phone": null,
"mobile_no": null,
"birth_date": null,
"location": null,
"banner_image": null,
"interest": null,
"bio": null,
"mute_sounds": 0
//.........
}
};

While the backend supplies common properties across doctypes, the above sample should not be assumed in your implementation

Possible Errors

Non-existing document

HTTP code: 404

type: NotFoundError

cause: Docname does not exist

suggestion: Make sure the queried document name is correct or create the required document

Wrong input

HTTP code: 412

type: DataFormatError

cause: The input arguments are in the wrong type/format

suggestion: Use the correct parameters types/formats referencing the functions signature

.getList() ☆

To get a list of documents using the doctype, and other optional filters.

Input

GetListParams

property

type

required

description

doctype

string

yes

The doctype of the list, e.g: 'User'

fields

string[]

no

The list of docfield names, e.g: ["name", "email", "full_name"]. Use ["*"] if all fields are required

orderBy

string

no

Criteria of ordering ('ASC', 'DESC')

limitPageStart

number

no

Used for pagination. Select which document to start at

limitPageLength

number

no

Used for pagination . Selects the number of results in the response

filters

DBFilter

no

Can use SQL-like querying

parent

string

no

If a child table is to be queried, pass the name of the parent document

tableFields

[x: string] : string[]

no

To get the fields of the child table fields. Can specify the fields like fields

withLinkFields

string[]

no

To get the complete document if a field is of type Link (Another document)

Output

[{ [x: string]: DBBasicValues | [{}] }]

This means the data will include string or number for the fields that are not an object. Also it could contain nested array of objects, for instance, linked documents.

Example

async-await

const listResponse = await renovationInstance.model.getList({
doctype: "User"
});
if (listResponse.success) {
// If the list was successfully retrieved
console.log("Document", listResponse.data);
} else {
// If the list was not retrieved
console.log("Error", listResponse.error);
}

Classic Promise

renovationInstance.model
.getList({
doctype: "User",
fields: ["*"]
})
.then(listResponse => {
if (listResponse.success) {
// If the list was successfully retrieved
console.log("Document", listResponse.data);
} else {
// If the list was not retrieved
console.log("Error", listResponse.error);
}
});

Sample Response

{
"success": true,
"httpCode": 200,
"data": [
{
"doctype": "User",
"name": "test@abc.com",
"owner": "test@abc.com",
"creation": "2020-02-27 23:22:34.929267",
"modified": "2020-04-11 18:44:31.803200",
"modified_by": "test@abc.com",
"parent": null,
"parentfield": null,
"parenttype": null,
"idx": 616,
"docstatus": 0,
"enabled": 1,
"email": "test@abc.com",
"first_name": "test@abc.com",
"middle_name": "testing_save_doc",
"last_name": null,
"full_name": "test@abc.com",
"send_welcome_email": 1,
"unsubscribed": 0,
"username": "test_abc",
"language": "en",
"time_zone": null,
"override_as_global": 0,
"user_image": null,
"role_profile_name": null,
"gender": null,
"phone": null,
"mobile_no": null,
"birth_date": null,
"location": null,
"banner_image": null,
"interest": null,
"bio": null,
"mute_sounds": 0
//.........
},
{.....},
{.....}
]
};

While the backend supplies common properties across doctypes, the above sample should not be assumed in your implementation.

.getValue()

To get a single value from DB.

Input

GetValueParams

property

type

required

description

doctype

string

yes

The doctype of the document, e.g: 'User'

docname

string

yes

The name (identifier) of the document, e.g: 'test@abc.com'

docfield

string

yes

The name of the field to get the value of, e.g: 'email'

Output

{ [x: string]: DBBasicValues }

This is an Indexed Property which can contain only values of type string or number.

Example

async-await

const fieldValue = await renovationInstance.model.getValue({
doctype: "User",
docname: "test@abc.com",
docfield: "email"
});
if (fieldValue.success) {
// User Email: {"email":"test@abc.com"}
console.log("User Email: ", fieldValue.data);
} else {
console.log("Error", fieldValue.error);
}

Classic Promise

renovationInstance.model
.getValue({
doctype: "User",
docname: "test@abc.com",
docfield: "email"
})
.then(fieldValue => {
if (fieldValue.success) {
// User Email: {"email":"test@abc.com"}
console.log("User Email: ", fieldValue.data);
} else {
console.log("Error", fieldValue.error);
}
});

Possible Errors

Non-existing document

HTTP code: 404

type: NotFoundError

cause: Docname does not exist

suggestion: Make sure the queried document name is correct or create the required document

Wrong input

HTTP code: 412

type: DataFormatError

cause: The input arguments are in the wrong type/format

suggestion: Use the correct parameters types/formats referencing the functions signature

.setValue()

To set a single value from DB.

Input

SetValueParams

property

type

required

description

doctype

string

yes

The doctype of the document, e.g: 'User'

docname

string

yes

The name (identifier) of the document, e.g: 'test@abc.com'

docfield

string

yes

The name of the field to set the value of, e.g: 'middle_name'

value

DBBasicValues

yes

The value to set the field with

Output

RenovationDocument

Returns the whole document with the field modified.

Example

async-await

const userDoc = await renovationInstance.model.setValue({
doctype: "User",
docname: "test@abc.com",
docfield: "middle_name",
value: "My Middle Name"
});
if (userDoc.success) {
// User Middle Name: My Middle Name
console.log("User Middle Name: ", userDoc.data.middle_name);
} else {
console.log("Error", userDoc.error);
}

Classic Promise

renovationInstance.model
.setValue({
doctype: "User",
docname: "test@abc.com",
docfield: "middle_name",
value: "My Middle Name"
})
.then(userDoc => {
if (userDoc.success) {
// User Middle Name: My Middle Name
console.log("User Middle Name: ", userDoc.data.middle_name);
} else {
console.log("Error", userDoc.error);
}
});

Possible Errors

Doctype Does Not Exist

HTTP code: 404

type: NotFoundError

cause: DocType does not exist

suggestion: Make sure the queried DocType is input correctly or create the required DocType

Docname Does Not Exist

HTTP code: 404

type: NotFoundError

cause: Docname does not exist

suggestion: Make sure the queried document name is correct or create the required document

.setLocalValue()

Sets local value on a document, triggering events for the operation.

The document must be loaded in the cache, otherwise, an error is thrown when used.

Input

SetLocalValueParams

property

type

required

description

doctype

string

yes

The doctype of the document, e.g: 'Renovation Review'

docname

string

yes

The name (identifier) of the document, e.g: 'RE-00021'

docfield

string

yes

The name of the field to set the value of

value

DBBasicValues

yes

The value to set the field with

Example

renovationInstance.model.setLocalValue({
doctype: "Renovation Review",
docname: "RE-00003",
docfield: "reviewed_by",
value: "test@abc.com"
});
// Reviewed By: test@abc.com
console.log(
"Reviewed By: ",
renovationInstance.model.locals["Renovation Review"]["RE-00003"].reviewed_by
);

.newDoc()

To create a new document with default added properties. Also saves the created document in the local cache.

Default fields:
docstatus: 0
__islocal: 1
__unsaved: 1

Input

NewDocParams

property

type

required

description

doctype

string

yes

The doctype of the document, e.g: 'Renovation Review'

Output

Promise<RenovationDocument>*

Returns the new document including the default values. The object can be cast to a custom DocType interface to add the properties.

Example

async-await

const newDoc = (await renovationInstance.model.newDoc({
doctype: "Renovation Review"
})) as RenovationReview;
if (newDoc.success) {
newDoc.name = "Test Review";
// Review Name: Test Review
console.log("Review Name: ", newDoc.data.name);
} else {
console.log("Error", newDoc.error);
}

Classic Promise

renovationInstance.model
.newDoc({
doctype: "Review"
})
.then(newDoc => {
if (newDoc.success) {
newDoc.name = "Test Review";
// Review Name: Test Review
console.log("Review Name: ", newDoc.data.name);
} else {
console.log("Error", newDoc.error);
}
});

.saveDoc() ☆

To save the document in the backend.

Input

SaveDocParams

property

type

required

description

doc

RenovationDocument

yes

The document to be saved

Output

RenovationDocument

Example

async-await

const savedDoc = await renovationInstance.model.saveDoc({
doc: await renovationInstance.model.newDoc({
doctype: "Renovation Review",
name: "Test Review"
})
});
if (savedDoc.success) {
// Review Name: Test Review
console.log("Review Name: ", savedDoc.data.name);
} else {
console.log("Error", savedDoc.error);
}

Classic Promise

renovationInstance.model
.newDoc({ doctype: "Renovation Review", name: "Test Review" })
.then(newDoc =>
renovationInstance.model
.saveDoc({
doc: newDoc
})
.then(savedDoc => {
if (savedDoc.success) {
// Review Name: Test Review
console.log("Review Name: ", savedDoc.data.name);
} else {
console.log("Error", savedDoc.error);
}
})
);

Possible Errors

Duplicate document found

HTTP code: 409

type: DuplicateEntryError

cause: Duplicate doc found while saving

suggestion: Change the 'name' field or delete the existing document

.submitDoc()

To submit the document in the backend.

Input

SubmitDocParams

property

type

required

description

doc

RenovationDocument

yes

The document to be submitted

Output

RenovationDocument

Example

async-await

const submittedDoc = await renovationInstance.model.submitDoc({
doc: { doctype: "Renovation Review", name: "Test Review" }
});
if (submittedDoc.success) {
// Review Name: Test Review
console.log("Review Name: ", submittedDoc.data.name);
} else {
console.log("Error", submittedDoc.error);
}

Classic Promise

renovationInstance.model
.submitDoc({
doc: { doctype: "Renovation Review", name: "Test Review" }
})
.then(submittedDoc => {
if (submittedDoc.success) {
// Review Name: Test Review
console.log("Review Name: ", submittedDoc.data.name);
} else {
console.log("Error", submittedDoc.error);
}
});

Possible Errors

Doctype Does Not Exist

HTTP code: 404

type: NotFoundError

cause: DocType does not exist

suggestion: Make sure the queried DocType is input correctly or create the required DocType

Non-existing document

HTTP code: 404

type: NotFoundError

cause: Docname does not exist

suggestion: Make sure the queried document name is correct or create the required document

.saveSubmitDoc() ★

To save the document first, then submit, in a single db transaction.

Input

SaveSubmitDocParams

property

type

required

description

doc

RenovationDocument

yes

The document to be saved & submitted

Output

RenovationDocument

Example

async-await

const savedSubmittedDoc = await renovationInstance.model.saveSubmitDoc({
doc: { doctype: "Renovation Review", name: "Test Review" }
});
if (savedSubmittedDoc.success) {
// Review Name: Test Review
console.log("Review Name: ", savedSubmittedDoc.data.name);
} else {
console.log("Error", savedSubmittedDoc.error);
}

Classic Promise

renovationInstance.model
.saveSubmitDoc({
doc: { doctype: "Renovation Review", name: "Test Review" }
})
.then(savedSubmittedDoc => {
if (savedSubmittedDoc.success) {
// Review Name: Test Review
console.log("Review Name: ", savedSubmittedDoc.data.name);
} else {
console.log("Error", savedSubmittedDoc.error);
}
});

Possible Errors

Doctype Does Not Exist

HTTP code: 404

type: NotFoundError

cause: DocType does not exist

suggestion: Make sure the queried DocType is input correctly or create the required DocType

Non-existing document

HTTP code: 404

type: NotFoundError

cause: Docname does not exist

suggestion: Make sure the queried document name is correct or create the required document

.copyDoc()

To create a cloned document, with a new local name.

The cloned document is also added to the local cache.

Input

CopyDocParams

property

type

required

description

doc

RenovationDocument

yes

The document to be cloned

Output

Promise<RenovationDocument>*

Example

async-await

const clonedDoc = await renovationInstance.model.copyDoc({
doc: { doctype: "Renovation Review", name: "Test Review" }
});
if (clonedDoc.success) {
// Review Name: New Renovation Review 1
console.log("Review Name: ", clonedDoc.data.name);
} else {
console.log("Error", clonedDoc.error);
}

Classic Promise

renovationInstance.model
.saveSubmitDoc({
doc: { doctype: "Renovation Review", name: "Test Review" }
})
.then(clonedDoc => {
if (clonedDoc.success) {
// Review Name: New Renovation Review 1
console.log("Review Name: ", clonedDoc.data.name);
} else {
console.log("Error", clonedDoc.error);
}
});

.amendDoc()

To clone a document then set amended_from property to the original doc.

Input

RenovationDocument

property

type

required

description

doc

RenovationDocument

yes

The document to be cloned

Output

Promise<RenovationDocument>*

Example

async-await

const amendedDoc = await renovationInstance.model.amendDoc({
doc: { doctype: "Renovation Review", name: "Test Review" }
});
if (amendedDoc.success) {
// Review Name: New Renovation Review 1
console.log("Review Name: ", amendedDoc.data.amended_from);
} else {
console.log("Error", amendedDoc.error);
}

Classic Promise

renovationInstance.model
.amendDoc({
doc: { doctype: "Renovation Review", name: "Test Review" }
})
.then(amendedDoc => {
if (amendedDoc.success) {
// Review Name: New Renovation Review 1
console.log("Review Name: ", amendedDoc.data.amended_from);
} else {
console.log("Error", amendedDoc.error);
}
});

.addChildDoc()

To add a child document to a parent document. (Table field)

Input

AddChildDocParams

property

type

required

description

doc

RenovationDocument

yes

The document to be cloned

field

string | DocField

yes

The field in the parent doc to add the new child doc.

Output

Promise<RenovationDocument>*

The child document added.

Example

async-await

const childDoc = await renovationInstance.model.addChildDoc({
doc: { doctype: "Renovation Review", name: "Test Review" },
field: "reviews"
});
// Save the child doc or manipulate before saving...

Classic Promise

renovationInstance.model
.addChildDoc({
doc: { doctype: "Renovation Review", name: "Test Review" },
field: "reviews"
})
.then(childDoc => {
// Save the child doc or manipulate before saving...
});

.deleteDoc()

To delete a document from the backend.

Input

DeleteDocParams

property

type

required

description

doctype

string

yes

The doctype of the document

docname

string

yes

The document name to be deleted

Output

RenovationDocument

Example

async-await

const deletedDoc = await renovationInstance.model.deleteDoc({
doctype: "Renovation Review",
docname: "Test Review"
});
if (deletedDoc.success) {
// Review Name: Test Review
console.log("Review Name: ", deletedDoc.data.name);
} else {
console.log("Error", deletedDoc.error);
}

Classic Promise

renovationInstance.model
.deleteDoc({
doctype: "Renovation Review",
docname: "Test Review"
})
.then(deletedDoc => {
if (deletedDoc.success) {
// Review Name: Test Review
console.log("Review Name: ", deletedDoc.data.name);
} else {
console.log("Error", deletedDoc.error);
}
});

Possible Errors

Non-existing document

HTTP code: 404

type: NotFoundError

cause: Docname does not exist

suggestion: Make sure the queried document name is correct or create the required document

.cancelDoc()

To cancel a submitted document in the backend.

Input

CancelDocParams

property

type

required

description

doc

RenovationDocument

yes

The document to be cancelled

Output

RenovationDocument

Example

async-await

const cancelledDoc = await renovationInstance.model.cancelDoc({
doc: {
doctype: "Renovation Review",
docname: "Test Review"
}
});
if (cancelledDoc.success) {
// Review Name: Test Review
console.log("Review Name: ", cancelledDoc.data.name);
} else {
console.log("Error", cancelledDoc.error);
}

Classic Promise

renovationInstance.model
.cancelDoc({
doc: {
doctype: "Renovation Review",
docname: "Test Review"
}
})
.then(cancelledDoc => {
if (cancelledDoc.success) {
// Review Name: Test Review
console.log("Review Name: ", cancelledDoc.data.name);
} else {
console.log("Error", cancelledDoc.error);
}
});

Possible Errors

Doctype Does Not Exist

HTTP code: 404

type: NotFoundError

cause: DocType does not exist

suggestion: Make sure the queried DocType is input correctly or create the required DocType

Non-existing document

HTTP code: 404

type: NotFoundError

cause: Docname does not exist

suggestion: Make sure the queried document name is correct or create the required document

.assignDoc()

To assign a document to a user.

Input

AssignDocParams

property

type

required

description

doctype

string

yes

The doctype to assign to

assignTo

string

yes

The user to be assigned

docname

string

no

The specific document assigned to

docnames

string[]

no

The list of documents to be assigned to

myself

boolean

no

Whether the current logged in user is assigned

description

string

no

Description of the assignment

dueDate

string

no

The due date for the assignment

notify

boolean

no

Whether to notify the user

priority

string

no

The priority to be set for the assignment. Possible values: "Low" | "Medium" | "High"

bulkAssign

boolean

no

Whether to assign in bulk of documents. Use docnames instead while using bulkAssign

Output

any

Example

async-await

const assignResponse = await renovationInstance.model.assignDoc({
assignTo: "abc@test.com",
doctype: "Renovation Review",
docname: "Renovation Review A",
description: "Test Assign",
priority: "High",
dueDate: "2050-12-31"
});
if (assignResponse.success) {
// Owner: abc@test.com
console.log("Owner: ", assignResponse.data.owner);
} else {
console.log("Error", assignResponse.error);
}

Classic Promise

renovationInstance.model
.assignDoc({
assignTo: "abc@test.com",
doctype: "Renovation Review",
docname: "Renovation Review A",
description: "Test Assign",
priority: "High",
dueDate: "2050-12-31"
})
.then(assignResponse => {
if (assignResponse.success) {
// Owner: abc@test.com
console.log("Owner: ", assignResponse.data.owner);
// Description: abc@test.com
console.log("Description: ", assignResponse.data.description);
} else {
console.log("Error", assignResponse.error);
}
});

.completeDocAssignment()

To set the assignment as completed.

Input

CompleteDocAssignmentParams

property

type

required

description

doctype

string

yes

The target doctype

docname

string

yes

The target document having the assignment

assignedTo

string

yes

The user assigned previously to the document to be completed

Output

any[]

Example

async-await

const completedAssignment = await renovationInstance.model.completeDocAssignment(
{
assignedTo: "abc@test.com",
doctype: "Renovation Review",
docname: "Renovation Review A"
}
);
if (completedAssignment.success) {
// Assignment: [{"owner": "abc@test.com","description": "Assignment"}]
console.log("Assignment: ", completedAssignment.data);
} else {
console.log("Error", completedAssignment.error);
}

Classic Promise

renovationInstance.model
.completeDocAssignment({
assignedTo: "abc@test.com",
doctype: "Renovation Review",
docname: "Renovation Review A"
})
.then(completedAssignment => {
if (completedAssignment.success) {
// Assignment: [{"owner": "abc@test.com","description": "Assignment"}]
console.log("Assignment: ", completedAssignment.data);
} else {
console.log("Error", completedAssignment.error);
}
});

.unAssignDoc()

To unassign a user from an assignment.

Input

UnAssignDocParams

property

type

required

description

doctype

string

yes

The target doctype

docname

string

yes

The target document having the assignment

unAssignFrom

string

yes

The user to be unassigned

Output

string

Example

async-await

const unassigned = await renovationInstance.model.unAssignDoc({
unAssignFrom: "abc@test.com",
doctype: "Renovation Review",
docname: "Renovation Review A"
});
if (unassigned.success) {
// UnAssign Response: OK
console.log("UnAssign Response: ", unassigned.data);
} else {
console.log("Error", unassigned.error);
}

Classic Promise

renovationInstance.model
.unAssignDoc({
unAssignFrom: "abc@test.com",
doctype: "Renovation Review",
docname: "Renovation Review A"
})
.then(unassign => {
if (unassigned.success) {
// UnAssign Response: OK
console.log("UnAssign Response: ", unassigned.data);
} else {
console.log("Error", unassigned.error);
}
});

.getDocsAssignedToUser() ★

To get the documents that are assigned to a user.

Input

GetDocsAssignedToUserParams

property

type

required

description

assignedTo

string

yes

The target user

doctype

string

no

The target doctype

status

string

no

Whether to query the status is "Open" or "Closed"

Output

GetDocsAssignedToUserResponse[]

Example

async-await

const docsAssigned = await renovationInstance.model.getDocsAssignedToUser({
assignedTo: "abc@test.com"
});
if (docsAssigned.success) {
// Number of docs: 3
console.log("Number of docs: ", docsAssigned.data.length);
// Doctype: Renovation Review
console.log("Doctype: ", docsAssigned.data[0].doctype);
} else {
console.log("Error", docsAssigned.error);
}

Classic Promise

renovationInstance.model
.getDocsAssignedToUser({
assignedTo: "abc@test.com"
})
.then(docsAssigned => {
if (docsAssigned.success) {
// Number of docs: 3
console.log("Number of docs: ", docsAssigned.data.length);
// Doctype: Renovation Review
console.log("Doctype: ", docsAssigned.data[0].doctype);
} else {
console.log("Error", docsAssigned.error);
}
});

.getUsersAssignedToDoc()

To get the users assigned to a document.

Input

GetUsersAssignedToDocParams

property

type

required

description

doctype

string

yes

The target doctype

docname

string

yes

The target document

Output

GetUsersAssignedToDocResponse[]

Example

async-await

const usersAssigned = await renovationInstance.model.getUsersAssignedToDoc({
doctype: "Renovation Review",
docname: "Renovation Review A"
});
if (usersAssigned.success) {
// Number of users: 2
console.log("Number of users: ", usersAssigned.data.length);
// Assigned: abc@test.com
console.log("Assigned: ", usersAssigned.data[0].assignedTo);
} else {
console.log("Error", usersAssigned.error);
}

Classic Promise

renovationInstance.model
.getUsersAssignedToDoc({
doctype: "Renovation Review",
docname: "Renovation Review A"
})
.then(usersAssigned => {
if (usersAssigned.success) {
// Number of users: 2
console.log("Number of users: ", usersAssigned.data.length);
// Assigned: abc@test.com
console.log("Assigned: ", usersAssigned.data[0].assignedTo);
} else {
console.log("Error", usersAssigned.error);
}
});

.addTag()

To add a tag to a document.

If the tag exists, a success is returned silently.

Input

AddTagParams

property

type

required

description

doctype

string

yes

The target doctype

docname

string

yes

The target document

tag

string

yes

The tag to be added

Output

string

The tag added to the document.

Example

async-await

const addedTag = await renovationInstance.model.addTag({
doctype: "Renovation Review",
docname: "Test Renovation Review",
tag: "test-tag"
});
if (addedTag.success) {
// Tag added: test-tag
console.log("Tag added: ", addedTag.data);
} else {
console.log("Error", addedTag.error);
}

Classic Promise

renovationInstance.model
.addTag({
doctype: "Renovation Review",
docname: "Test Renovation Review",
tag: "test-tag"
})
.then(addedTag => {
if (addedTag.success) {
// Tag added: test-tag
console.log("Tag added: ", addedTag.data);
} else {
console.log("Error", addedTag.error);
}
});

Possible Errors

Doctype Does Not Exist

HTTP code: 404

type: NotFoundError

cause: DocType does not exist

suggestion: Make sure the queried DocType is input correctly or create the required DocType

Non-existing document

HTTP code: 404

type: NotFoundError

cause: Docname does not exist

suggestion: Make sure the queried document name is correct or create the required document

.removeTag()

To remove a tag from a document.

Input

RemoveTagParams

property

type

required

description

doctype

string

yes

The target doctype

docname

string

yes

The target document

tag

string

yes

The tag to be removed

Output

null

If the tag doesn't exist, a success is returned silently.

Example

async-await

const removeTag = await renovationInstance.model.removeTag({
doctype: "Renovation Review",
docname: "Test Renovation Review",
tag: "test-tag"
});
if (removeTag.success) {
// Tag removed
console.log("Tag removed");
} else {
console.log("Error", removeTag.error);
}

Classic Promise

renovationInstance.model
.removeTag({
doctype: "Renovation Review",
docname: "Test Renovation Review",
tag: "test-tag"
})
.then(removeTag => {
if (removeTag.success) {
// Tag removed
console.log("Tag removed");
} else {
console.log("Error", removeTag.error);
}
});

Possible Errors

Doctype Does Not Exist

HTTP code: 404

type: NotFoundError

cause: DocType does not exist

suggestion: Make sure the queried DocType is input correctly or create the required DocType

Non-existing document

HTTP code: 404

type: NotFoundError

cause: Docname does not exist

suggestion: Make sure the queried document name is correct or create the required document

.getTaggedDocs()

To get all the tagged documents of a certain doctype.

Input

GetTaggedDocsParams

property

type

required

description

doctype

string

yes

The target doctype

tag

string

yes

The target tag

Output

string[]

The names of the documents as a list.

Example

async-await

const taggedDocs = await renovationInstance.model.getTaggedDocs({
doctype: "Renovation Review",
tag: "test-tag"
});
if (taggedDocs.success) {
// Number of documents: 3
console.log("Number of documents: ", taggedDocs.data.length);
} else {
console.log("Error", taggedDocs.error);
}

Classic Promise

renovationInstance.model
.getTaggedDocs({
doctype: "Renovation Review",