Internal $D methods

Basic functions

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

1
$D.getValueFromTemplate = function(fieldName[string])
2
// the same but shorter:
3
$D.eval = function(fieldName[string])
4
​
5
// examples
6
var name = $D.getValueFromTemplate("{{name}}") // name == Ivan
7
​
8
// you also can get values from linked objects
9
var phone = $D.getValueFromTemplate("{{author_id.phone}}") // phone == 79141230000
10
​
11
// tip: for getting data from arrayLinks use $D.store.get()
Copied!

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

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

$D.store.save() Saving an object

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

$D.console.log() Console logging

1
$D.console.log = function(string)
2
​
3
// example
4
$D.console.log('a = ' + a)
Copied!

Dealing with context variables

1
$D.context.get("test")
2
$D.context.set("test", "value111")
Copied!

Additional functions

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

Function downloads the file and saves it to the File storage​
1
$D.fs.download(fileUrl[string]) = function(string)
2
​
3
// example
4
var fileUrl = $D.fs.download("https://booble.com/files/logo.png")
5
// fileUrl == "https://api.directual.com/fileUploaded/uao/2a10d948-2e2e-49cb-9987-54f00cd6528d.png"
Copied!

$D.image.resize() Resizing an image

Function resizes the image and saves the result to the File storage​
1
$D.image.resize(fileUrl[string], params) = function(string)
2
​
3
//params is a json object like {"width": 100}, {"scale": .3}, or {"height": 130}
4
var resizedImageUrl = $D.image.resize("https://booble.com/files/logo.png", {"width": 100})
Copied!

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

1
$D.concat = function(string, string)
2
// arrays in Directual are strings, comma separated
3
​
4
$D.concat('{{array}}', 'new element')
5
// or
6
$D.concat('{{array}}', '{{other_field}}')
7
// even or
8
$D.concat('{{array}}', '{{other_field_1}},{{other_field_2}}')
9
//
10
// e.g.
11
// $D.concat('', '3') returns 3
12
// $D.concat('1,2', '1,2,3') returns 1,2,3
13
// $D.concat('1,2,3', '3,4') returns 1,2,3,4
14
// $D.concat('1,2,3', '3') returns 1,2,3
Copied!

$D.splice() Removing an element from array

1
$D.splice = function(string, string)
2
// arrays in Directual are strings, comma separated
3
​
4
$D.splice('{{array}}', 'removed element')
5
// or
6
$D.splice('{{array}}', '{{other_field}}')
7
// even or
8
$D.splice('{{array}}', '{{other_field_1}},{{other_field_2}}')
9
//
10
// e.g.
11
// $D.splice('', '3') returns ''
12
// $D.splice('1,2', '1,2,3') returns 3
13
// $D.splice('1,2,3', '3,4') returns 1,2
14
// $D.splice('1,2,3', '3') returns 1,2
Copied!

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

1
function(string)
2
​
3
$D.hash.md5('hello world')
4
// returns 5eb63bbbe01eeed093cb22bb8f5acdc3
5
​
6
$D.hash.bcrypt('hello world')
7
// returns $2a$10$H.NnoiFyqDicSv8ufvW9iutzoHvLs0MsXWQk0ZVRhUcj9Mpgv.0/.
8
​
9
$D.hash.sha256('hello world')
10
// returns b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
Copied!
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

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

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

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

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

1
$D.json.fromXML("{{xml}}")
2
​
3
// often there is a need to use the following templating features:
4
$D.json.fromXML("{β€Œ{#escape}β€Œ}{{#stripNewLine}β€Œ}{{xml}}{β€Œ{/stripNewLine}}{β€Œ{/escape}β€Œ}")
Copied!
Last modified 15d ago