Class: CrmRpc

CrmRpc

Class to create Remote Objects

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
entity string 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
entity string The entity name, e.g. "Comp"
whereFields array A list of field names to match (used as WHERE criteria), e.g. ["NAME", "OPENED"]
whereValues array A list of values to match, e.g. ["Efficy", "1"]
orderByExpression string 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
entity string The entity name, e.g. "Comp"
extraFields array <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
entity string The entity name, e.g. "Comp"
keys number | 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
idQuery number
queryParameters array <optional>
The query parameters delivered via a JS Array
loadBlobs boolean <optional>
false If true, blob fields (e.g. memo, stream) are returned
recordCount number <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
sqlQueryText string The SQL query text
queryParameters array The query parameters delivered via a JS Array
loadBlobs boolean <optional>
false If true, blob fields (e.g. memo, stream) are returned
recordCount number <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
master number
detail number
queryParameters array The query parameters delivered via a JS Array
loadBlobs boolean <optional>
false If true, blob fields (e.g. memo, stream) are returned
recordCount number <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
entity string 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
consultHandle number
entity string 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
editHandle number
Source:

getEditRelationObject(editHandle)

Create and return an EditObject based on an existing editHandle
Parameters:
Name Type Description
editHandle number
Source:

getSetting(module, name [, asString])

Requests the current value of a given Efficy setting.
Parameters:
Name Type Argument Default Description
module string The name of the setting.
name string The name of the module (JSON object) that owns the setting.
asString boolean <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
entity string The entity name, e.g. "Comp"
key number 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
entity string The entity name, e.g. "Comp"
key number <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
entity string The entity name, e.g. "Comp"
detail string The detail name, e.g. "Cont"
key number The key of the entity
detailKey number The key of the detail
relationId number <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();

Performs a search on the database and returns the data set with search results.
Parameters:
Name Type Argument Default Description
entity string The entity name, e.g. "Comp"
method string The field to be searched. Special values SEARCHFAST, SEARCHFULL, SEARCHTEXT, SEARCHFILENAME, SEARCHFILE correspond to the search options in the web application user interface
value string The value to search
own boolean <optional>
false If true, search own records only.
contains boolean <optional>
true If true, allow matches on part of field
opened boolean <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
recipients Array.<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
phoneNumber string 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");