Finding enum fields with string value | Community
Skip to main content
Level 3
June 17, 2021
Solved

Finding enum fields with string value

  • June 17, 2021
  • 2 replies
  • 2649 views
We have several enum fields (dropdown to choose from) in several tables having value as string data type. We are wanting to make them numeric for performance reasons. What's the best way to identify all such enum fields?
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by CedricRey

Hello @harshalte 

Can you give a try to this script (for example in a JS workflow activity) please :

var schemaQuery = xtk.queryDef.create(<queryDef operation="select" schema="xtk:schema"><select><node expr="@namespace"/><node expr="@name"/></select></queryDef>); var allSchem = schemaQuery.ExecuteQuery(); for each(var schem in allSchem) { checkEnumFields(schem.@namespace + ":" + schem.@name); } function checkEnumFields( schemaNS ) { var schema = application.getSchema( schemaNS ); var root = schema.root; if(root && root.children ) checkChildren( schemaNS, root.children ); } function checkChildren( name, children ){ for each(var node in children) { if( node.hasEnumeration && node.type == "string" ) logInfo(name + "/" + node.name + " uses enumeration " + node.enumeration.name ); if( node.isElementOnly ) checkChildren( name + "/" + node.name, node.children ); } }

This should log all fields that use enum, with 'string' type, in all your schemas (with recursivity)

 

Let me know if it works.

Cedric

2 replies

CedricRey
CedricReyAccepted solution
Level 5
June 17, 2021

Hello @harshalte 

Can you give a try to this script (for example in a JS workflow activity) please :

var schemaQuery = xtk.queryDef.create(<queryDef operation="select" schema="xtk:schema"><select><node expr="@namespace"/><node expr="@name"/></select></queryDef>); var allSchem = schemaQuery.ExecuteQuery(); for each(var schem in allSchem) { checkEnumFields(schem.@namespace + ":" + schem.@name); } function checkEnumFields( schemaNS ) { var schema = application.getSchema( schemaNS ); var root = schema.root; if(root && root.children ) checkChildren( schemaNS, root.children ); } function checkChildren( name, children ){ for each(var node in children) { if( node.hasEnumeration && node.type == "string" ) logInfo(name + "/" + node.name + " uses enumeration " + node.enumeration.name ); if( node.isElementOnly ) checkChildren( name + "/" + node.name, node.children ); } }

This should log all fields that use enum, with 'string' type, in all your schemas (with recursivity)

 

Let me know if it works.

Cedric

HarshalTeAuthor
Level 3
June 29, 2021
Great Cedric ... that worked well for us.
LaurentLam
Level 5
June 20, 2021

Hello,

First, you do not have to change OOTB enumeration as, in best scenarii, it will complexify maintenance & build upgrade

In data schema views,

You can first filters about all schemas created specifically for the environment (by default, nameSpace is "cus" but it everyone choose its own nameSpace)

You then surfilter on 'mData' / 'Entity content' field using 'contains' operator and 'enum="' string to search
It will provide all the custom schema where you can make a modification 

 

You'll have to change the enumeration setting in the schema but to change also the field where it related to from string to integer... But, don't forget that it will drop the column and create a new one when "updating the database structure"... So be sure to first create your new column, populate its value through a workflow... Change the enum from field A to field B. And once, you're sure, you can delete field A

HarshalTeAuthor
Level 3
June 21, 2021
This certainly looks helpful. I shall try and revert on this.