Skip to main content



No record found.

Dynamics 365 Community / Forums / Commerce forum / Select Control doesn...
Commerce forum

Select Control doesn't populate - View Extension (MPOS)

Posted on by 110

Hello everyone,

I'm new to customizing the MPOS (D365 Commerce) and I'm trying to fill the "Select" control with data from the database. I have validated that my controller (Api) returns the required information, however it is not reflected in the view (Cart).

import {
} from "PosApi/Extend/Views/CartView";

import {
} from "PosApi/TypeExtensions";

import { ProxyEntities, ClientEntities } from "PosApi/Entities";
import { TipoComprobanteApiPE } from "../../DataService/DataServiceRequests.g";
import { Entities } from "../../DataService/DataServiceEntities.g";
import MessageDialog from "../../DialogSample/MessageDialog";

export default class SalesCustomControl extends CartViewCustomControlBase {

private _cart: Observable<ProxyEntities.Cart>;
public documentTypeIdPE: Observable<string>;

public documentTypeListPE: ObservableArray<Entities.TipoComprobantePEEntity>;

private _context: ICartViewCustomControlContext;
private _state: ICartViewCustomControlState;

private static readonly TEMPLATE_ID: string = "Microsoft_Pos_Extensibility_Samples_Sales";
public readonly documentTypePELabel: string;

constructor(id: string, context: ICartViewCustomControlContext) {
super(id, context);

/* Start fixed values*/
let tp1: Entities.TipoComprobantePEEntity = new Entities.TipoComprobantePEEntity();
tp1.TipoComprobanteId = "-";
tp1.TipoComprobante = "--DEFAULT--";

let tp2: Entities.TipoComprobantePEEntity = new Entities.TipoComprobantePEEntity();
tp2.TipoComprobanteId = "01";
tp2.TipoComprobante = "INVOICE";
/* End fixed values*/

this._context = context;

this.documentTypeIdPE = ko.observable("");

this.documentTypeListPE = ko.observableArray([tp1, tp2]);

this.documentTypePELabel = this._context.resources.getString("string_50");

this._cart = ko.observable(null);

this.cartChangedHandler = (data: CartChangedData) => {



this.documentTypeIdPE.subscribe((newValue: string): void => {

this._addOrUpdateExtensionProperty("DOCUMENTTYPEID", <ProxyEntities.CommercePropertyValue>{ StringValue: newValue });



public onReady(element: HTMLElement): void {

ko.applyBindingsToNode(element, {
template: {
name: SalesCustomControl.TEMPLATE_ID,
data: this


public init(state: ICartViewCustomControlState): void {

this._state = state;

let correlationIdDT: string = this._context.logger.getNewCorrelationId();
let requestTP: TipoComprobanteApiPE.GetTipoComprobanteRequest<TipoComprobanteApiPE.GetTipoComprobanteResponse> = new TipoComprobanteApiPE.GetTipoComprobanteRequest();

.then((result: ClientEntities.ICancelableDataResult<TipoComprobanteApiPE.GetTipoComprobanteResponse>): void => {

if (!(result.canceled || ObjectExtensions.isNullOrUndefined( {

let myResult: Entities.TipoComprobantePEEntity[] = []; Entities.TipoComprobantePEEntity): void => {

//It returns all values that I expect.


.catch((reason: any) => {

this._context.logger.logError(JSON.stringify(reason), correlationIdDT);



* Gets the property value from the property bag, by its key. Optionally creates the property value on the bag, if it does not exist.
private _addOrUpdateExtensionProperty(key: string, newValue: ProxyEntities.CommercePropertyValue): void {

let cart: ProxyEntities.Cart = this._cart();

let extensionProperty: ProxyEntities.CommerceProperty = Commerce.ArrayExtensions.firstOrUndefined(cart.ExtensionProperties, (property: ProxyEntities.CommerceProperty) => {
return property.Key === key;

if (ObjectExtensions.isNullOrUndefined(extensionProperty)) {
let newProperty: ProxyEntities.CommerceProperty = {
Key: key,
Value: newValue

if (ObjectExtensions.isNullOrUndefined(cart.ExtensionProperties)) {
cart.ExtensionProperties = [];


} else {

extensionProperty.Value = newValue;






If I add fixed values to my variable "documentTypeListPE" it shows as I expected.


I will be grateful for the help you can give me.

thanks in advance.

  • RE: Select Control doesn't populate - View Extension (MPOS)

    Thanks for the update - glad to hear you were able to get it going.

  • Adolfome9 Profile Picture
    Adolfome9 110 on at
    RE: Select Control doesn't populate - View Extension (MPOS)

    Hi Shane;

    Thank you for your comment, I have solved it checking log event viewer. In method "_addOrUpdateExtensionProperty" wasn't properly controlled undefined value for cart variable.

  • RE: Select Control doesn't populate - View Extension (MPOS)


    Based on the comment in the code, it looks like you verified that the init() runs and the call to get the data (GetTipoComprobanteRequest) works fine.

    I wonder if the fact that you already populated the dropdown in the constructor (with the two default values) is causing the dropdown to be fixed at just those two values:

           this.documentTypeListPE = ko.observableArray([tp1, tp2]);

    Have you tried leaving the code out and seeing if the code in the init populates the list?

    If you're still having problems, you may want to open a support request to get some assistance.

  • ToddB Profile Picture
    ToddB on at
    RE: Select Control doesn't populate - View Extension (MPOS)

    Hi Adolfo,

    I am checking to see what I can find in regard to this; and will also leave this for the community to reply as well.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans