How to modify person or group field value with new value

Hi
I have person or group field having property Person Only.
Thsi firls already have one value. Now I want to update it but this code to update value is not working.
string myName = @"ABC\myname";
web.EnsureUser(myName);
SPUser myUser = web.SiteUsers[myName];
SPFieldUserValue myNamevlaue = new SPFieldUserValue(web, myUser.ID, myUser.LoginName);
oSplistItem["My_x0020_User"] = myNamevalue;
oSplistItem.Update();
I am getting myNamevalue correct in the veriable. But why its not updating in the list?
is there any issue in the above code?
Do I need to delete previous value and then update new value in this field? How?

Hi,
The format of the user value in people/Group field must be
ID;#Name, you can use the following code snippets to update the people/group field.
string loginName = "ABC\\myname";
SPUser user = web.SiteUsers[loginName];
SPList list = web.Lists.TryGetList("ListName");
if (list == null)
Console.WriteLine("list is not exist!");
return;
SPListItem item = list.GetItemById(3);
item["My_x0020_User"] = user.ID.ToString() + ";#" + user.Name;
item.Update();
Thanks,
Jason
Please remember to mark the reply as answer if it help, and unmark the answer if it provide no help.

Similar Messages

  • How to export "Managed by" field of Distribution and Security groups and import with new values? (Exchange 2010, AD 2003)

    My Active Directory environment is 2003 functional level and we have Exchange 2010.
    I am trying to find out the best way to do a mass edit for the "Managed by" values of our security and distribution groups.
    I know we can export the "managed by" field by csvde but I am not sure this is the correct way to do it. Also in the case that there are multiple users assigned to be managing a distribution group it only shows one value. Also powershell from Exchange
    2010 can be used with "get-distribution" but as our AD environment is 2003 is this correct also?
    Finally once the data is exported to csv can it be edited to then reimport and udpate the existing group managed by fields with new values?
    Not really sure that the best way to go about this is.
    Summary - We have 2003 AD with Exchange 2010 and I am trying to export a list of all our Distribution/Security groups showing the group name and managedby values so we can edit and update the
    existing managedby values with new ones. In some cases we have multiple users as the owners.
    Appreciate any advice on how this can be best achieved. Thank you.

    Hi,
    We can use the following command in Exchange 2010 to export "Managed by" field of Distribution and Security groups:
    Get-DistributionGroup | Select-object Name,@{label="ManagedBy";expression={[string]::join(“;”,$_.managedby)}},Primarysmtpaddress | Export-Csv
    C:\export.csv
    After you changed the Managed by field in export.csv and saved it as a new file named import.csv, we can run the following command to set with new value:
    Import-Csv C:\import.csv | Foreach-Object{ Set-DistributionGroup –Identity $_.Name –ManagedBy $_.ManagedBy}
    Hope it works.
    Thanks,
    Winnie Liang
    TechNet Community Support

  • How to export "Managed by" field of Distribution and Security groups and import with new values?

    My Active Directory environment is 2003 functional level and we have Exchange 2010.
    I am trying to find out the best way to do a mass edit for the "Managed by" values of our security and distribution groups.
    I know we can export the "managed by" field by csvde but I am not sure this is the correct way to do it. Also in the case that there are multiple users assigned to be managing a distribution group it only shows one value. Also powershell from Exchange
    2010 can be used with "get-distribution" but as our AD envronment is 2003 is this correct also?
    Finally once the data is exported to csv can it be edited to then reimport and udpate the existing group managed by fields with new values?
    Not really sure that the best way to go about this is.
    Summary - We have 2003 AD with Exchange 2010 and I am trying to export a list of all our Distribution/Security groups showing the group name and managedby values so we can edit and update the
    existing managedby values with new ones.
    Appreciate any advice on how this can be best achieved. Thank you.

    Hi Barkley,
    You can also refer to Official Scripting Guys forum to get a script solution:
    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG&filter=alltypes&sort=lastpostdesc
    Best Regards,
    Amy Wang

  • Replacing the old value with new value on the website

    Hi ,
    I have two input fields CLIN # and PR#.When i enter the text,for the first it is working fine,second time when i enter it is replacing the value which i enter with the first one.I should not replace the old value.
    ex:
    Example when i enter test5 for the first time
    CLIN # :Test 5
    Next when i enter Test6 ,this value replaces the first one
    CLIN#: Test6
    CLIN#:Test6(there is no test5)
    I am doing for my istore application.Any ideas

    As the user that created the anonymous block ruun:
    select count(*) from general_acct_mast_table;
    and
    select tbaadm.count(*) from general_acct_mast_table;I strongly suspect that they are actually two different tables, and the tbaadm version is substantially larger that the non-qualified one.
    In any case I would not be doing this as a row-by-row procedure. I would create two lookup tables like:
    create table masked_general as
    select acid, foracid, round(dbms_random.value(81000000,85000000)) masked
    from (select distinct acid, foracid
          from general_acct_mast_table
          where acct_ownership not in ('O'));
    create table masked_stmnt as
    select * from masked_general;
    alter table masked_general add constraint masked_general_pk
       primary key (acid);
    alter table masked_stmnt add constraint masked_stmnt_pk
       primary key (foracid);Then do the updates as:
    update (select g.foracid, g.acid, gm.masked
            from general_acct_mast_table g
               join masked_general gm
                  on g.acid = gm.acid)
    set foracid = masked;
    update (select s.foracid, sm.masked
            from mini_stmnt_details_table s
               join masked_stmnt sm
                  on s.foracid = sm.acid)
    set foracid = masked;Note that this assumes that both acid and foracid are individually unique in general_acct_mast_table, which seems to be implied by your procedure, and that you want to be able to roll the whole thing back if there are problems (that is, you do not want to commit between the update of general_acct_mast_table and mini_stmnt_details_table).
    I would also probably a a verification step after creating the first masked table to ensire that you did get unique vluaes back fo the masked column.
    John

  • How to add users from person or group field in a sharepoint list to sharepoint group

    Hi,
    How to add users(single or multiple) from person or group field in a sharepoint list to sharepoint group programmatically?
    Any suggestions would be appreciated.
    Thank you,
    AA.

    Hello,
    Use SPGroup.AddUser() method to add user in group. I have just written sample code in notepad so it is not tested:
    SPSecurity.RunWithElevatedPrivileges(delegate()
    using(SPSite Site = new SPSite(SPContext.Current.Site.Url))
    Using(SPWeb Web = Site.OpenWeb())
    SPList list = web.Lists["ListName"];
    SPQuery query=new SPQuery ();
    query.Query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>Test</Value></Eq></Where>";
    SPListItemCollection items = list.GetItems(query);
    if(items.Count > 0)
    foreach(SPListItem item in items)
    //Get USers from person or group column
    SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");
    SPFieldUserValueCollection userFieldValueCollection = (SPFieldUserValueCollection)userField.GetFieldValue(item["Users"].ToString());
    SPGroup spGroup = spSite.RootWeb.Groups[groupName];//group name
    if (users.Count != 0)
    bool isUserInGroup = false;
    foreach (SPFieldUserValue user in users)
    foreach (SPUser item in spGroup.Users)
    string itemUserName = item.LoginName;
    string UserName = user.User.LoginName;
    if (itemUserName == UserName)
    isUserInGroup = true;
    break;
    if (!isUserInGroup)
    spGroup.AddUser(user.User);
    The above code will query list item and then get users from "Users" column. Now it will check whetehr user is already in group not, if not then add user in group.
    http://rajanijilla.blogspot.sg/2012/09/add-users-to-group-programmatically.html
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Save history values of person or group field in another person or group field

    Hi
    I have a person or group field in sharepoint list that users can assign task to colleagues by this column. Every time value of this field changed and I want to save
    these values in another person or group field (for history and 
    filter view base on it).
    How I can do this?
    Thanks.

    I create workflow variable and give it these values:
    First Person/Group value,(Display Names, Semicolon Delimited),
    Second Person/Group value,(Display Names, Semicolon Delimited)
    Then I set this variable to Second Person/Group but it's give me error and does not work.

  • How to Insert Sharepoint 2013 Person or Group Field using VBA

    Hello,
    How to Insert Sharepoint 2013 Person or Group Field using VBA , I tried set the field with ID / ID;Name / Name
    but all failed, Please advice 
    Function SetSP_Field(F_Yer As Single, F_WekNo As Single, F_ProjectNum As String, strField As Variant, strFieldValue As Variant) As String
    ' test code
        Dim rst         As Recordset
        Dim strSQL      As String
        Dim SP_RecSet   As ADODB.Recordset
        Set SP_RecSet = New ADODB.Recordset
        SetSP_Field = False
        strSQL = "Status Report"
        On Error Resume Next
        Call SP_Connect(2)
        strSQL = "select " & SP_List & ".* From  " & SP_List _
               & " Where [Year] = " & CInt(F_Yer) _
               & "   and [WeekNo] = " & CInt(F_WekNo) _
               & "   and [Compass_Code] = '" & F_ProjectNum & "' ; " _
    '           & " Set " & strField & " = " & strFieldValue
        'Debug.Print strSQL
        'Debug.Print SP_CN
        SP_RecSet.Open strSQL, SP_CN, adOpenStatic, adLockOptimistic
        If SP_RecSet.RecordCount = 0 Then
            Debug.Print "Record for project: " & F_ProjectNum & " not found"
            LogFile.WriteLine ("Record " & strID & " not found")
        End If
        If Not SP_RecSet.EOF Then
            'SP_RecSet.Edit
            SP_RecSet.Fields(strField) = strFieldValue
            SP_RecSet.Update
            If Err.Number <> 0 Then
                MsgBox ("SP Update Error: " & Err.Description)
                GoTo Exit_Fun
            End If
            SetSP_Field = True
        End If
    Exit_Fun:
        SP_RecSet.Close
        Set SP_RecSet = Nothing
    End Function

    Hi Tim,
    Let’s verify the followings:
    Whether this issue occurred for other lists in the same site.
    Whether this issue occurred for all users who don’t have full control.
    Whether this issue occurred on other sites.
    When you created the people & group column, which show field did you used? Please try to use a different show field for the people & group column, compare the result.
    In addition, please check if the link is useful:
    http://www.learningsharepoint.com/2013/08/21/empty-value-in-people-picker-after-saving-the-list-form-in-sharepoint/
    Best Regards,
    Wendy
    Wendy Li
    TechNet Community Support

  • Copy person & group field value to another person or group field programmatically

    Hi 
    I have one user list in SharePoint sitecollection1 having User in Title(having simple user name) and UserName in Person or Group type field.
    I want to copy this list into my site list with same column names programatically using timer job.
    How I can copy the person or Group field from siteColletion1 to person or group field of sitecollection2(my site),
    as both column types are same.
    Pleas suggest any solution.

    I am getting user name and user id using following code,
    foreach (Microsoft.SharePoint.Client.FieldUserValue userValue in oclistItem["UserName"] as Microsoft.SharePoint.Client.FieldUserValue[])
    string username =    userValue.lookupValue.tostring();                               
    But how to get the login name ? or how can I get the User Object from this field?
    Anybody got this type of issue before.
    Please suggest any solution

  • Sorting and filtering by select-multi person or group field in the list in SharePoint 2013

    Hi everybody,
    In SharePoint 2013, I have defined a column as "Person or Group" field, which you allow for multiple selections. when I try to sort/filter it by this field in the list. The field doesn't show up in the dropdown. If I changed "Allow multiple
    selections" option to "No" by clicking the column name to edit it in "List Settings", the field can show up sort in the dropdown.
    How about support sorting and filter by select-multiple "Person or Group" field in sharepoint 2013?
    BTW, in SharePoint 2010, it can support this issue no matter what the "Allow multiple selections" option the request is.
    Any help would be great!
    Thanks,
    Jodie

    Hi Jodie,
    Can you please give this as a try.
    To fix the Filter Issue on Assigned To Column. We need to run the following scripts.
    The field which allows more than one values or which allows multiple selections. The multi-valued fileds are non-sortable,
    non-filterable. Multi-valued fields cannot be indexed
    $web=Get-SPWeb
    $list=$web.Lists[] $field=$list.Fields[ColumnName] $strSchema=$field.SchemaXml $str=Schema$strSchema.Replace("Sortable=`"FALSE`"","Sortable=`"true`"")
    $field.SchemaXml = $strSchema
    Krishana Kumar http://www.mosstechnet-kk.com
    Thanks for your reply, I have tried to run the scripts, but it still cannot work. The following is my scripts:
    $web=Get-SPWeb 'http://cst-server-01'
    $list=$.web.Lists["Product Request"]
    $field=$list.Fields["Applicant"]
    $strSchema=$field.SchemaXml
    $str=Schema$strSchema.Replace("Sortable='"FALSE'"", "Sortable='"True'"")
    $field.SchemaXml = $strSchema

  • Where to Configure Service Ticket "Reason" & "Subject" field with new value

    Hi Friends - I am working on IC Webclient Service Ticket. I want to Configure the "Reason" field as well as the "Subject" field in Service Ticket with new Values as per our requirement.
    I could not find any Configuration object for the above mentioned customizing in the CRM > SPRO.
    Can you pls guide me where I can configure the same?
    Thanks in advance and warm regards
    Purnendu

    Hi Gert - Thanks a lot for your reply.
    I am using CRM 5.0. I just forgot that Categorization profile can be used for the same.
    I have configured the categorization profile for the same and its working fine.
    One more thing -
    I want to create an Appointment with Customer for problem resolution at the Customer Site. I want to assign Resorces to the Appointment so that the responsible resource is notified and sent to the Customer Site for Visit.
    Can you pls guide me on the same?
    Cheers
    Purnendu
    P.S. - Full reward points awarded.

  • How can I compare single value with multiple value...

    Hello,
    I want to compare one value with multiple values, how can it possible ?
    Here in attachment I tried to design same logic but I got problem that when I entered value in y that is compared with only minimum value of x, I don't want that I want to compare y value with all the x value and then if y is less then x while loop should be stop.
    I want to do so because in my program some time I didn't get result what I want, for example x values is 4,5,6,7,8  and y value is  suppose 6 then while loop should be stop but here it consider only minimum number and its 4 here so while loop is not stop even y is less then 7 and 8. So I want to compare y value with all the entered values of x and if y is less then any of x values then while loop should be stop and led should be ON.
    Please guide me how can I do so.....
    Solved!
    Go to Solution.
    Attachments:
    COMPARISON.vi ‏8 KB

    AnkitRamani wrote:
    Thank you very mach for your help..
    may be i have solved this ....i have made one change in my vi that instead of min. i select max and max. value is compare with the value of y and then if y is less then the max. while loop will be stop other wise its run continuously.
    this is working fine...
    any ways thanks again for your help and time...
    I have to agree with Lewis - his way is more efficient.
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • How to compare single value with multiple values

    In my query I have something like this:
    A.SOR_CD=B.SOR_CODE where A and B are 2 different tables. This condition is in the where clause. The column in table A has single values but some values in table B have multiple comma separated values (822, 869, 811, ..).  I want to match this single
    value on the left side with each of the comma separated values. Please let me know how will I be able to do it. The number of comma separated values on the right side may vary.

    Hi MadRad123,
    According to your description, you want to compare single value with multiple values in your query. Right?
    In this scenario, the table B has comma separated values, however those comma separated values are concatenated into a string. So we can use charindex() function to return the index of the table A value. And use this index as condition in
    your where clause. See the sample below:
    CREATE TABLE #temp1(
    ID nvarchar(50),
    Name nvarchar(50))
    INSERT INTO #temp1 VALUES
    ('1','A'),
    ('2','A'),
    ('3','A'),
    ('4','A'),
    ('5','A')
    CREATE TABLE #temp2(
    ID nvarchar(50),
    Name nvarchar(50))
    INSERT INTO #temp2 VALUES
    ('1','a,A'),
    ('2','A,B'),
    ('3','c'),
    ('4','A,C'),
    ('5','d')
    select * from #temp1 a inner join #temp2 b on a.ID=b.ID
    where CHARINDEX(a.Name,b.Name)>0
    The result looks like below:
    Reference:
    CHARINDEX (Transact-SQL)
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • How to compare dropdown pre value with post value in sharepoint designer list workflow

    How to compare dropdown pre value with post value in sharepoint designer list workflow

    Hi,
    Can you provide more details about your requirement? It would make others easier to find a solution for you.
    By default, a workflow will be triggered after submitting data in the NewForm or EditForm.
    If you want to monitor the value changed in a drop down menu which is supposed to be in NewForm or EditForm, it would be more appropriate to apply custom JavaScript in the NewForm
    or EditForm page.
    About how to detect the value changed using JavaScript, the demos in this thread would be helpful:
    http://stackoverflow.com/questions/12080098/dropdown-using-javascript-onchange
    Thanks
    Patrick Liang
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to find in which table field "DDTEXT" with entry "xyz"

    How to find in which table field "DDTEXT" with entry "Item number in contract account document" exists.
    There are too many tables with field name "DDTEXT"

    Refer:
    Getting short text of data element

  • UIInput will not refresh with new value

    I have the following JSF component
    <h:inputText id="entryfee" binding="#{entryform.evententryfee}" value=""/>
    in a onchangeevent in another component I have the following
    double entryfee = 100.0;
    FacesContext mycontext = FacesContext.getCurrentInstance();
    evententryfee.setValue(String.valueOf(entryfee));
    evententryfee.updateModel(mycontext);
    evententryfee is updated but the new value is not displayed by the component
    How do I refresh the display to show the new value ?

    Why do you use the component binding instead of a normal value binding?
    You can write
    <h:inputText id="entryfee" value="#(entryform.entryfee}"/>
    Anyway, a component binding does not overwrite the attribute whichi is explictly specifed by the tag.
    So, if you insist to use the component binding, you can write
    <h:inputText id="entryfee" binding="#{entryform.evententryfee}"/>

Maybe you are looking for

  • Apple Menu items are missing. How do I restore them?

    My Apple Menu is missing some items. Not sure of all that may be missing, but the ones that I use that are missing include "System Preferences," "Restart," and "Shutdown." System Preferences is still installed and available from the Applications fold

  • How to authenticate  a Servlet-- HELP!!!!!!!!

    I have a Java client that try to contact with a servlet using a user and a password. I know that the authentication is correct, because the message "User OK" (showed below) appear, but I don't know what to do now to obtain an UrlConnection with the s

  • Working C++ Program in Xcode, NOT working.

    Please Help!! I have written a small program for my C++ Programming College Course.  I Normally use Xcode on my Macbook Pro to do all my HW, But since the new iCloud came out, I was able to link all my files to my iMac at home.  I installed Xcode on

  • Same form but printout  different font in printer HP2200 and HP4100

    Dear experts, I have one SAPscript form ,print in pinter HP2200 and HP4100, but printout is distinct font. Could you help me? Thanks and regards, collysun

  • Ipod hold button not working

    I sent my ipod to apple to get the battery replaced. On receiving the ipod back i realised the hold button did not work and that the ipod was continuosly crashing when on the move and downloading songs from i tunes. I contacted the support team think