new CrmRpc( [crmEnv] [, logFunction] [, threadId])
Construct a CrmRpc object
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
crmEnv |
CrmEnv |
<optional> |
When empty, uses the Efficy context of the browser |
logFunction |
function |
<optional> |
Your (custom) log function to call for requests and responses, e.g. console.log |
threadId |
number |
<optional> |
Unique thread ID for logging purposes |
- Source:
Example
function logger(msg, reqLog) {
console.log(msg);
}
const crm = new CrmRpc(crmEnv, logger);
Extends
- RemoteAPI
Members
-
<readonly> constants :object
-
Efficy Enterprise constants
Type:
- object
- Source:
-
currentDatabaseAlias
-
Retrieves the alias (name) of the currently connected database
- Source:
-
currentDatabaseTimezone
-
Retrieves the current database timezone
- Source:
-
currentLicenseName
-
Retrieves the current license name
- Source:
-
currentUserCode
-
Retrieves the current user code, e.g. "CRM01"
- Source:
-
currentUserFullName
-
Retrieves the current user full name
- Source:
-
currentUserGroups
-
Retrieves the group memberships of the current user as semicolon separated string list, e.g. "1;28;292;936"
- Source:
-
currentUserId
-
Retrieves the current user key, e.g. "4"
- Source:
-
currentUserTimezone
-
Retrieves the current user timezone
- Source:
-
ws :WsObject
-
Provides access to the methods of a constructed WsObject Methods are isolated from RemoteObjects because they contain implicit executeBatch() operations
Type:
- Source:
Methods
-
consultFavorites(entity)
-
Consult your favorite records.
Parameters:
Name Type Description entitystring The entity name, e.g. "Comp" - Source:
Returns:
- Type
- DataSetObject
Example
const compFavorites = crm.consultFavorites("Comp"); -
consultManyEx(entity, whereFields, whereValues, orderByExpression)
-
Selects records that exactly match certain field values
Parameters:
Name Type Description entitystring The entity name, e.g. "Comp" whereFieldsarray A list of field names to match (used as WHERE criteria), e.g. ["NAME", "OPENED"] whereValuesarray A list of values to match, e.g. ["Efficy", "1"] orderByExpressionstring SQL sort expression, e.g. "K_COMPANY desc" - Source:
Returns:
- Type
- DataSetObject
Example
const morningMeetings = crm.consultManyEx("Acti", ["PLANNED", "D_BEGIN"], ["1", "2022-03-14 09:00:00"], "D_BEGIN"); -
consultRecent(entity [, extraFields])
-
Consult your recent records, optionally extended by additional fields.
Parameters:
Name Type Argument Default Description entitystring The entity name, e.g. "Comp" extraFieldsarray <optional>
[] A list of extra fields to consult for each recent entity record, e.g. ["POSTCODE", "CITY"] - Source:
Returns:
- Type
- DataSetObject
Example
const compRecents = crm.consultRecent("Comp"); const compRecentsEx = crm.consultRecent("Comp", ["CITY", "COUNTRY"]); -
deleteEntity(entity, keys)
-
Deletes records
Parameters:
Name Type Description entitystring The entity name, e.g. "Comp" keysnumber | Array.<number> List of keys - Source:
-
<async> executeBatch()
-
Execute all assembled and queued RPC operations
- Source:
-
executeDatabaseQuery(idQuery [, queryParameters] [, loadBlobs] [, recordCount])
-
Executes a database query stored in QUERIES
Parameters:
Name Type Argument Default Description idQuerynumber queryParametersarray <optional>
The query parameters delivered via a JS Array loadBlobsboolean <optional>
false If true, blob fields (e.g. memo, stream) are returned recordCountnumber <optional>
0 If 0, return all records - Source:
Returns:
- Type
- DataSetObject
Example
const tags = crm.executeDatabaseQuery(99990034); // Query "Standard: Top company tags"
-
executeSqlQuery(sqlQueryText, queryParameters [, loadBlobs] [, recordCount])
-
Runs a native (SQL) database query, only if the user has SQL Exec the permissions!
Parameters:
Name Type Argument Default Description sqlQueryTextstring The SQL query text queryParametersarray The query parameters delivered via a JS Array loadBlobsboolean <optional>
false If true, blob fields (e.g. memo, stream) are returned recordCountnumber <optional>
0 Limit the returned records - Source:
Returns:
- Type
- DataSetObject
Example
const appos = crm.executeSqlQuery("Select * from ACTIONS where PLANNED=:p1 and DONE=:p2", ["1", "0"], true, 2); -
executeSystemQuery(master, detail, queryParameters [, loadBlobs] [, recordCount])
-
Executes a system database query stored in SYS_QUERIES
Parameters:
Name Type Argument Default Description masternumber detailnumber queryParametersarray The query parameters delivered via a JS Array loadBlobsboolean <optional>
false If true, blob fields (e.g. memo, stream) are returned recordCountnumber <optional>
0 If 0, return all records - Source:
Returns:
- Type
- DataSetObject
Example
const contDupls = crm.executeSystemQuery(4, 1, [11000,2]); // System query "Own Duplicate List"
-
getCategoryCollection(entity)
-
Request the accessible categories - for the current user - of the given entity
Parameters:
Name Type Description entitystring The entity name, e.g. "Comp" - Source:
Returns:
- Type
- DataSetObject
Example
const compCategories = crm.getCategoryCollection("comp"); -
getConsultObject(consultHandle, entity)
-
Create and return an ConsultObject based on an existing consultHandle
Parameters:
Name Type Description consultHandlenumber entitystring Weird, but the RPC interface requires the entity of the consultHandle! - Source:
-
getEditObject(editHandle)
-
Create and return an EditObject based on an existing editHandle
Parameters:
Name Type Description editHandlenumber - Source:
-
getEditRelationObject(editHandle)
-
Create and return an EditObject based on an existing editHandle
Parameters:
Name Type Description editHandlenumber - Source:
-
getSetting(module, name [, asString])
-
Requests the current value of a given Efficy setting.
Parameters:
Name Type Argument Default Description modulestring The name of the setting. namestring The name of the module (JSON object) that owns the setting. asStringboolean <optional>
true If true, the settings of type TDateTime will be returned as a string formatted with the ShortDateTime format. If false, it will be returned as a float value. - Source:
Returns:
- Type
- StringObject
Example
const workingPeriodFrom = crm.getSetting("user", "WorkingPeriodFrom"); const workingPeriodFromFloat = crm.getSetting("user", "WorkingPeriodFrom", false); await crm.executeBatch(); workingPeriodFrom.result; // e.g. "30/12/1899 08:00" workingPeriodFromFloat.result; // e.g. "0.333333333333333 -
getSystemSettings()
-
Request a list of system settings. Use the Map object to retrieve settings
- Source:
Returns:
- Type
- ListObject
Example
const settings = crm.getSystemSettings(); await crm.executeBatch(); settings.map.get("ShortDateFormat"); // e.g. "dd/mm/yyyy" settings.map.forEach(console.log); // prints each setting on console -
getUserList()
-
Requests a list of users, groups and resources
- Source:
Returns:
- Type
- DataSetObject
Example
const userList = crm.getUserList();
-
logoff()
-
Logoff the remote session
- Source:
-
openConsultObject(entity, key)
-
Opens a consult context for the record identified by entity and key. A context remains memory-resident (on the web server) until it is closed. Always match with a closeContext() call to avoid memory consumption.
Parameters:
Name Type Description entitystring The entity name, e.g. "Comp" keynumber The key of the record. Use key = 0 to create a new record. - Source:
Returns:
- Type
- ConsultObject
Example
const comp = crm.openConsultObject("comp", 2); const dsComp = comp.getMasterDataSet(); const dsCompAddress = comp.getCategoryDataSet("COMP$ADDRESS"); const linkedContacts = comp.getDetailDataSet("cont"); await crm.executeBatch(); const companyNames = [comp.data.master.NAME, comp.data.category["COMP$ADDRESS"].NAME]; comp.closeContext(); await crm.executeBatch(); -
openEditObject(entity [, key])
-
Opens an edit context for the record identified by entity and key. A context remains memory-resident (on the web server) until it is closed. Always match with a closeContext() call to avoid memory consumption.
Parameters:
Name Type Argument Default Description entitystring The entity name, e.g. "Comp" keynumber <optional>
0 The key of the record. Use key = 0 to create a new record. - Source:
Returns:
- Type
- EditObject
Example
const docu = crm.openEditObject("docu", 0); docu.updateField("NAME", "Jan"); docu.insertDetail("Comp", 2); docu.insertDetail("Cont", 44395, true, true); docu.commitChanges(); docu.activateCategory("DOCU$INVOICING"); docu.updateCategoryFields("DOCU$INVOICING", { "D_INVOICE":"2021-01-08T00:00:00", "COMMUNICATION": "Hello World!" }); docu.updateCategoryField("DOCU$INVOICING", "PRE_PAID", 123.456) docu.clearDetail("Comp"); docu.insertDetail("Comp", 4); docu.insertDetail("Cont", 50512, false); docu.insertDetail("Prod", 4); docu.updateDetail("Prod", 0, { QUANTITY: 5 }); docu.setUsers([169, 170], true); docu.setUserSecurity(99999002, 271); docu.setReference(99999001); docu.commitChanges(); docu.closeContext(); await crm.executeBatch(); -
openEditRelationObject(entity, detail, key, detailKey [, relationId])
-
Opens an edit context for a relation. If the relation does not yet exist, it is created. A context remains memory-resident (on the web server) until it is closed. Always match with a closeContext() call to avoid memory consumption.
Parameters:
Name Type Argument Description entitystring The entity name, e.g. "Comp" detailstring The detail name, e.g. "Cont" keynumber The key of the entity detailKeynumber The key of the detail relationIdnumber <optional>
The key of the relation if multi-relation is available - Source:
Returns:
- Type
- EditRelationObject
Example
const contCont = crm.openEditRelationObject("cont", "cont", 5, 6); contCont.updateField("RELATION", 1); contCont.updateReciprocityField("RELATION", 2); contCont.commitChanges(); const dsContCont = contCont.getMasterDataSet(); const dsContCont1 = contCont.getMasterDataSet(1); await crm.executeBatch(); console.log(dsContCont.item["R_RELATION"]); console.log(dsContCont1.item["R_RELATION"]); contCont.closingCommit(); await crm.executeBatch(); -
search(entity, method, value [, own] [, contains] [, opened])
-
Performs a search on the database and returns the data set with search results.
Parameters:
Name Type Argument Default Description entitystring The entity name, e.g. "Comp" methodstring The field to be searched. Special values SEARCHFAST, SEARCHFULL, SEARCHTEXT, SEARCHFILENAME, SEARCHFILE correspond to the search options in the web application user interface valuestring The value to search ownboolean <optional>
false If true, search own records only. containsboolean <optional>
true If true, allow matches on part of field openedboolean <optional>
true If true, search for opened or active records only - Source:
Returns:
- Type
- DataSetObject
Example
const compSearch = crm.search("comp", "SEARCHFAST", "Efficy"); -
searchContactsByEmail(recipients)
-
Returns all the Contacts having one of the e-mail provided in their e-mail fields (or in the Cont_Comp relation).
Parameters:
Name Type Description recipientsArray.<string> The list of email addresses - Source:
Returns:
- Type
- DataSetObject
Example
const contactsByEmail = crm.searchContactsByEmail(["john.doe@efficy.com", "john.doe@outlook.com"]);
-
searchContactsByPhone(phoneNumber)
-
Returns all the first Contacts having a match with the provided (formatted) phone number
Parameters:
Name Type Description phoneNumberstring The phone number, doesn't have to be stripped from formatting - Source:
Returns:
- Type
- DataSetObject
Example
const contactsByPhone = crm.searchContactsByPhone("+32 474 00 00 00");