Updating User Profile Field REST Endpoint

How do you update the user profile field REST endpoint with a name and value for a Single Select? This is what I currently have:

_saveCountry = function(context) {
	return $.telligent.evolution.put({
	    url: jQuery.telligent.evolution.site.getBaseUrl() + 'api.ashx/v2/userprofilefields/country.json',
	    data: { 
		    'name':  context.countryname,
		    'value': context.country
	    },
	    success: function(response) {

	    }
    });
		     
},

Parents Reply Children
  • Ok, so you probably meant without the braces, right? Isn't there a way to do it dynamically as there are a lot of countries, and I will be doing the same for regions and cities?

  • Yes, without the braces.  Add the countries to the data object with a loop.  Then just the set data in your rest call to that object.

  • I thought it was working, but apparently not. How do I add the countries to the data object within a loop?

    I've tried         

     data._FieldTypeChoices_+context.countryname = context.country   

    and

     data.'_FieldTypeChoices_'+context.countryname = context.country  

    within the loop, but It doesn't seem to like it.

  • Here is an example adding 2 dynamically named fields to the data object.  You will just need to do the same with a loop adding all the dynamically named fields.

    var data = { IsSearchable: false };
    
    //loop start here
    var country = '_FieldTypeChoice_' + 'country1';
    data[country] = 'value1';
    
    country = '_FieldTypeChoice_' + 'country2';
    data[country] = 'value2';
    
    //loop end here
    
    
    console.log(data);
    
    

  • Actually, I don't want to update it in a loop as previously stated. I want to update it with the name and value of the Country select box each time a user fills out and submits the form. 

    The problem is that my code is overwriting the previously saved name and value with the current one, instead of adding to it. Here is the code that is called each time a user submits the form:

    _saveCountry = function(context) {
        var data = {};   
        var countryName = $("select.country").children("option:selected").text();
        var iso2 =  $(context.country).val();
        var country = '_FieldTypeChoices_' + iso2;
        data[country] = countryName;
    	return $.telligent.evolution.put({
    	    url: jQuery.telligent.evolution.site.getBaseUrl() + 'api.ashx/v2/userprofilefields/Country.json',
    	    data: data
        }); 
    		     
    },

  • You need to provide the entire list on each update.  You cannot just add an item.