moqui / moqui-framework

Use Moqui Framework to build enterprise applications based on Java. It includes tools for databases (relational, graph, document), local and web services, web and other UI with screens and forms, security, file/resource access, scripts, templates, l10n, caching, logging, search, rules, workflow, multi-instance, and integration.
http://www.moqui.org
Other
279 stars 200 forks source link

'select-field' not work on entity-find with REST screen transition #427

Closed hansbak closed 4 years ago

hansbak commented 4 years ago

when i implement a REST interface taking advantage if the JSON in/output by using the screen file with a transition, i need to be able to select the fields required, because often too many fields are supplied......

my screen file:

<screen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/xml-screen-2.1.xsd"
        require-authentication="false" track-artifact-hit="false" default-menu-include="false">

        <transition name="testing" method="get" begin-transaction="false">
            <service-call name="servicefile.getCurrencyList"
            web-send-json-response="true"/>
            <default-response type="none"/>
        </transition>
        <widgets><!-- this should never be viewed... --></widgets>
</screen>

my services file:

<service verb="get" noun="CurrencyList" authenticate="anonymous-all">
        <description>
            Get currency list for registration.
        </description>
        <out-parameters>
            <parameter name="currencyList" type="List"/>
        </out-parameters>
        <actions>
            <entity-find entity-name="moqui.basic.Uom" list="currencyList">
                <econdition field-name="uomTypeEnumId" value="UT_CURRENCY_MEASURE"/>
                <select-field field-name="abbreviation"/>
            </entity-find>
        </actions>
    </service>

the shortened output:

{
  "currencyList" : [ {
    "description" : "Bitcoin",
    "uomId" : "BTC",
    "lastUpdatedStamp" : 1594365110959,
    "abbreviation" : "BTC",
    "uomTypeEnumId" : "UT_CURRENCY_MEASURE"
  }, {
    "abbreviation" : "CRC",
    "uomId" : "CRC",
    "description" : "Costa Rica Colon",
    "lastUpdatedStamp" : 1594365110959,
    "uomTypeEnumId" : "UT_CURRENCY_MEASURE"
  }, {
    "abbreviation" : "COP",
...................

Regards Hans

jonesde commented 4 years ago

That's because it's coming from the cache and cached queries always select all fields from the database otherwise a different cache entry in memory would be needed for every combination of selected fields. Usually this doesn't matter because when doing cached finds you want all fields anyway.

If you really want the entity facade to limit the results then use cache="false" but then you'll also always be hitting the database. For runtime performance and DB load better to transform/filter the data yourself.

On Thu, Jul 16, 2020 at 1:11 AM Hans Bakker notifications@github.com wrote:

when i implement a REST interface taking advantage if the JSON in/output by using the screen file with a transition, i need to be able to select the fields required, because often too many fields are supplied......

my screen file:

<screen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/xml-screen-2.1.xsd" require-authentication="false" track-artifact-hit="false" default-menu-include="false">

    <transition name="testing" method="get" begin-transaction="false">
        <service-call name="servicefile.getCurrencyList"
        web-send-json-response="true"/>
        <default-response type="none"/>
    </transition>
    <widgets><!-- this should never be viewed... --></widgets>

my services file:

Get currency list for registration.

the shortened output:

{ "currencyList" : [ { "description" : "Bitcoin", "uomId" : "BTC", "lastUpdatedStamp" : 1594365110959, "abbreviation" : "BTC", "uomTypeEnumId" : "UT_CURRENCY_MEASURE" }, { "abbreviation" : "CRC", "uomId" : "CRC", "description" : "Costa Rica Colon", "lastUpdatedStamp" : 1594365110959, "uomTypeEnumId" : "UT_CURRENCY_MEASURE" }, { "abbreviation" : "COP", ...................

Regards Hans

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/moqui/moqui-framework/issues/427, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFEVUJ6GRU2I5RK6F722TTR32YZVANCNFSM4O3ZCKOQ .

hansbak commented 4 years ago

Thanks for your quick reply. However that fact (caching) makes this method using transactions uninteresting. Currently i am using jsonslurp on input and the creation json on output myself using the REST resources calling of services. Regards, Hans