Announcements
str2Enum(enumType,enumvalue)
Hi Martin,
I did try to mark your suggestion as verified but I am getting error as "I dont have permission to update this reply"
If it answered you question, please use Did this answer your question? > Yes on the reply to verify it.
Hi Martin,
Thanks you much for your help..
Your solution made our day :)
If I understand it correctly, you have a table name, a field name and a string with the element name of an enum. And you want to get the numeric value of the enum element.
The first thing to do is finding which enum is used by the field:
SysDictField df = SysDictField::findFieldByName('HcmPersonPrivateDetails', 'Gender'); EnumId enumId = df.enumId();
With this knowledge, you can use SysDictEnum class to convert the symbol to a value:
SysDictEnum dictEnum = new SysDictEnum(enumId); int value = dictEnum.symbol2Value('Male');
public static void runBulkUpdate() { MaskedValueConfiguration maskedvalConfig; Query queryBase = new Query(); Query queryRecord = new Query(); QueryBuildDataSource qbds; QueryBuildRange qbrRecord; QueryRun queryRun; qbds = queryBase.addDataSource(tableNum(MaskedValueConfiguration)); queryRun = new QueryRun(queryBase); while(queryRun.next()) { DictTable dictTable; Query qr = new Query(); QueryBuildDataSource qbdsDocuParm; QueryRun qRun; DocuParameters docParm; Common commonBuffer; maskedvalConfig = queryRun.get(tableNum(MaskedValueConfiguration)); dictTable = new DictTable(tablename2id(maskedvalConfig.TableName)); qbdsDocuParm = qr.addDataSource(tablename2id(maskedvalConfig.TableName)); qbdsDocuParm.addRange(fieldName2Id(tablename2id(maskedvalConfig.TableName),"DataAreaId")).value(curExt()); qRun = new QueryRun(qr); commonBuffer = dictTable.makeRecord(); commonBuffer.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction); select * from commonBuffer; var uo = new SysDaUpdateObject(commonBuffer); uo.settingClause().add(maskedvalConfig.DataFieldName, new SysDaValueExpression(maskedvalConfig.DataFieldMaskedValue)); ttsbegin; new SysDaUpdateStatement().execute(uo); ttscommit; } }
This is one of the scenario we are having problems with updating fields based of Enum.
Please see our code as pasted above.
Here the common buffer would have the table to which we want to perform bulk update. In our case (HcmPersonPrivateDetails)
And our target field to be updated in this is (Gender) based out of enum (HcmPersonGender).
SO the syntax would be like as follows:
uo.settingClause().add(maskedvalConfig.DataFieldName, new SysDaValueExpression(maskedvalConfig.DataFieldMaskedValue));
now the SysDaValueExpression would be (SysDaValueExpression(maskedvalConfig."Male")) // Pass enum (MALE) as string
Now our actual problem is we cannot pass hardcode the enum type as it could be any thing or any type in real implementation.
Hence we required your suggestion here how can we achieve this ?
All right, so the type is string. What is the value. Can you give us a concrete example, please?
Hi Martin,
The value in maskedValConfig.DataFieldMaskedValue is a string.
I mean if the field is based of an enum then since we can't pass it as the same type we are passing it as a string value.
Because our custom table field is a string field.
hence we tried to use the global conversion str2Enum,however we could not as we cannot pass the enum type dynamically..
Please suggest if there is any possibility to achieve this.
Hi Martin,
It will have a string value.
I mean if a field is based of an enum lets say "HcmPersonGender" then the maskedValConfig.DataFieldMaskedValue would have "Male","Female" as string. And this is where we are having problem that no value is being saved in such case.
And hence we tried the conversion str2Enum() but unfortunately we could not as was unable to pass the enum type dynamically
could you please provide some suggestion here?
Hi Martin,
If the field is based of an Enum.
Lets say if its based of "HcmPersonGender" then we are passing value either "Male" or "Female".
As you see we are passing the values as string thought the field is based of an enum and that's where we tried to use str2Enum() but we hanged with enum type as we cannot pass it dynamically..
What value do you have in your maskedvalConfig.DataFieldMaskedValue variable?
André Arnaud de Cal...
293,304
Super User 2025 Season 1
Martin Dráb
232,149
Most Valuable Professional
nmaenpaa
101,156
Moderator