简体   繁体   中英

XPages REST Service's “keys” property - how to use dynamic value

I have a REST service that uses a categorized view. I am trying to get the "keys" property to work with a non-hardcoded value. I get the "Sorry, an error occurred" message when I try to use any Javascript.

This is the only way it works:

<xe:restService id="rsVictims" pathInfo="gridDataVictims">
    <xe:this.service>
        <xe:viewItemFileService defaultColumns="true"
            viewName="InvoiceMPRVictims" contentType="application/json"
            keys="k28ts71zrjsw">
            <xe:this.databaseName><![CDATA[#{javascript:applicationScope.get("appConfig").keywords.appDataStore.join("!!")}]]></xe:this.databaseName>
        </xe:viewItemFileService>
    </xe:this.service>
</xe:restService>

I have tried returning a value with SSJS:

    <xe:restService id="rsVictims" pathInfo="gridDataVictims">
        <xe:this.service>
            <xe:viewItemFileService defaultColumns="true"
                viewName="InvoiceMPRVictims" contentType="application/json">
                <xe:this.databaseName><![CDATA[#{javascript:applicationScope.get("appConfig").keywords.appDataStore.join("!!")}]]></xe:this.databaseName>
                <xe:this.keys><![CDATA[#{javascript:var doc:NotesDocument = currentDocument.getDocument();
var keyValue = doc.getItemValueString("grantID");
return keyValue;}]]></xe:this.keys>
            </xe:viewItemFileService>
        </xe:this.service>
    </xe:restService>

I have also tried moving that SSJS into a function and calling that:

<xe:restService id="rsVictims" pathInfo="gridDataVictims">
    <xe:this.service>
        <xe:viewItemFileService defaultColumns="true"
            viewName="InvoiceMPRVictims" contentType="application/json"
            keys="#{javascript:getMPRRESTKey();}">
            <xe:this.databaseName><![CDATA[#{javascript:applicationScope.get("appConfig").keywords.appDataStore.join("!!")}]]></xe:this.databaseName>
        </xe:viewItemFileService>
    </xe:this.service>
</xe:restService>

Here is the getMPRRESTKey() function:

function getMPRRESTKey() {  
    var doc:NotesDocument = currentDocument.getDocument();
    var keyValue = doc.getItemValueString("grantID");
    return keyValue;
}

The only way it works is to "hardcode" a value in the keys property.

Any help would be great on this!

Thanks!

我的答案(感谢Steve Zavocki)是将viewScope变量传递给keys属性:

<xe:this.keys><![CDATA[#{javascript:viewScope.get("myKeysValue");}]]></xe:this.keys>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM