Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

This repo provides samples for apps, solutions, and related services for Dynamics 365. For Dynamics 365 docs, visit <https://docs.microsoft.com/dynamics365>.

## Agent-Specific Real-Time Translation

To support agent-specific real-time translation in Omnichannel for Customer Service, a new field must be added to the `systemuser` entity within the Dataverse. This field will store the ISO 639-1 language code representing the agent's preferred language. The language code should be a two-letter code (e.g., 'de' for German, 'es' for Spanish, etc.).

To enable and configure agent-specific real-time translation, follow these steps:

1. Add a custom field to the `systemuser` entity in the Dataverse to store the ISO 639-1 language code for each agent's preferred language (e.g., 'en' for English, 'de' for German).

2. In the script, locate the `C1WebResourceNamespace` object and find the `agentPreferredLanguageField` property. Replace `'jkalz_preferredlanguagecode'` with the actual schema name of the custom field you added in step 1. This should be a string in single quotes.

3. Set the `enableAgentSpecificTranslation` property to `true` to activate the agent-specific translation feature.

Example configuration in the script:
```javascript
var C1WebResourceNamespace = {
// ... (other properties)

// The actual schema name of the custom field for agent's preferred language
agentPreferredLanguageField: 'your_custom_field_name_here',

// Enable agent-specific translations
enableAgentSpecificTranslation: true,

// ... (rest of the script)
};
```

After configuring these values, the script will use the preferred language settings from each agent's profile to perform translations during customer interactions.
## Related samples repos

- AL language code samples for Dynamics 365 Business Central: <https://github.com/Microsoft/AL>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ var C1WebResourceNamespace = {
useAzureTranslationApis: true,//please override it to false if planning to use google translation v2 api
messageBuffer: new Map(),
enableLanguageDetectionWithHistoryMessages: false,

agentPreferredLanguageField: 'jkalz_preferredlanguagecode', // Replace with the actual field name for agent's preferred language on the systemuser entity
enableAgentSpecificTranslation: false, // Set to true to enable agent specific translations

//ISO 639-1 language code. It is supported by Azure Cognitive Translate API and Google V2 translation API
ISO6391LanguageCodeToOcLanguageCodeMap: {
'gu': ['71', '1095'],
Expand Down Expand Up @@ -241,6 +243,38 @@ var C1WebResourceNamespace = {
conversationConfig,
c1Language
});

const getAgentPreferredLanguage = async () => {
try {
// Get the current user's ID
const userId = window.top.Xrm.Utility.getGlobalContext().userSettings.userId.replace("{", "").replace("}", "");

// Define the entity name and the columns to retrieve
const entityName = "systemuser";

// Define the columns to retrieve, jkalz_preferredlanguagecode is the language preference field
// which should be added to the systemuser entity
const columns = ["fullname", C1WebResourceNamespace.agentPreferredLanguageField];

// Fetch the user's details including their language preference
let userDataResponse = await window.top.Xrm.WebApi.retrieveRecord(entityName, userId, `?$select=${columns.join(',')}`);

let agentPreferredLanguage = userDataResponse[C1WebResourceNamespace.agentPreferredLanguageField];
return agentPreferredLanguage;
} catch (error) {
console.error("Error in fetching agent's preferred language:", error);
return null; // Handle error case appropriately
}
};

// Use the function to get the agent's preferred language, if it's null, then use the default
const agentPreferredLanguage = await getAgentPreferredLanguage();

if (C1WebResourceNamespace.enableAgentSpecificTranslation) {
const agentPreferredLanguage = await getAgentPreferredLanguage();
c1Language = agentPreferredLanguage || c1Language;
}

//error handling if invalid language is found
if (c1Language == "invalid code") {
consoleLogHelper(conversationId, "Invalid c1Language found");
Expand Down