I’ve got a weird problem with a data processor. Its added as a Request Data Processor to an API function as I need to manipulate the inbound request.
Despite using the code below - the .get() on the 2x choice fields just wont return the saveable value of the choice field - its always returns the DTCxxxxxx value
Don’t think I’m doing anything obviously wrong but apologies for the slightly noddy code 
/**
- Data Processor
- Processes rows of data, typically within imports/exports and API calls/handlers
/
return {
/*
*
-
@param {Object} The raw fields
-
@param {Object} Context details
-
@returns {Object} Processed data
*/
main: function(fields, context) {
let sanction;
cs.log(fields);
//cs.log(context);
let id = fields.p_0;
let status = fields.p_1;
let risk = fields.p_2;
if (status == “” || status == null || status == undefined)
{
cs.log(“Empty Status”);
sanction = cs.record(id); // get the specific sanctions record
let recStatus = sanction.get(cs.ref(“fld_sanctions_check_status”),“saveable”);
fields.p_1 = recStatus ;
}
if (risk == “” || risk == null || risk == undefined)
{
cs.log(“Empty Risk”);
sanction = cs.record(id); // get the specific sanctions record
let recRisk = sanction.get(cs.ref(“fld_sanctions_risk_level”),“saveable”);
fields.p_2 = recRisk;
}
cs.log(fields);
return fields;
}
}
I’ll open by saying CS isn’t my strength, and I mostly just use the built-in data processors, but I think that the DTCxxxxxx is the ‘saveable’ value from the DB perspective - have you tried using Displayable? Or more explicitly for Choice fields perhaps, ‘to_choice_text’? That’d usually transform it into the display text rather than the DB reference…
1 Like
Scott is correct, those are the saveable value (i.e. the underlying actual value saved to the database).
Assuming you are then saving these values in the API Function definition, then that should be fine as long as you haven’t put a field processor on them.
However if you are using a “From choice text” processor on the fields, then you’d need your data processor to fetch the “displayable” value instead.
Either option should be fine I think.
all I really want to do is just get the name associated with a property choice against the object. I dont want its display name as there IS a field processor already in place expecting the name value.
If I was using From Choice Text that would be fine - but the API definition sends in name and NOT display name !!!
Literally all I want is the name value from the choice property … nothing more.
Cant be that hard can it ?
In fact entirely ignore its API context in this case - I should be able to get the name of a choice property of an object I have in context ?
Hi Haydn,
This post may help with your requirement - Get list of interfaces in cs
This is the part that’s relevant.
Filtering to a specific data type
cs.build_choices(‘data_type’, { ‘base_format’ : ‘choice’, ‘data_type_id’ : ‘DTP0000085EFCAE1’ })
data_type_id - the id of the data type ( Example DTP0000085EFCAE1 )
Note that if using a first argument of ‘data_type’, by adding … parameters, the function will return an array of that data_types choices instead of an array of data types.
So you could create a reference to your choice data type and use the following:
cs.build_choices(‘data_type’, { ‘base_format’ : ‘choice’, ‘data_type_id’ : your_ref})
You can also use the more advanced cs.get_component() to get full details of any Data Store items.
In this case to get info about Choice options, including ID, name and display name:
let choices = cs.get_component(cs.ref('my_choice_data_type')).get_choices();
which will return an object like:
{
"DTC0000111GBQGH1": {
"id": "DTC0000111GBQGH1",
"name": "A",
"display_name": "A"
},
"DTC0000112GBQGH1": {
"id": "DTC0000112GBQGH1",
"name": "B",
"display_name": "B"
},
"DTC0000113GBQGH1": {
"id": "DTC0000113GBQGH1",
"name": "C",
"display_name": "C"
}
}
1 Like
Hi Bob,
A combination of the comments above is more or less what I ended up doing in the end. Yours is a bit more elegant than mine so I may well retrofit when time permits.
Feels a bit strange to have to jump through all these hoops just to get the name of a choice property. Feels like there should be a helper of some kind ?
Thanks for all the input everyone - problem resolved for now.
1 Like