Expand my Community achievements bar.

SOLVED

AEM Forms drop-down list localization

Avatar

Level 2

I am binding a drop-down list to an Entity in MS Dynamics. The data is just reference look-up data. I need to fetch either the English or French data from the Entity based on the language the user selects in the User Interface. e.g. list of countries in either English or French

In the Forms editor, when binding a drop-down list to REST endpoint, the Display Value must be selected from the list of available fields from the endpoint. This basically hard-codes the returned values to just a single language.

How can I set the Display Value based on the the language the user selects in the User Interface [not the browser language setting]?

1 Accepted Solution

Avatar

Correct answer by
Level 2

Here is the final code hat works in the drop-down list initialization:

------------------------------------------------------------------------------------------

var operationInfo = {

    "formDataModelId": "/content/dam/formsanddocuments-fdm/ms-dynamics-fdm",

    "operationTitle": "GET salutation /salutations",

    "operationName": "GET salutation /salutations_15592508761020"

};

var inputs = {

};

var outputs;

var str = window.location.href.toLowerCase();

var matches = str.match(/afacceptlang=([^&]*)/); // extract query string parameter

if ( (matches !== null) && ( matches[1].toLowerCase() == 'fr'  ) ) {

  console.log('FRENCH');

  outputs={

      savedValue:'salutationid',

      displayedValue:'namefra',

      field:this

  }; 

}

else { // default language

console.log('ENGLISH');

  outputs={

      savedValue:'salutationid',

      displayedValue:'name',

      field:this

  }; 

}

guidelib.dataIntegrationUtils.setOptionsFromService(operationInfo, inputs, outputs);

------------------------------------------------------------------------------------------

View solution in original post

4 Replies

Avatar

Employee Advisor

Hi,

Do you need to make 2 different calls to get the different language list?

Avatar

Level 2

I use the Visual Editor to bind the list once.

Seems like the below should work in the Code Editor data-binding

if(languageParameter='en') {

var operationInfo = {

    "formDataModelId": "/content/dam/formsanddocuments-fdm/ms-dynamics-fdm",

    "operationTitle": "GET salutation /salutations",

    "operationName": "GET salutation /salutations_15592508761020"

};

var inputs = {

};

var outputs={

    savedValue:'salutationid',

    displayedValue:'name_en',

    field:this

};

guidelib.dataIntegrationUtils.setOptionsFromService(operationInfo, inputs, outputs);

}

else {

var operationInfo = {

    "formDataModelId": "/content/dam/formsanddocuments-fdm/ms-dynamics-fdm",

    "operationTitle": "GET salutation /salutations",

    "operationName": "GET salutation /salutations_15592508761020"

};

var inputs = {

};

var outputs={

    savedValue:'salutationid',

    displayedValue:'name_fr',

    field:this

};

guidelib.dataIntegrationUtils.setOptionsFromService(operationInfo, inputs, outputs);

}

Avatar

Employee Advisor

Yes, the approach you are using is fine. Just place the script on the value-commit of the language field.

Avatar

Correct answer by
Level 2

Here is the final code hat works in the drop-down list initialization:

------------------------------------------------------------------------------------------

var operationInfo = {

    "formDataModelId": "/content/dam/formsanddocuments-fdm/ms-dynamics-fdm",

    "operationTitle": "GET salutation /salutations",

    "operationName": "GET salutation /salutations_15592508761020"

};

var inputs = {

};

var outputs;

var str = window.location.href.toLowerCase();

var matches = str.match(/afacceptlang=([^&]*)/); // extract query string parameter

if ( (matches !== null) && ( matches[1].toLowerCase() == 'fr'  ) ) {

  console.log('FRENCH');

  outputs={

      savedValue:'salutationid',

      displayedValue:'namefra',

      field:this

  }; 

}

else { // default language

console.log('ENGLISH');

  outputs={

      savedValue:'salutationid',

      displayedValue:'name',

      field:this

  }; 

}

guidelib.dataIntegrationUtils.setOptionsFromService(operationInfo, inputs, outputs);

------------------------------------------------------------------------------------------