LogoLogo
HomepageResellerPricingSign in
  • AppMachine
  • πŸ“ƒProduct Updates
  • πŸ‘·Build your app
    • Preview your app
    • App templates
    • App Settings
    • Update payment method
    • Cancel subscription
  • ❔General App Building FAQ
  • How to
  • 🧱Blocks
    • πŸ” Admin
    • πŸ“„Blank Page
    • πŸ“žCall
    • 🏒Contact
    • πŸ“Contact Us
    • 🧾Coupons
    • πŸ“ƒCustom Form
    • πŸ“§Email
    • πŸ—“οΈEvents
    • ❔FAQ
    • 🌐Facebook
    • πŸ•‘Hours
    • ℹ️Information
    • πŸ“£Intro
    • β˜•JavaScript
    • πŸ”’Lock
    • 🎧Music
    • πŸ“°News
    • πŸ“ƒPDF
    • πŸ—ΊοΈPOI
    • πŸ‘₯People
    • πŸ“·Photos
    • 🏬Products
    • πŸ“©Push Messages
    • πŸ“»Radio
    • β†ͺ️Submenu
    • 🐦Twitter
    • πŸ‘¨β€πŸ’»URLs
    • πŸ–₯️Web Page
    • πŸ“ΊVideo
    • πŸ“±WhatsApp
  • πŸ“ƒData
    • Appmachine Data
    • Delete (test) data from Custom Form
    • Google Sheets
    • Web services
  • πŸ–ŒοΈStyle your app
    • Theme
    • Home Screen
    • FAQ Style
  • 🎨Style your screens
    • Elements
  • Share your app
    • ✈️Publishing your app
      • Technical Setup Quick Start Guide
      • Update your app
      • Unpublish an app from the app stores
    • 🌐Web App Publishing
      • Hosting on custom domain
    • 🍏Apple App Store
      • iOS developer account
      • App Store Connect API keys
      • Link your app
      • New app record in App Store Connect
      • App privacy details
      • Edit Store information
      • Fix App publish issues
      • Push certificates
      • App Store Connect app status overview
      • App Store Review Guidelines
      • Publish app Unlisted
      • Accept updated License agreement
      • Apple App Store FAQ
      • iPad
      • Enterprise
        • Setup your Enterprise app
        • Create iOS Distribution Certificate
        • Create App ID
        • Create Mobile Provisioning Profile
        • Downloading and installing an Enterprise app
    • 🍐Google Play
      • Create a Google Developer Account
      • Setup your Android app
      • How to request a Google Maps API Key
      • Test your Android app before publishing to Google Play
      • Upload your Android app to Google Play Store for the first time
      • Update Android app (short)
      • Update an Android app (extended)
      • Data safety details on the Google Play Store
      • Sell your app in Google Play Store
      • Create Google merchant account
      • Force Store Update for your Android App
      • Authorise an additional user to your Google Play developer account
      • What if my app is suspended by Google?
  • App details
    • πŸ•΅οΈGoogle Analytics
      • Google Analytics setup overview
      • Setup iOS analytics
      • Setup Android analytics
      • Inviting a new Google Analytics user
    • πŸ”₯Firebase
      • Create Firebase project
      • Locate Firebase Server key
      • Renew Firebase Server Key
      • Register iOS app
      • Register Android app
      • Enable Cloud Messaging
      • Enable Google Analytics
      • Google Analytics via Firebase
    • πŸ“¨Push notifications
      • Setup Apple Push certificate
    • πŸ§‘β€πŸ€β€πŸ§‘User management
      • Create Apple Sign In key
      • Setup Azure Active Directory
      • Create Facebook App ID Secret
    • 🐦Twitter API keys
    • πŸ”Privacy policy
    • πŸ‘©β€πŸ”§Your Account
      • Account Settings
      • Account FAQ
      • Payment FAQ
    • πŸ“±Admin CMS
  • Developers
    • πŸ‘©β€πŸ’»JavaScript
      • Develop locally
      • SDK
        • Core
        • JS Data
        • Media
        • Navigation
        • Notification
        • User
      • CLI
        • CLI Token and Secret
        • Errors
          • CONFIG_PROPERTIES_INVALID
          • CONFIG_VALUES_INVALID
          • ENTRY_FILE_NOT_FOUND
          • OUTPUT_DIRECTORY_IS_EMPTY
          • OUTPUT_DIRECTORY_NOT_FOUND
          • TOKEN_SECRET_NOT_PROVIDED
          • TOKEN_SECRET_NOT_VALID
      • Migrate from old Custom JS
    • πŸ’»Web services
