0

What is wrong with my code? privateConfigurationPromise return always "pending". I have to wait for the multiretrieve result before reading. I can not figure out what is wrong. I also tried with a timer but the answer is always "pending". Explain to me what I'm doing wrong.

    function isEmpty(obj) {
            if (obj == null) return true;

            if (obj.length > 0)    return false;
            if (obj.length === 0)  return true;

            if (typeof obj !== "object") return true;

            for (var key in obj) {
                if (hasOwnProperty.call(obj, key)) return false;
            }

            return true;
        }

    function retrieveMultipleWithPromise() {
        var entityName = "privateconfiguration";
        var fieldValue = "value";
        var fieldName = "name";
        var fieldNameBaseValue = "pc_mvc_base";
        var fieldNameControllerValue = "pc_mvc_books";
        var option = "$select=" + fieldValue + "&$filter=" + fieldName + " eq '" + fieldNameBaseValue + "' or " + fieldName + " eq '" + fieldNameControllerValue + "'";

        return new Promise(function (resolve, reject) {
            var result = SDK.REST.retrieveMultipleRecords(
                entityName,
                option,
                function (result) {
                },
                function (error) {
                    errorHandler(error);
                },
                function () {
                }
            );
            if(!(isEmpty(result))){
                resolve(result);
            }
            else{
                reject(result);
            }
        });
    }

    var iframe = Xrm.Page.getControl("IFRAME_MVCApp");
    //retrieve delle due private conf.
    var privateConfigurationPromise = retrieveMultipleWithPromise()
        .then(result => result.map(function (item) { return item.ava_value; }).join(""))
        .catch(error => console.log(error));

};
  • What is `SDK.REST`? – Bergi Aug 01 '18 at 15:04
  • [You must resolve/reject the promise from the asynchronous callbacks.](https://stackoverflow.com/q/22519784/1048572) It probably should look like `return new Promise((resolve, reject) => { SDK.REST.retrieveMultipleRecords( entityName, option, resolve, reject, () => {}); });` – Bergi Aug 01 '18 at 15:05
  • @Bergi SDK.Rest is a js SDK from Microsoft for rest call. With the correction proposed by you, get the same result – Enrico Meloni Aug 01 '18 at 15:49
  • Regarding "*privateConfigurationPromise return always "pending".*" - how are you using it? – Bergi Aug 01 '18 at 16:01
  • the retrieveMultiple gives me back two fields, concatenated then, they will compose a URL, which I will use to unseal a webapp in an iframe – Enrico Meloni Aug 01 '18 at 19:28
  • Can you post that code as well, especially the place where you get "pending" - do you log anything? – Bergi Aug 01 '18 at 20:06
  • The code is already present, it's the one below. No log is generated. In console privateConfigurationPromise value is Promise – Enrico Meloni Aug 02 '18 at 07:14
  • The code you posted just creates `privateConfigurationPromise`, it doesn't use it. What are you trying to do with the retrieved records? – Bergi Aug 02 '18 at 09:06
  • Can You post an example of Promise with JQuery? – Enrico Meloni Aug 02 '18 at 12:06
  • What does jQuery have to do with this? And unless you link the docs of that `SDK.REST` thing, I can't tell you how to properly promisify it. – Bergi Aug 02 '18 at 12:52

0 Answers0