0

I have a person or group column in SharePoint 2013 I want to set the multiple values I have set its value like 1;#pallavi it's working but when done for multiple values like 1;#pall;#2;#shee it's not working can anybody help me with this? I am using c# this is my code snipped

private WebRequest createWebRequest(string RequestType, string fileName, string htmlCode, List clients) { dynamic request = null; request = new DisclosureWebRequest(); int numberOfExpiryMonths = new ReminderSPService().GetExpiryOfADocument(Constants.DISCLOSURE_LIBRARY_NAME); int masterDocumentIdDisclosure = ClientMasterDocumentsSharePointServices.GetMasterDocumentIdDisclosure(); DateTime today = DateTime.UtcNow; DateTime expiryDate = numberOfExpiryMonths > 0 ? today.AddMonths(numberOfExpiryMonths) : today.AddMonths(12); var analysts = "1192;#Monica Castro;#2786;#Winnie the Pooh"; request.MetaDataJSON = "{" + string.Format("" + "'{0}':'{1}', " + "'{2}': '{3}', " + "'{4}': '{5}', " + "'{6}': '{7}', " + "'{8}': '{9}', " + "'{10}': '{11}', " + "'{12}': '{13}', " + "'{14}':'{15}'," + "'{16}':'{17}'," + "'{18}':'{19}'," + "'{20}':'{21}'" , Constants.DISCLOSURE_FIELD_CLIENTDOCUMENTSTATUS, "Green", Constants.DISCLOSURE_FIELD_DOCUMENT_PRIORITY, "Primary Source", Constants.DISCLOSURE_FIELD_MASTERDOCUMENTID, masterDocumentIdDisclosure, Constants.DISCLOSURE_FIELD_SIGNED_DATE, today, Constants.DISCLOSURE_FIELD_PBSEXPIRES, expiryDate, Constants.DISCLOSURE_FIELD_CLIENTID, Clientid, Constants.DISCLOSURE_FIELD_ISALLPARENTSIGNED, hidIsParentSigned.Value, Constants.DISCLOSURE_FIELD_ISALLANALYSTSIGNED, hidIsAnalystSigned.Value, Constants.DISCLOSURE_FIELD_HTML, HttpUtility.HtmlEncode(htmlCode), Constants.DISCLOSURE_FIELD_ANALYSTDETAIL, hidParentAnalystDetail.Value, Constants.DISCLOSURE_FIELD_Analysts, analysts ) + "}";

        request.FileName = fileName;
        //string url = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
        string url = "http://52.171.137.86";
        var htmlCodeForPDF = "";
        if (Convert.ToInt32(hidIsParentSigned.Value) == 1 && Convert.ToInt32(hidIsAnalystSigned.Value) == 1)
        {
            htmlCodeForPDF = hidPageHTML.Value;
            htmlCodeForPDF = htmlCodeForPDF.Replace("<link rel=\"stylesheet\" href=\"", "<link rel=\"stylesheet\" href=\"" + url);
            htmlCodeForPDF = htmlCodeForPDF.Replace("<script type=\"text/javascript\" src=\"", "<script type=\"text/javascript\" src=\"" + url);
            request.HTML = htmlCodeForPDF;
        }
        else
        {
            request.HTML = "";
        }

here analyst is person or group column

Thanks

  • Please describe it more like in which version of SharePoint you are trying and which programming language you are using and please share your code. – Habibur Rahaman Apr 18 at 17:50
0

Using the below PowerShell command we can update the multi-value people or group column:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Set parameter values
$SiteURL="https://crescent.sharepoint.com/sites/pmo"
$ListName="Projects"
$FieldName= "ProjectMembers" #Internal Name
$ListItemID="25"
$UserIDs=@("salaudeen.rajack@crescent.com","Charles.jonathan@crescent.com","mark.jones@crescent.com")

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials

#Get the List & Item to update
$List = $Ctx.Web.lists.GetByTitle($ListName)
$ListItem = $List.GetItemById($ListItemID)
$Ctx.Load($ListItem)
$Ctx.ExecuteQuery()

#Resolve each user ID and get the User Objects
$UserValueColl = @()
ForEach($UserID in $UserIDs)
{
    #Get the User to Update
    $SPOUser = $Ctx.Web.EnsureUser($UserID)
    $Ctx.Load($SPOUser)
    $Ctx.ExecuteQuery()

    If($SPOUser -ne $Null)
    {
        $SPOUserValue = New-Object Microsoft.SharePoint.Client.FieldUserValue
        $SPOUserValue.LookupId = $SPOUser.id
        $UserValueColl += $SPOUserValue
    }
}

IF($UserValueColl.length -gt 0)
{
    $UserValueCollCollection = [Microsoft.SharePoint.Client.FieldUserValue[]]$UserValueColl
    #Update the Multi-People picker column
    $ListItem[$FieldName] = $UserValueCollCollection
    $ListItem.Update()
    $Ctx.ExecuteQuery()
    Write-Host -f Green "List Item has been updated!"
}

Reference URL:

SharePoint Online: Read / Update Person or Group Field (People Picker) Values using PowerShell

Using C# client-side object model coding:

ClientContext ctx = new ClientContext(weburl);
ctx.Credentials = new SharePointOnlineCredentials(userName, passWord); 

List list = ctx.Web.Lists.GetByTitle("ListTitle");
ListItem currentItem = list.GetItemById(1);

FieldUserValue[] userValueCollection = new FieldUserValue[1];

//Get all the users of this Web
UserCollection userCollection = this.ctx.Web.SiteUsers; 
this.ctx.Load(userCollection, w => w.Include(p => p.Id, p => p.Title));
this.ctx.ExecuteQuery(this.ctx);

User user = userCollection.FirstOrDefault(p => p.Title.ToLower().Trim() == userTitle.ToLower().Trim());

//Making sure that a user of title userTitle is present in this Web
if (user != null)
{
    FieldUserValue fieldUserVal = new FieldUserValue();
    fieldUserVal.LookupId = user.Id;
    userValueCollection.SetValue(fieldUserVal, 0);
}

currentItem["MultiUserValCol"] = userValueCollection;
currentItem.Update(); 
this.ctx.ExecuteQuery(); 

Source:

Update a UserMulti Column value in Client Object Model C#

Using the REST API:

var spID =_spPagecontextinfo.userid;//to add current user

strUrl = “http://<site url>//_api/web/lists/getbytitle(‘ListName’)/items”;
strheader= {“Accept”: “application/json;odata=verbose”,
“X-RequestDigest”: $(“#__REQUESTDIGEST”).val()
};

var itemType = ‘SP.Data.ListNameListItem’;///ListItemEntityTypeFullName
var item = {
“__metadata”: { “type”: itemType },
         StakeholderId:spID
};
$.ajax({
url: strUrl,
type: “POST”,
async:false,
cache:false,
contentType: “application/json;odata=verbose”,
data: JSON.stringify(item),
headers:strHeader,
success: function (data){
///your code on success
},
error: function (error) {
//return alert(error.responseText);
}
});

Source:

Updating Person/Group column using Jquery REST API and Client Object model

Using the Microsoft flow, refer to the below article:

Updating a multi-people field in SharePoint with Microsoft Flow

| improve this answer | |

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.