Powered by GitBook
On this page
  • Get Records​
  • Get Current Record​

Was this helpful?

  1. Developers
  2. JavaScript
  3. SDK

JS Data

Data is the driving force behind your app. Integrate your custom JavaScript code with the web services in your app using these functions.

PreviousCoreNextMedia

Last updated 2 years ago

Was this helpful?

Get Records

Get all records of a webservice by specifying the name and (when required) parameters of a webservice block to fetch the records for. Optionally the records for the current webservice (that is, the closest one to the current block) can be fetched by not specifiying any name. For example, to fetch all records of an Excel block that is the parent of the block running your code you simply call getRecords().

Arguments

Name
Type
Required
Default

variableName

String

-

parameters

String

-

Example

Example if using a data block with products in it. You can simply use your favorite JavaScript framework.

// Example with React
import React from 'react'
import { getRecords } from '@myjsblock/sdk'

interface Product {
    name: string
    price: number
    image: string
    description: string
}

export default function RelatedProducts(): JSX.Element {
    const [relatedProducts, setRelatedProducts] = React.useState<Product[]>([]);

    React.useEffect(() => {
        getRecords<Product[]>().then(products => {
            setRelatedProducts(products);
        });
    },[]);

    return (
        <ul>
            {
                relatedProducts.map((product) => (
                    <li>{product.name}</li>
                ));
            }
        </ul>
    );
}
// Example with React
import React from 'react'
import { getRecords } from '@myjsblock/sdk'

export default function RelatedProducts() {
    const [relatedProducts, setRelatedProducts] = React.useState([]);

    React.useEffect(() => {
        getRecords().then(products => {
        setRelatedProducts(products);
        });
    },[]);

    return (
        <ul>
            {
                relatedProducts.map((product) => (
                    <li>{product.name}</li>
                ));
            }
        </ul>
    );
}
Error Code
Description

INVALID_ARGUMENT

The specified variableName doesn't reference a webservice block. An parameter in parameters is not valid for the webservice.

WEBSERVICE_ERROR

The remote server returned an invalid result or the result could not be parsed.

MISSING_CONTEXT

The variableName parameter is missing and the current block is not in a data context.

Get the record that is currently selected. For instance, if your code is running in a block that is the child of a list block (e.g. an Excel block) getCurrentRecord() will return the data item of the list item that the user selected in the previous screen.

Example if using the data showing a "detail" page.

// Example with React
import React from 'react'
import { getCurrentRecord } from '@myjsblock/sdk'

interface Product {
    name: string
    price: number
    image: string
    description: string
}

export default function ProductDetail(): JSX.Element {
    const [product, setProduct] = React.useState<Product>();

    React.useEffect(() => {
        getCurrentRecord<Product>().then(setProduct);
    },[]);

    if (!product) {
        return null;
    }

    return (
        <main className="product">
            <img src={product.image}>
            <h1>{product.name}</h1>
            <p className="price">{product.price}</p>
            <p className="info">{product.description}</p>
        </main>
    );
}
import React from 'react'
import { getCurrentRecord } from '@myjsblock/sdk'

export default function ProductDetail() {
    const [product, setProduct] = React.useState();

    React.useEffect(() => {
        getCurrentRecord().then(setProduct);
    },[]);

    if(!product) {
        return null;
    }

    return (
        <main className="product">
            <img src={product.image}>
            <h1>{product.name}</h1>
            <p className="price">{product.price}</p>
            <p className="info">{product.description}</p>
        </main>
    );
}
Error Code
Description

MISSING_CONTEXT

The current block is not in a data context.

Errors

Here is a list of errors that can be thrown when calling this function in addition to :

Get Current Record

Example

Errors

Here is a list of errors that can be thrown when calling this function in addition to :

πŸ‘©β€πŸ’»
​
​
​
​
​
​
​
generic errors
generic errors