AnsweredAssumed Answered

Getting a promise from layers-add-result event

Question asked by ndilekli on Mar 15, 2018
Latest reply on Mar 22, 2018 by rscheitlin

I need to access the username promise from the layers-add-result event, but it is ignored. I think I can illustrate it best in code.

function init() {
     require([], function() {

        On(map, 'load', mapLoaded);

        function mapLoaded() {
            getUserName().then(function (res) {
                // This part is executed
            });
        }

        On(map, 'layers-add-result', initMapLayerData);

        function initMapLayerData(evt) {
            // This part is executed

            getUserName().then(function (res) {
                // This part is NOT executed
            });
        }
    });

}

function getUserName() {
     return new Promise(function (resolve, reject) {
          require(["esri/IdentityManager"], function (esriId) {
               esriId.on("credential-create", function (e) {
                    var userName = e.credential.userId;
                    resolve(userName);
               });
          });
     });
}

What am I doing wrong? How do I access the user id from the layers-add-result event?

 

Thanks

Outcomes