umbraco how to update multiple prevalue programatically - umbraco

I have a member type which has a custom property - lets name it books - of data type checkbox - so multiple choice is possible.
Now I'm trying to update this member programatically with new values for books. In the customxml it comes as cdata, I'm passing a value as
umbraco.cms.businesslogic.member.Member member = umbraco.cms.businesslogic.member.Member.GetMemberFromEmail(email);
member.SetProperty("memberBooks", booksValue);
member.Save();
where 'booksValue' is a string of values seperated with comma - because it's how it appears in the contentXml.
It doesn't work.
The question is - how do I update the member property/ xml with new multiple values?

I have resolved this issue.
Both
member.getProperty(“memberBooks”).Value = booksValue;
and
member.SetProperty("memberBooks", booksValue);
work
I was just passing wrong values.
In the contentXml they display as values but actually I need to update the property with the ids so if the data type is checkbox list and the values are like:
1 - book
2 - booko
3 - booki
then in the contentXml it displays as a list "book,booko,booki" but to update it programatically I had to pass: "1,2,3" to the property.
So it should be:
member.SetProperty("memberBooks", "1,2,3");
instead of:
member.SetProperty("memberBooks", "book,booko,booki");
I hope it helps others with the same problem.

here is what you need to do:
umbraco.cms.businesslogic.member.Member member = umbraco.cms.businesslogic.member.Member.GetMemberFromEmail(email);
member.getProperty(“memberBooks”).Value = booksValue;
member.Save();
I hope this should work. I haven't tried it since long-time but this is how I used it.

Related

ABAP: how to compare three internal tables

I've recently started an apprenticeship and I've received a small project to help checking tables.
The request is that I am supposed to write a report that compares a table to our profit center's standard hierarchy and tells you which entries are the same and which ones are not.
Now, I've only started getting into ABAP and while I've had SQL prior, i'm not exactly good in it. My colleagues are nice but I fear that I'd look like an idiot if I kept asking them how to do this.
What i've done so far is giving the table some records to check in our development system, selecting all records in it and also selecting everything I need from SETLEAF and SETNODE.
SELECT * FROM Y_TABLE
INTO TABLE #DATA(lt_compare).
SELECTION-SCREEN BEGIN OF BLOCK set_leaf.
CONSTANTS:
SET_CLASS TYPE SETLEAF-SETCLASS VALUE '0102',
SUB_CLASS TYPE SETLEAF-SUBCLASS VALUE 'D100'.
PARAMETERS:
lv_pcnr TYPE SETLEAF-VALFROM,
setname TYPE SETLEAF-SETNAME.
SELECTION-SCREEN END OF BLOCK set_leaf.
TYPES:
BEGIN OF lt_ausgabe,
SETCLASS TYPE SETLEAF-SETCLASS,
SUBCLASS TYPE SETLEAF-SUBCLASS,
VALFROM TYPE SETLEAF-VALFROM,
SETNAME TYPE SETLEAF-SETNAME,
END OF lt_ausgabe.
DATA:
gt_setleaf TYPE STANDARD TABLE OF lt_ausgabe,
gt_setnode TYPE STANDARD TABLE OF lt_ausgabe.
SETNODE-SUBSETNAME = SETLEAF-SETNAME.
SETNODE-SETNAME = SETNODE-SUBSETNAME.
FORM build_table_setleaf.
SELECT *
FROM SETLEAF
INTO CORRESPONDING FIELDS OF TABLE #gt_setleaf
WHERE SETCLASS = #set_class AND SUBCLASS = #sub_class AND VALFROM = #lv_pcnr AND SETNAME = #setname.
ENDFORM.
FORM build_table_setnode.
SELECT *
FROM SETNODE
INTO CORRESPONDING FIELDS OF TABLE #gt_setnode
WHERE SETCLASS = #set_class AND SUBCLASS = #sub_class AND SUBSETNAME = #setname.
ENDFORM.
I've changed the table name and the constant values because I don't know how much of them I can share.
Now I want to compare these tables and well, do what the request asked for. But I don't really understand how to do this. The code above may not be the way to solve this at all..
I'm sorry in advance if any of this sounds off, I would ask in my own language if.. my people weren't known for being unhelpful and rude when asking code-related stuff.
Thank you in advance.

How to access map keys through index? Dart

