Question

I have following code on infopath form. All the column gets updated in the target list except for the people column. The verifiedBy is not updating the column in SP List. (In the list I have to to display Name). I even tried DisplayName instead of AccountId.

Can anyone please tell me what I am doing wrong. Thanks in advance.

item["LoadDate"] = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:grpLoad/my:fldLoadDate", NamespaceManager).Value;
item["EndDate"] = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:grpLoad/my:fldEndDate", NamespaceManager).Value;
item["checkRequired"] = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:grpLoad/my:fldcRequired", NamespaceManager).Value;                                                                                                         
item["VerifiedBy"] = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:grpDaa/my:CheckedBy/pc:Person/pc:AccountId", NamespaceManager).Value;
Was it helpful?

Solution

This worked.

item["VerifiedBy"] = web.EnsureUser(MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/m‌​‌​y:grpDaa/my:CheckedBy/pc:Person/pc:AccountId", NamespaceManager).Value);

OTHER TIPS

You might need to format the InfoPath user like [id];#[username]

maybe something like...

item["VerifiedBy"] = String.Format("{0};#{1}", MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:grpDaa/my:CheckedBy/pc:Person", NamespaceManager).Value), MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:grpDaa/my:CheckedBy/pc:Person/pc:AccountId", NamespaceManager).Value);

A couple resources I found this were

You probably need to construct the correct string in the following format: "[userid];#[displayname]", or use an SPFieldUserValue class for that.

For example:

SPUser user = web.EnsureUser(MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/m‌​‌​y:grpDaa/my:CheckedBy/pc:Person/pc:AccountId", NamespaceManager).Value);
item["VerifiedBy"] = new SPFieldUserValue(web, user.ID, user.Name);

Note that you might have a permission issue with EnsureUser method, if the user is not added to the site collection.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top