Internal $D methods

Basic functions

$D.eval() or $D.getValueFromTemplate() Getting the field value of the current object

$D.getValueFromTemplate = function(fieldName[string])
// the same but shorter:
$D.eval = function(fieldName[string])
​
// examples
var name = $D.getValueFromTemplate("{{name}}") // name == Ivan
​
// you also can get values from linked objects
var phone = $D.getValueFromTemplate("{{author_id.phone}}") // phone == 79141230000
​
// tip: for getting data from arrayLinks use $D.store.get()

$D.store.get() Getting an object from different structure

$D.store.get = function(structName[string], objectID[string], fields[object])
​
// example
var object = $D.store.get("WebUser", "7967", {fields: ["phone", "role"]});
// object == { role: "candidate,admin", phone: "79670190000", id: "7967" }

$D.store.save() Saving an object

$D.store.save = function(structName[string], obj[object], createEvent[boolean])
​
// example
var ID = "10341"
$D.store.save("WebUser", {"id": ID, "stringF": "Changed string value" }, true)
​
// note that if createEvent == false, no event will be created,
// so the scenarios will not trigger

$D.console.log() Console logging

$D.console.log = function(string)
​
// example
$D.console.log('a = ' + a)

Dealing with context

$D.context.get("test")
$D.context.set("test", "value111")

Additional functions

$D.fs.download() Saving the file to the internal file storage

Function downloads the file and saves it to the File storage​

$D.fs.download(fileUrl[string]) = function(string)
​
// example
var fileUrl = $D.fs.download("https://booble.com/files/logo.png")
// fileUrl == "https://api.directual.com/fileUploaded/uao/2a10d948-2e2e-49cb-9987-54f00cd6528d.png"

$D.concat() Adding an element into array, having avoided duplication

$D.concat = function(string, string)
// arrays in Directual are strings, comma separated
​
$D.concat('{{array}}', 'new element')
// or
$D.concat('{{array}}', '{{other_field}}')
// even or
$D.concat('{{array}}', '{{other_field_1}},{{other_field_2}}')
//
// e.g.
// $D.concat('', '3') returns 3
// $D.concat('1,2', '1,2,3') returns 1,2,3
// $D.concat('1,2,3', '3,4') returns 1,2,3,4
// $D.concat('1,2,3', '3') returns 1,2,3

$D.splice() Removing an element from array

$D.splice = function(string, string)
// arrays in Directual are strings, comma separated
​
$D.splice('{{array}}', 'removed element')
// or
$D.splice('{{array}}', '{{other_field}}')
// even or
$D.splice('{{array}}', '{{other_field_1}},{{other_field_2}}')
//
// e.g.
// $D.splice('', '3') returns ''
// $D.splice('1,2', '1,2,3') returns 3
// $D.splice('1,2,3', '3,4') returns 1,2
// $D.splice('1,2,3', '3') returns 1,2

$D.hash.md5(), $D.hash.bcrypt(), $D.hash.sha256()

function(string)
​
$D.hash.md5('hello world')
// returns 5eb63bbbe01eeed093cb22bb8f5acdc3
​
$D.hash.bcrypt('hello world')
// returns $2a$10$H.NnoiFyqDicSv8ufvW9iutzoHvLs0MsXWQk0ZVRhUcj9Mpgv.0/.
​
$D.hash.sha256('hello world')
// returns b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9

You can choose the encryption method for user's passwords in API security settings​

$D.arrayContainsAny() check if an array contains at least one element

$D.arrayContainsAny = function(string, string)
​
$D.arrayContainsAny("1,2,3","3,4") // returns true
$D.arrayContainsAny("1,2,3","4,5") // returns false

$D.arrayContainsAll() check if an array contains all the elements

$D.arrayContainsAll = function(string, string)
​
$D.arrayContainsAll("1,2,3","3,4") // returns false
$D.arrayContainsAll("1,2,3","2,3") // returns true

$D.json.fromXML() converts XML to JSON

$D.json.fromXML("{{xml}}")
​
// often there is a need to use the following templating features:
$D.json.fromXML("{β€Œ{#escape}β€Œ}{{#stripNewLine}β€Œ}{{xml}}{β€Œ{/stripNewLine}}{β€Œ{/escape}β€Œ}")