Skip to content

KVSFCYJsonManagement#

Procedures#

addJsonObjToArray(JsonArray, Text, Text) :#

Summary: Adds a JSON object with 'No.' and 'Name' properties to an existing JSON array. This procedure creates a standardized JSON object structure containing identifier and name fields, then appends it to the provided JSON array. This is commonly used for building lists of items such as customers, vendors, items, or other master data entities where both a code/number and descriptive name are needed. The procedure follows a consistent JSON schema that can be easily consumed by web services, APIs, or client applications expecting structured data with identifier and name pairs. This standardization ensures uniformity across different data export and integration scenarios, making it easier to process JSON arrays containing multiple entities with the same structural format for dropdown lists, lookup tables, or reference data.

procedure addJsonObjToArray(var jsonArr: JsonArray; no: Text; name: Text): 

Parameters:

  • jsonArr: JSON array variable to which the new JSON object will be appended, passed by reference for modification.
  • no: Identifier or number value to be stored in the 'No.' property of the JSON object.
  • name: Descriptive name or title value to be stored in the 'Name' property of the JSON object.

recordTojson(RecordRef) : Text#

Summary: Converts a recordset to a JSON array string containing all records and their field values. This procedure iterates through all records in the provided RecordRef, extracting field values from non-obsolete fields and creating JSON objects for each record. FlowFields are automatically calculated to ensure accurate values, and Option fields are converted to their string representation for better readability. Each record becomes a JSON object within a JSON array, providing a complete serialization of the recordset data. The procedure handles various field types appropriately, ensuring proper formatting and data integrity in the resulting JSON structure. This is particularly useful for data export scenarios, API responses, integration with external systems, and creating structured data representations for reporting or analysis purposes.

procedure recordTojson(varRecordRef: RecordRef): Text

Parameters:

  • varRecordRef: RecordRef containing the recordset to be converted to JSON, with current filters and position determining which records are processed.

Returns: JSON array string containing all records as JSON objects with their field names and formatted values.

recordTojsonObj(RecordRef) : JsonObject#

Summary: Converts a single record to a JSON object containing all field names and their corresponding values. This procedure operates on the current record position of the provided RecordRef, extracting field values from all non-obsolete fields and creating a JSON object with field names as keys and formatted field values as properties. FlowFields are automatically calculated to ensure accurate values, and Option fields are converted to their string representation for better readability and integration compatibility. Unlike the recordTojson procedure that processes multiple records into a JSON array, this procedure focuses on converting a single record into a JSON object structure. This is particularly useful for single record API responses, detailed record views, integration scenarios requiring individual record serialization, and creating structured data representations for specific record analysis or display purposes.

procedure recordTojsonObj(varRecordRef: RecordRef): JsonObject

Parameters:

  • varRecordRef: RecordRef positioned on the specific record to be converted to a JSON object with all field values.

Returns: JsonObject containing field names as keys and their corresponding formatted values as properties for the current record.

getFieldValueAsText(Text[50], JsonObject) : Text#

Summary: Extracts a specific field value from a JSON object and returns it as formatted text. This procedure searches for a named field within the provided JSON object and retrieves its value, converting it to a properly formatted text string. The procedure handles field name validation, checking for empty field names and returning appropriate defaults. When a matching field is found, the value is processed through the getStringFromJsonToken helper function to ensure proper formatting, including handling of quotes, escape characters, and null values. This is particularly useful for extracting specific data elements from JSON responses, parsing API results, processing configuration data, and retrieving individual field values from complex JSON structures in integration scenarios. The procedure provides safe field access with fallback handling for missing or invalid field names.

procedure getFieldValueAsText(fieldName: Text[50]; fieldsJsonObject: JsonObject): Text

Parameters:

  • fieldName: Name of the field to search for and extract from the JSON object, limited to 50 characters.
  • fieldsJsonObject: JSON object containing the field data to search within for the specified field name.

Returns: Formatted text value of the specified field, or empty string if field is not found or field name is empty.

getStringFromJsonToken(JsonToken) : Text#

Summary: Converts a JSON token to a properly formatted text string with appropriate character handling and cleanup. This procedure performs comprehensive formatting of JSON token values, ensuring they are suitable for display and processing in Business Central. It validates that the token contains a value, formats the content as text, and performs several cleanup operations including escape character handling, quote normalization, and newline conversion. The procedure handles null values appropriately by returning empty strings, replaces escaped quotes with normal quotes for readability, converts newlines to spaces for single-line display, and removes surrounding quotes that are typically present in JSON string values. This formatting ensures that JSON data can be safely used in Business Central fields, reports, and user interfaces while maintaining data integrity and proper character encoding for integration scenarios.

procedure getStringFromJsonToken(jsonToken: JsonToken): Text

Parameters:

  • jsonToken: JSON token containing the value to be converted and formatted as text with proper character handling.

Returns: Formatted text string with cleaned characters, or empty string if token is invalid, empty, or null.