Call DR from LWC Template

import { LightningElement, track, api } from 'lwc';
import { OmniscriptBaseMixin } from 'vlocity_ins/omniscriptBaseMixin';
import util from "vlocity_ins/utility"; // Update as per your installed App

export default class MyCustomComponent extends OmniscriptBaseMixin(LightningElement) {
    @track DRresponse = []; // This variable will store the DR response, can be an array [] or object {};

    // Define the request for the DataRaptor (DR)
    requestDR = {
        type: "DataRaptor",
        value: {
            bundleName: "YourDataRaptorName", // Replace with your specific DataRaptor name
            inputMap: "{}", // Initialize the inputMap as an empty JSON object
            optionsMap: "{}" // Initialize the optionsMap as an empty JSON object
        }
    };

    // Function to trigger the DataRaptor call
    myFunction() {
        // Generate DR input by populating the inputMap with key-value pairs
        this.requestDR.value.inputMap = JSON.stringify({
            // Create Input key-value pairs here as needed
        });
        
        // Call the DataRaptor using the utility function
        util
        .getDataHandler(JSON.stringify(this.requestDR))
        .then(result => {
            // Parse the DR response and store it in the DRresponse variable
            this.DRresponse = JSON.parse(result);
            
            // You can optionally log the DR response for debugging
            // console.log('DRresponse' + JSON.stringify(result));    
        })
        .catch(error => {
            // Handle any errors that occur during the DR call
            console.log("DRresponse error", JSON.stringify(error));
        });
    }
}

Last updated