AEM Forms drop-down list localization

Avatar

Avatar

idekaresearch

Avatar

idekaresearch

idekaresearch

04-11-2019

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]?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

idekaresearch

Avatar

idekaresearch

idekaresearch

04-11-2019

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);

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

Answers (3)

Answers (3)

Avatar

Avatar

Mayank_Gandhi

Employee

Avatar

Mayank_Gandhi

Employee

Mayank_Gandhi
Employee

04-11-2019

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

Avatar

Avatar

idekaresearch

Avatar

idekaresearch

idekaresearch

04-11-2019

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

Avatar

Mayank_Gandhi

Employee

Avatar

Mayank_Gandhi

Employee

Mayank_Gandhi
Employee

04-11-2019

Hi,

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