0

I am working on building a webpart using SPFx. I need to access userprofile service to set value to a custom user profile property.

I am using PnP Js to achieve this. I found here that there is a method named "setMultiValuedProfileProperty" which supposedly should allow to set values. However i could not find any example how to use this method. I tried to use it but getting below exception

TypeError: Failed to fetch

Any help is greatly appreciated. Below is the code snippet for reference.

let propValues:string[]=["test"];
  propValues.push("this is a test");
  let userProfQuery:pnp.UserProfileQuery = new pnp.UserProfileQuery("https://contoso.onmicrosoft.com/sites/publish");
  userProfQuery.setMultiValuedProfileProperty("i:0#.f|membership|userName@contoso.onmicrosoft.com","MyProperty",propValues).then(
    function(result){
      console.log(result);
    }
  ).catch(function(error) {  
    console.log("Error: " + error);  
  });
2

You need to use it as in the below mentioned snippet:

let propValues:string[]=["test"];

pnp.sp.profiles.setMultiValuedProfileProperty
("i:0#.f|membership|userName@contoso.onmicrosoft.com", 'MyProperty', propValues).then(
    function(result){
      console.log(result);
    }
  ).catch(function(error) {  
    console.log("Error: " + error);  
});
  • i am getting below error after using the code snippet you provided: ProcessHttpClientResponseException: Error making HttpClient request in queryable: [500] – Sagar Aug 14 '18 at 6:09
  • Update : Thanks a lot @Gautam the snippet you provided worked (there was a silly mistake from my end which was causing the error) – Sagar Aug 14 '18 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.