remove specific value form Map<String,Object> Object - dictionary

This My code
Map<Strig,Object> map
so inside **map** object having value like this
{id=123, type=V, bn={type=P, value=MCD}, s=[{type=p, dsId=udi, s={type=p, value=SM}, value=55}, {type=P, dsId=psg, s={type=P, value=GPS}, value=11}, {type=P, source={type=P, value=CAMM}, value=10}]}
i want to be reomve some specfic value from this Map so My
desire output should be like this
{id=123, type=V, bn=MCD, s=[{dsId=udi, s={value=SM}, value=55}, { dsId=psg, s={value=GPS}, value=11}, {source={value=CAMM}, value=10}]}
So Map<String,Object> map representation should be above like of code
Here i want to do response optimization so please help me how to do this .

Related

Querring Humio (LogScale)

i'm trying to create this query for Humio and can't figure out the syntax I need.
I want to use the regex() function on fieldA, put its result in a new field RESULT and then look for RESULT inside the text of fieldB.
I tried something like:
regex(regex="...(?<RESULT>...)...", field=fieldA)
| in(field=fieldB, values=[*RESULT*])
but I can only pass free text to the value of the in() function.
How can I pass the value of the new field?

Populating an Apex Map from a SOQL query

// I have a custom metadata object named boatNames__mdt and I'm using two methods to get a list of picklist values in a String[];
First Method
Map<String, boatNames__mdt> mapEd = boatNames__mdt.getAll();
string boatTypes = (string) mapEd.values()[0].BoatPick__c;
// BoatPick__c is a textarea field (Eg: 'Yacht, Sailboat')
string[] btWRAP = new string[]{};
**btWRAP**.addAll(boatTypes.normalizeSpace().split(','));
Second Method
string[] strL = new string[]{};
Schema.DescribeFieldResult dfr = Schema.SObjectType.boatNames__mdt.fields.BoatTypesPicklist__c;
// BoatTypesPicklist__c is a picklist field (Picklist Values: 'Yacht, Sailboat')
PicklistEntry[] picklistValues = dfr.getPicklistValues();
for (PicklistEntry pick : picklistValues){
**strl**.add((string) pick.getLabel());
}
Map with SOQL query
Map<Id, BoatType__c> boatMap = new Map<Id, BoatType__c>
([Select Id, Name from BoatType__c Where Name in :btWRAP]);
When I run the above Map with SOQL query(btWRAP[]) no records show up.
But when I used it using the strl[] records do show up.
I'm stunned!
Can you please explain why two identical String[] when used in exact SOQL queries behave so different?
You are comparing different things so you get different results. Multiple fails here.
mapEd.values()[0].BoatPick__c - this takes 1st element. At random. Are you sure you have only 1 element in there? You might be getting random results, good luck debugging.
normalizeSpace() and trim() - you trim the string but after splitting you don't trim the components. You don't have Sailboat, you have {space}Sailboat
String s = 'Yacht, Sailboat';
List<String> tokens = s.normalizeSpace().split(',');
System.debug(tokens.size()); // "2"
System.debug(tokens); // "(Yacht, Sailboat)", note the extra space
System.debug(tokens[1].charAt(0)); // "32", space's ASCII number
Try splitting by "comma, optionally followed by space/tab/newline/any other whitespace symbol": s.split(',\\s*'); or call normalize in a loop over the split's results?
pick.getLabel() - in code never compare using picklist labels unless you really know what you're doing. Somebody will translate the org to German, French etc and your code will break. Compare to getValue()

How to extract a string value from an array using scripted field in kibana?

Is there a way to extract a string value from an array with the use of if statement in scripted field in kibana. I tried the below code, however, I am unable to filter out the correct and incorrect values in discover tab of kibana. This might be due to remark field is an array.
def result_string = "";
if (doc['nac.keyword'].value =="existing_intent" &&doc['remark.keyword'].value != "acceptable") {
result_string = "incorrect";
}
if (doc['nac.keyword'].value =="existing_intent" &&doc['remark.keyword'].value == "acceptable") {
result_string = "correct";
}
return result_string;`
You can use the contains method defined on Array to check for element membership:
!doc['remark.keyword'].value.contains("acceptable") //does not contain
For this, you might want to ensure first that doc['remark.keyword'].value is indeed an Array.

How to write Key Value Pairs in Map in a Loop without overwriting them?

the following is my problem:
I do a select on my database and want to write the values of every record i get in a map. When i do this, i only have the values of one record in my map, because the put() function overwrites the entries everytime the loop starts again. Since I have to transfer the Key:Value pairs via JSON into my Javascript and write something into a field for every Key:Value pair, an ArrayList is not an option.
I've already tried to convert a ArrayList, which contains the Map, to a Map or to a String and then to Map, but i failed.
EDIT:
HereĀ“s my Code
def valueArray = new ArrayList();
def recordValues = [:]
while (rs.next())
{
fremdlKorr = rs.getFloatValue(1)
leistungKorr = rs.getFloatValue(2)
materialKorr = rs.getFloatValue(3)
strid = rs.getStringValue(4)
recordValues.put("strid", strid);
recordValues.put("material", materialKorr);
recordValues.put("fremdl", fremdlKorr);
recordValues.put("leistung", leistungKorr);
valueArray.add(korrekturWerte);
}
The ArrayList was just a test, i dont want to have an ArrayList, i need a Map.
The code as written, will give you a list of maps, but the maps will all contain the values of the last row. The reaons is the def recordValues = [:] that is outside of the while loop. So you basically add always the same map to the list and the map values get overwritten each loop.
While moving the code, would fix the problem, I'd use Sql instead. That all boils down to:
def valueArray = sql.rows("select strid, material, fremdl, leistung from ...")

How to convert a String into the property name of an object in Flex

I need to get the value of the item clicked and the name of the columns.
for each(item in colunas) {
var itemok:String = item.dataField;
Alert.show(''+datagridlist.selectedItem.itemok); // show value of column
}
But this way it returns 'undefined'.
But if I put the name already in function, I can get the correct data, example:
Alert.show(''+datagridlist.selectedItem.create); // create is a column name in mysql
But this variable must be created dynamically, example:
var itemok:String = item.dataField;
Alert.show(''+datagridlist.selectedItem.itemok); // show value of column
Could someone help me? I'm at it on time and I can not convert the string to column name.
I thank you all now
for each(item in colunas)
{
var itemok:String = item.dataField;
Alert.show(''+datagridlist.selectedItem[itemok]);
}
The dot syntax to access properties/fields works only with property names. When the property name is stored in a string, use square brackets.
var t:String = "value";
//The following three lines are the same and will work
trace(something.value);
trace(something["value"]);
trace(something[t]);
//but this one won't
trace(something.t);

Resources