Documentation
AcademyCommunitySign In
  • 👋Overview
  • 💙Platform Features
  • Getting started
    • 🚪Signing up & Logging in
      • 👤Profile Settings
    • 🎛️App Management
    • ✴️Templates to Start With
      • Basic Template (Blank app)
      • CRM Template
    • 👨‍🎓Learning Directual
      • 👨‍🏫Webinars
  • Data base
    • Data Structures
      • System Structures
    • Data Types
      • Markdown Cheat Sheet
      • Indexing Fields
      • Formatting Date/Time
    • Directual Query Language (DQL)
    • Import and Export
      • Import API
    • File Storage
      • API for File Storage
  • API and integraions
    • API-Endpoints
      • Advanced techniques for GET and POST requesting
        • Paging for GET-requests
        • Dynamic sorting for GET-requests
        • Custom filtering parameters for GET-requests
        • Advanced filtering for GET-requests
        • Formatting response for GET-request
        • Fields validation for POST-requests
        • Synchronic scenarios for POST-requests
        • Cross-Origin Resource Sharing CORS
      • API testing and debugging
      • Coding mode (raw mode) in filters
      • Swagger specification
    • Webhooks
    • Authentication API
      • Login/password
      • OpenID connect
      • Facebook oAuth
      • Google oAuth
    • Security Features
    • Other Integrations
      • OpenAI
      • Integration Hubs
        • Zapier
      • Telegram
        • Telegram: Advanced Techniques
      • Email
        • SMTP
        • Gmail
      • Twilio SMS
      • Airtable
      • Coupler.io
      • Other No-Code Tools
        • Bubble.io
          • Authorization
          • Displaying Data from Directual on Bubble
        • Adalo
        • UI bakery
        • Tilda
        • AppGyver
  • App interface
    • Web-App Builder basics
    • Web-App Settings
      • General web-app settings
      • Main menu
      • Creating a logotype
      • Web-App color scheme
      • Web-app typography
      • White Labeling
      • Web-App Icon
      • Custom Domain
      • Custom code
    • Setting Up Page Layout
      • Subpages and URL Parameters
    • Components
      • Multistep Form
      • Cards
      • Table
      • Kanban
      • Chart
      • Markdown text
      • HTML code
      • Hint
      • Link Button
      • Video
      • Form (outdated)
    • Embedding Pages
  • Scenarios
    • Understanding Directual Scenarios
      • Directual Event Model
    • Event-Based Triggers
    • Scheduled Triggers
      • Cron Format
    • Synchronous Scenarios
    • Editing Scenarios
      • System Steps
        • Start step
        • Delay step
        • Comment step
        • Catch error step
        • Link scenario step
        • Exit step
      • Action steps
        • Edit object step
        • Create object step
        • Search objects step
        • JSON step
        • Delete object step
        • Run report step
        • Generate document step
        • JS SDK step
      • Condition steps
        • Condition step
        • A/B test step
        • JS SDK condition step
      • Integration steps
        • HTTP-request step
        • Zapier step
        • Telegram step
        • API response
        • Email step
        • SQL-request step
        • Queue step
    • Using Variables
      • Global Variables
      • Context Variables (scenario parameters)
    • Testing and Debugging
    • System Scenarios
    • Advanced Scenario Settings
  • Template system
    • Templating Principles
      • Templating Techniques for Scenarios
      • Templating Techniques for Web-pages
    • Coding Mode (evaluating as a JS-expression)
    • Comparison Component
      • Regular Expressions
    • Tips for Dealing with Data
  • Telegram
    • Telegram
  • Plugins
    • 🔌Using Plugins
      • Scenario Steps Plugins
      • Web Plugins
      • User Authentication Plugins (Not Web3)
        • TMA (Telegram Mini App)
        • Google OAuth Plugin
        • Facebook OAuth Plugin
        • Open ID Auth Plugin
      • Blockchain (Web3)
        • TON (The Open Network)
        • Polygon
        • Ethereum
        • NEAR Protocol
        • NFT and Smart-Contracts
        • MetaMask Wallet
        • WalletConnect
      • WebSockets (Socket.IO)
    • 🪚Developing Plugins
      • Developing Scenario Plugins
      • Developing Web-plugins
        • Example: Using Chart.js in Directual
        • Example: Building Simple Form
        • Example: TON plugin
  • Teams
    • Teams
    • Sandbox Apps
  • JavaScript SDK
    • Directual + JavaScript SDK: The Basics
    • Internal $D Methods
    • Using Google Sheets
    • JS SDK: Examples
  • Reports
    • Reports
  • App life cycle management
    • App Versions
  • Directual 💙 React JS
    • Directual + React JS
  • Pricing and billing
    • 💳How Billing Works
    • 🎁Promo Codes
    • Pricing Plans for Apps
    • Team Pricing Plans
    • How we count requests and operations
    • On-Demand Resource Consumption
    • 🤝Affiliate Program
  • Hire a Directual expert
    • 🏆Certification
    • 🤝Matching with Experts
    • 🏦Escrow service
  • Security and stability
    • 🛡️Public Cloud
    • Platform Architecture
  • Support
    • 📬Contact Directual
  • Directual step-by-step
    • Public Development Roadmap
      • Step 0: Planning App Architecture
      • Step 1: Requesting Features
      • Step 2: Approving Features
      • Step 3. Upvoting Features
      • Step 4. Watching Features
    • Weather Forecast App
    • Web3 Marketplace on Polygon
    • Transferring NFT
Powered by GitBook
On this page
  • Basic functions
  • $D.eval() or $D.getValueFromTemplate() Getting the field value of the current object
  • $D.store.get() Getting an object from a different structure
  • $D.store.save() Saving an object
  • $D.store.find Searching for objects
  • $D.console.log() Console logging
  • Dealing with context variables
  • Additional functions
  • $D.fs.download() Saving files to the internal file storage
  • $D.fs.saveText() Saving text to file
  • $D.image.resize() Resizing images
  • $D.concat() Adding an element into array while avoiding duplication
  • $D.splice() Removing elements from an array
  • $D.hash.md5(), $D.hash.bcrypt(), $D.hash.sha256()
  • $D.arrayContainsAny() Checking if an array contains at least one element
  • $D.arrayContainsAll() Checking if an array contains all elements
  • $D.json.fromXML() Converting XML to JSON
  • JWT Methods

Was this helpful?

  1. JavaScript SDK

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 a 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.store.find Searching for objects

Result is an array of objects.

var filters = [{
    "exp": "<=",
    "field": "x",
    "value": "10",
    "isExp": false
}]

$D.store.find('SystemMessage', filters, 
{
    "page":0, 
    "size":10, 
    "fields": ["id", "isError", "msg", "type", "userID"]
});

$D.console.log() Console logging

$D.console.log = function(string)

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

Dealing with context variables

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

Additional functions

$D.fs.download() Saving files to the internal 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.fs.saveText() Saving text to file

Function returns link to the file in Dirctual storage

$D.fs.saveText(text[string], format[string]) = function(string, string)
//$D.fs.saveText('<html><body>test</body></html>', 'html')
//$D.fs.saveText('hello \n world', 'txt')
//$D.fs.saveText('1;2;3', 'csv')

$D.image.resize() Resizing images

$D.image.resize(fileUrl[string], params) = function(string)

//params is a json object like {"width": 100}, {"scale": .3}, or {"height": 130}
var resizedImageUrl = $D.image.resize("https://booble.com/files/logo.png", {"width": 100})

$D.concat() Adding an element into array while avoiding 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 elements from an 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

$D.arrayContainsAny() Checking 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() Checking if an array contains all 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() Converting 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}‌}")

JWT Methods

Encode

If the 'expiration' (exp field) is undefined, set the current timestamp in seconds based on UTC time.

 //example code
DirectualEngine.addEventListener(AppEvents.START, function(context){
 var secret = $D.eval("{{secret}}") // get RS256 secret key
 var token = {
    "data": "",
    "kid":"b3fdfe5ebb9b60500eb96b05ece80d0ed294ed7f",
    "iss":"app@directual.com",
    "sub":"app@directual.com",  
    "aud":"https://api.directual.com/",
    "exp": 1628690000,
    "iat": 1628686000
  }
 return $D.jwt.encode(token, secret, "RS256");
 });
 $D.jwt.encode({
      "sub": "Directual",
      "iat": 1516239022
  }, "dTkJvdM0DroUP43X1faVKydVT6FpAUlaqur+y+r14mo=", "HS256")
 $D.jwt.encode({
      "sub": "Directual",
      "iat": 1516239022,
      "data": {"email":"test"}
  }, "dTkJvdM0DroUP43X1faVKydVT6FpAUlaqur+y+r14mo=", "HS256")

Decode

If the expiration date is earlier than the current time, this function will throw an exception.

var decodeResutl = $D.jwt.decode(payload, secret, "HS256")

$D.console.log(decodeResult.claim.subject)

PreviousDirectual + JavaScript SDK: The BasicsNextUsing Google Sheets

Last updated 10 months ago

Was this helpful?

filters (the second argument) syntax is the same for

This function downloads and saves files to the .

This function resizes images and saves the result to the

You can select the encryption method for user passwords in the .

API-filtering raw mode
File storage
File storage
API security settings