Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to integrate XSJS service into OData service

Hello experts!

I have a problem. I want use smart-table on UI. I use OData protocol, but medata doesn't contain all necessary attributes.

I try fix this problem with XSJS, which will add necessary attributes. And then I want to call XSJS from OData.

I have a questions. How can I call XSJS service logic in OData service?

Header function from XSJS:

function metadata(param) {

    var result = processXML(param.metadata, function(name, atts) {

        var EDM = "http://schemas.microsoft.com/ado/2008/09/edm";

        var SAP = "http://www.sap.com/Protocols/SAPData";

        var newAtts = {};

        if (name === EDM + ":Property" && atts.Name === "M1") {

            newAtts[SAP + ":label"] = "The Measure";

        }

        return newAtts;

    });

    return {metadata: result};

}

OData service:

service{

  "blabla::CV_TEXT_OD" as "Product" key ("PRODUCT_ID");

      metadata using "blabla.xs_test:metadata_exit.xsjs::metadata";

}

annotations {

   enable OData4SAP;

}

When I try run OData service its OK. But when I try to get metadata I have an error:

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

<code/>

<message xml:lang="en-US">Invalid script.</message>

</error>

Tags:
replied

Yes this is what I did in my SPS 10 system. My service definition:

service namespace "sap.hana.democontent.epmNext.services" {

  "sap.hana.democontent.epmNext.models::BUYER"

  as "BusinessPartners"

  keys("PARTNERID");

  metadata using "sap.hana.democontent.epmNext.services:businessPartnersAddresses.xsjslib::metadata";

}

annotations {

   enable OData4SAP;

}

And the Exit implementation:

function metadata(param){

// var result = processXML(param.metadata, function(name, atts) {

//        var EDM = "http://schemas.microsoft.com/ado/2008/09/edm";

//        var SAP = "http://www.sap.com/Protocols/SAPData";

//        var newAtts = {};

//        if (name === EDM + ":Property" && atts.Name === "M1") {

//            newAtts[SAP + ":label"] = "The Measure";

//        }

//        return newAtts;

//    });

     return {metadata: param.metadata};

}

That returns the metadata to the browser like normal. I know its calling my metadata function because if I introduce a syntax error into, the error message is what gets returned to the browser.

However here I think you have the core problem of hitting upon an unreleased/undocumented feature: Should it even work in your release, if so how, etc.  I'll repeat my warning now:

However I want to strongly caution you against using this functionality.  As it isn't documented/released, you aren't likely to get official support on it nor is it guaranteed that it would continue to work in the future.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question