Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

Enumeration in webapps

Avatar

Level 3

A webapp Page (v5 compatibility), Combo box input -> advanced settings Initialization: "Automatic via an enumeration" suggest we can use enumerations defined outside the webapp to populate a select element in our webpage's HTML.

 

Elements in schemas can use enumerations defined in the schema using attribute
enum="enumName"

 

Or, enum defined in different schema
enum="cus:schemaName:enumName"

 

Or, using a database enum
dbEnum="enumName"

 

However the settings for the combo box have a field "Enumeration Xpath", and however I write the reference to my enum, the select-element remains unpopulated.

 

The enum is of type system, and is working in inputforms using dbEnum="enumName" attribute. Can anyone share some light on how this is supposed to work, please?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello,

I agree this is a bit confusing.... But if we give a look a little closer, with the builtin webapps (for example 'deliveryOverview', 'webAppOverview' etc. by filtering webApp with "XML memo (data) contains 'contextOptions useContext="2" '), the answer is : the xpath refer to an attribute of the document schema ("Document type" defined into the General properties of the webapp) that use a enumeration.

For example, if you choose "nms:delivery" for your webapp document type, you can put "@state" into the xpath to populate the options with the nms:delivery:deliveryState enumeration values.

It's not impossible that you could use webapp context enumeration maybe ? If I see something I'll give you more precisions.


Cedric

View solution in original post

11 Replies

Avatar

Correct answer by
Community Advisor

Hello,

I agree this is a bit confusing.... But if we give a look a little closer, with the builtin webapps (for example 'deliveryOverview', 'webAppOverview' etc. by filtering webApp with "XML memo (data) contains 'contextOptions useContext="2" '), the answer is : the xpath refer to an attribute of the document schema ("Document type" defined into the General properties of the webapp) that use a enumeration.

For example, if you choose "nms:delivery" for your webapp document type, you can put "@state" into the xpath to populate the options with the nms:delivery:deliveryState enumeration values.

It's not impossible that you could use webapp context enumeration maybe ? If I see something I'll give you more precisions.


Cedric

Avatar

Community Advisor
Ok, I didn't noticed that if you need more flexibility, you can load custom values (for example into a script just before the page) and use the context 'ctx' to populate your list : choose the second options "from context" instead of "Automatic via an enumeration". Then you'll have to give the path of your xml list from the ctx (var ctx.mylist = <mylist><value myLabel="xxx" myValue="xxx"/><...></mylist>, just give "[mylist/value]" as options xpath, @myLabel for label xpath and @myValue for xpath value). By this way, you can load another enumeration from anywhere (schemas enums, xtk:enum etc.) to populate your input.

Avatar

Level 3
Unfortunately, I do not have the default apps you refer to, et least I do not find them when setting a webapp folder to ("folder is a view"). As you suggest I load the enumerations defined in a schema in a script object before the page, and then initiate the combobox "via the context". This works fine for enumerations defined in the schema, but not for enumerations stored in the database. The idea for the client is to have a separate "product" emnumeration they can syncronise with another system without involving editing of schemas. When I try to load the enumeration using

Avatar

Level 3
When I try to load the enumeration using ctx.enumTest = xtk.enum.load(pirmaryKey).toSource() all I get is <enumTest>({})</enumTest>

Avatar

Level 3

If anyone else sees this looking for assistance, you can use a javscript object to get all enumerations defined in a schema into ctx like this:

var schema = application.getSchema("cus:schemaName")
for each(var e in schema.enumerations)
{
var enum = eval("<enum_"+ e.label+ "/>");
var options = <options/>;
for each(var item in e.values){
options.appendChild(<option label={item.label} value={item.value} />)
}
enum.options = options.option
ctx.enum = enum
}

Avatar

Community Advisor
Instead of "toSource()", can you try to use "toXML()" ? But also, I'm not sure of what it loads, I'm affraid that xtk:enumValue are not loaded. I'll check and tell you, but I pretty sure that's possible.

Avatar

Level 3
.toXML() outputs the enumeration attributes, but as you suggested not the enumValues

Avatar

Level 3
I was hoping there were some well defined functionality using the option "Automatic via an Enumeration" which suggest it does just what im looking for;)

Avatar

Community Advisor

Here it is :

JS Script :

var enumId = 123456789 //xtk:enum ID

var domainsQuery = NLWS.xtkQueryDef.create({
  queryDef : {
    schema : "xtk:enumValue",
    operation : "select",
    select : {
      node : [
        {expr:"@label"},
        {expr:"@name"}
        ]
    },
    where : {
      condition : [
        {expr : "[@enum-id] = " + enumId }
      ]
    }  
   }
});
ctx.domains = new XML( domainsQuery.ExecuteQuery().toXMLString() );

Parameters init context :

Init : From context,

options XPath : [enumValue-collection/enumValue]

label XPath : @label

values XPath : @name

 

You can change the xptah using aliases into the query.

Cedric

Avatar

Level 3
Ah, I see. That woks perfect. Thank you very much for your assistance.

Avatar

Community Advisor

You're welcome. Also, if you need to load more than one enum, the code is incomplete (because each query will have the same element name "enumValue-collection". If needed :

myResult1 = new XML( domainsQuery.ExecuteQuery().toXMLString() );
myResult1.setName('myResult1'); //this is the real root element name to give to the "options Xptah" instead of "enumValue-collection" as I did before
ctx.myValues1 = myResult1;

... another query...
myResult2 = new XML( anotherQuery.ExecuteQuery().toXMLString() );
myResult2.setName('myResult2') 
ctx.myValues2 = myResult2;
Etc.

 

Then use options XPath : [myResult1/enumValue], [myResult2/enumValue] etc.

Cedric