Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

252
Vistas
How to download a json file which is coming from odata service in sapui5?

I need to download a JSON file from OData service by pressing a button in SAPUI5. For example, the path is "/abcd()" and the file is a base 64-encoded JSON. I'd really appreciate it if anyone could let me know how to consume it and download it as a plain text/JSON format. Thanks in advance. Please help.

I am trying to do like:

For XML:

<form:SimpleForm layout="ResponsiveGridLayout"
            width="30rem"
            editable="true"
            visible="{model>/download}">
            <form:toolbar>
                <Toolbar>
                    <Title id="idTitle"
                        text="{i18n>title}" />
                </Toolbar>
            </form:toolbar>
            <Button id="idDownload"
                text="Download"
                press="onDataDownload" />
        </form:SimpleForm>

For JS:

onDataDownload: function () {
            return model.getInstance().getOdataWrapper().getEntitySet({
                path: "/abcd"
            }).then((res) => {
                const blob = new Blob([res], { type: "application/json" });
                if (window.navigator.msSaveOrOpenBlob) {
                    window.navigator.msSaveBlob(blob, "filename");
                } else {
                    const ele = window.document.createElement("a");
                    ele.href = window.URL.createObjectURL(blob);
                    ele.download = "filename";
                    document.body.appendChild(ele);
                    ele.click();
                    document.body.removeChild(ele);
                }
            });
       }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I've solved this issue.

onDataDownload: function () {
            //call the function
            let obj = model.getInstance().getModelService().bindContext("/abcd(...)", undefined, {
                $$updateGroupId: "anyName"
            });

            obj.execute("anyName").then(function () {
                var encoded = obj.getBoundContext().getObject().value;
                var decoded = atob(encoded);
                const blob = new Blob([decoded], { type: "application/json" });

                if (window.navigator.msSaveOrOpenBlob) {
                    window.navigator.msSaveBlob(blob, "ABCD.json");
                    
                } else {
                    const ele = window.document.createElement("a");
                    ele.href = window.URL.createObjectURL(blob);
                    ele.download = "ABCD.json";
                    document.body.appendChild(ele);
                    ele.click();
                    document.body.removeChild(ele);
                    
                }
    
            });
            model.getInstance().getModelService().submitBatch("anyName");
        }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda