Domanda

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);  
  });
È stato utile?

Soluzione

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);  
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top