cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving the code data type of a codelist given the correspoding description C4C SDK

Former Member
0 Kudos

Hi Experts,
I defined a code list data type using a business configuration object with the fields below:

and the field values are 139 items/cities:

Now what I am trying to do in ABSL script is to get the "Type code for City"(the 3 digit number) given the "Name of City"(the Description), however the only way I can think of is to have 139 if-else statements or 139 switch-case condition like the code below, is there other way I can implement this, I saw one using querybyelements but I dont know how to code/implement it, hope you can show me how to code/implement this using query by elements.

var code;<br>if (Name of City == "Angeles") {<br>    code = "001";
} else if (Name of City == "Antipolo") {
    code = "002";
} else if (Name of City == "Bacolod") {
    code = "003";
} else if .....

Accepted Solutions (1)

Accepted Solutions (1)

former_member592782
Active Participant
0 Kudos

Hi Lenorsi,

As you mentioned you can use the QueryByElements to Query the BCO

For example:

var QueryBCO=CitiesBCO.QueryByElements;
var SelParams=QueryBCO.CreateSelectionParams();
SelParams.Add(QueryBCO.CitiesBCOCode.content,"I","EQ",001);
var ResultsSelection=QueryBCO.Execute(SelParams); //Here you can filter by the selection parameters
var Results=QueryBCO.Execute(); //Here you retrieve all the Cities (Values) from the BC Set.

Thanks,

Piotr.

Former Member
0 Kudos

Hi Piotr,

Thank you for answering.

What I need is to have the "Code" (001, 002, 003, 004.....) given the Value/Description ("Angeles", "Antipolo", "Bacolod", ... ), what you gave is the other way around. As an example, lets say I have

var value = "Angeles";

how do I get its corresponding "Code" which is 001

former_member592782
Active Participant
0 Kudos

Hi Lenorsi,

To do that you just apply the reverse logic i.e

SelParams.Add(QueryBCO.CONTENT.content,"I","EQ","Angeles"); //Here we are using CONTENT instead of CODE.
var ResultsSelection=QueryBCO.Execute(SelParams);
var CityCode=ResultsSelection.GetFirst().NAME.Content;//Here we are accessing the Query results and assigning the corresponding code(001) to the CityCode variable.

If this answers your question please mark the Question as Answered,

Thanks,

Piotr.

Answers (0)