Loading

Picklist Translation Issue In Omniscript

Fecha de publicación: Mar 26, 2024
Descripción
When translations are configured for a Picklist using Translation Workbench and the Picklist values are fetched using a DataRaptor, the values are returned are not translated values according to Current Logged in User Language Settings.
Solución

Instead of directly querying for the Value in the DataRaptor, a SOQL query can be used with the toLabel() function in an Apex Class Method, and this method can be called as a Remote Action from the OS, VIP or the DataRaptor. Using toLabel() method returns the translated values of the field according to current logged in user.

Sample Code for Remote Class:

global with sharing class SampleRemoteClass implements PACKAGE_NAMESPACE.VlocityOpenInterface2 {

    global Object invokeMethod(String methodName, Map<String,Object> input, Map<String,Object> output, Map<String,Object> options) {

        // Route to the correct method based on method name
        if (methodName == 'queryCustomLabel') {
            return queryCustomLabel(input);
        }

        // If no valid method found
        output.put('error', 'Invalid method name');
        return output;
    }

    /**
     * Method to query Account with translated picklist using toLabel()
     */
    private Object queryCustomLabel(Map<String,Object> input) {
        String recId;

        // 📌 Case 1: Callout from DataRaptor Formula
        // FUNCTION('SampleRemoteClass','queryCustomLabel', %recordId%)
        if (input.containsKey('arguments')) {
            List<Object> args = (List<Object>) input.get('arguments');
            if (!args.isEmpty()) {
                recId = (String) args[0];
            }
        }
        // 📌 Case 2: Callout from OS/VIP Remote Action
        else if (input.containsKey('recordId')) {
            recId = (String) input.get('recordId');
        }

        // 📌 Sample Query with toLabel() on Picklist field
        List<Account> acc = [
            SELECT Name, toLabel(Type)
            FROM Account
            WHERE Id = :recId
        ];

        output.put('result', acc);
        return output;
    }
}

Número del artículo de conocimiento

000390590

 
Cargando
Salesforce Help | Article