dartques = {'Color':[], 'Fruits':[], 'Hobbies':[]};
How to access the values using index in map?
I need to access only key or value using index.
Just like we do in list
=>list[1]
you can get it like this
var element = dartques.values.elementAt(0);
also for Dart 2.7+ you can write extension function
extension GetByKeyIndex on Map {
elementAt(int index) => this.values.elementAt(index);
}
var element = dartques.elementAt(1);
For accessing the values by index, there are two approaches:
Get Key by index and value using the key:
final key = dartques.keys.elementAt(index);
final value = dartques[key];
Get value by index:
final value = dartques.values.elementAt(index);
You may choose the approach based on how and what data are stored on the map.
For example if your map consists of data in which there are duplicate values, I would recommend using the first approach as it allows you to get key at the index first and then the value so you can know if the value is the wanted one or not.
But if you do not care about duplication and only want to find a value based on Index then you should use the second approach, as it gives you the value directly.
Note: As per this Answer By Genchi Genbutsu, you can also use Extension methods for your convenience.
Important:
Since the default implementation for Map in dart is LinkedHashmap you are in great luck. Otherwise Generic Map is known for not maintaining order in many programming languages.
If this was asked for any other language for which the default was HashMap, it might have been impossible to answer.
You can convert it to two lists using keys and values methods:
var ques = {'Color':['a'], 'Fruits':['b'], 'Hobbies':['c']};
List keys = ques.keys.toList();
List values = ques.values.toList();
print (keys);
print (values);
The output:
[Color, Fruits, Hobbies]
[[a], [b], [c]]
So you can access it normally by using keys[0], for example.

Phalcon Save: Can I update only specified columns if update?

I have a table with this columns:
param_id
val_value
val_flag
date_value
tmp_value
tmp_flag
And I have an array of elements, I always have param_id and date_value, but sometimes i have val columns and other times I have tmp columns.
I use $data->save() because sometimes I need to create a new register in db and other times I need to update the register with param_id and date_value.
The question is: Is there any way to do an insert/update but when is an update, only update tmp columns or val columns? I think a find First is my only option, but maybe there is another way.
Thank you.
[EDIT]
I'm trying with the whitelist but it does not work. Let me explain how the method works: I get a request to a web service, process the xml and generate an array of elements with the information collected, after processing these elements I have an array of elements of the class appropriate to save, but these may be new or existing and may contain tmp or val values, I have tried with this but I still change the values to null.
if ($medida->tipo == 'temporal'){
$whiteList = array('val_value','val_flag');
}else if ($medida->tipo == 'validado'){
$whiteList = array('tmp_value','tmp_flag');
}
$dato->save(null, $whitelist);
I do not have data of the post, I use null instead, I have also tried to use an array with the manual assignment of the data obtaining the same result.
Here are two options that can help you:
1) Use 'whitelist' for the save() method.
$obj->save($this->request->getPost(), ['tmp_1', 'tmp_2']);
More info in the documentation.
2) Use the 'Event Manager'.
The methods beforeCreate() and beforeUpdate() will be useful so you can decide which fields to use.
More info in the documentation.
Also if you really want phalcon phql to update only columns which changed you need to enable dynamic update.

How to update value in angular ui typeahead directive if no matching option is found

I've an array of objects containing title and salary which is used in typeahead directive.
I display department name and get entire object as value.
If none of the options match, I want user entered string to be converted to object still. Is there any way to update that?
This answer is pretty late, but I would just use ng-blur (to trap the end of the users input) along with a variable bound to typeahead-no-results. Then test if the variable is true in the method bound to ng-blur, and, if so, make an object out of the String supplied by the user and push it to your data source. Simple example found here.

Is it possible to assign a new value to a returned pointer?

I have a form that I'm creating and to simplify things, I'm trying to create a form field mapper to an object. As such, I create the following dictionary:
self.fieldPropertyMapper = #{
#(CompanyFieldName):self.company,
#(CompanyFieldDescription):self.company.description,
#(CompanyFieldWebsite):self.company.website,
#(CompanyFieldTwitter):self.company.twitter,
#(CompanyFieldAddress):self.company.address,
#(CompanyFieldAddress2):self.company.address2,
#(CompanyFieldCity):self.company.city,
#(CompanyFieldState):self.company.state,
#(CompanyFieldZipcode):self.company.zipcode,
#(CompanyFieldPhone):self.company.phone
};
The keys here are members of the CompanyFieldType enum.
My goal here is to later in my form to assign a value to the returned pointer. Here's what I mean: when a text field in one of my forms stops editing, I'm looking to set the value. Here's what I'd like to accomplish:
- (void)textFieldDidEndEditing:(UITextField *)textField
{
CompanyFieldType fieldType = [self fieldTypeForTag:textField.tag];
// Set the value of the respective company property
// In theory it would be something like:
// self.fieldPropertyMapper[#(fieldType)] = textField.text;
}
I'm assuming there's a way to assign by reference but I'm forgetting how to do this. (Is it using the & symbol or **?) I don't remember. Help appreciated! If I'm messing up my terminology, feel free to let me know.
You can't do exactly what you want to do. That is to say, there is no pointer magic that will do what you want.
You can get essentially the same effect, though, with key-value coding. Instead of storing the result of accessing the property (e.g. self.company.website), instead you want to just store the key path to the value you're interested in as a string — e.g. #"company.website". Then you can do like so:
[self setValue:textField.text forKey:self.fieldPropertyMapper[textField.tag]];
Using NSMapTable initialized with NSPointerFunctionsStrongMemory for the keys and NSPointerFunctionsOpaqueMemory for the values. Then you could store the addresses of your iVars backing your properties as the values in the table.
[self.mapTable setObject:&_company forKey:#(CompanyFieldName)];
Haven't tested this but this should get you started.

Resources