Search code examples
postsharepointsharepoint-2013user-information-list

SharePoint 2013 - Add a User to The UserInformationList


I'm currently having a little problem and I'm not quite sure how to solve it yet. The situation is this. In SharePoint 2013 I'm using the REST-API to update and create List Items.

If there is a ppl-Picker the Values are the Ids of the users in the UserInformationList. So far so good. But now heres my question.

This does not work with users that are not in the UserInformationList yet. SharePoint in nativc somehow seems to make to POST-Requests when I'm searching for a user that does not exist yet. The first one seems to fetch users from another list given the string entered so far in the ppl picker. That body looks like this

   <?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009" SchemaVersion="15.0.0.0" LibraryVersion="15.0.0.0" ApplicationName="Javascript Library">
   <Actions>
      <StaticMethod TypeId="{xxxxxxxxxxxxx}" Name="ClientPeoplePickerSearchUser" Id="5">
         <Parameters>
            <Parameter TypeId="{xxxxxxxxxxxxx}">
               <Property Name="AllowEmailAddresses" Type="Boolean">false</Property>
               <Property Name="AllowMultipleEntities" Type="Boolean">true</Property>
               <Property Name="AllUrlZones" Type="Boolean">false</Property>
               <Property Name="EnabledClaimProviders" Type="String" />
               <Property Name="ForceClaims" Type="Boolean">false</Property>
               <Property Name="MaximumEntitySuggestions" Type="Number">30</Property>
               <Property Name="PrincipalSource" Type="Number">15</Property>
               <Property Name="PrincipalType" Type="Number">1</Property>
               <Property Name="QueryString" Type="String">jack</Property>
               <Property Name="Required" Type="Boolean">false</Property>
               <Property Name="SharePointGroupID" Type="Number">0</Property>
               <Property Name="UrlZone" Type="Number">0</Property>
               <Property Name="UrlZoneSpecified" Type="Boolean">false</Property>
               <Property Name="Web" Type="Null" />
               <Property Name="WebApplicationID" Type="String">{00000000-0000-0000-0000-000000000000}</Property>
            </Parameter>
         </Parameters>
      </StaticMethod>
   </Actions>
   <ObjectPaths />
</Request>

It then gets back a JSON with the user Information. When I now send the form a second POST-Request is made basically containing all the form-info looking somewhat like this

<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009" SchemaVersion="15.0.0.0" LibraryVersion="15.0.0.0" ApplicationName="Javascript Library">
   <Actions>
      <ObjectPath Id="3" ObjectPathId="2" />
      <ObjectPath Id="5" ObjectPathId="4" />
      <ObjectPath Id="7" ObjectPathId="6" />
      <ObjectPath Id="9" ObjectPathId="8" />
      <ObjectPath Id="11" ObjectPathId="10" />
      <ExceptionHandlingScopeSimple Id="12">
         <Method Name="ValidateUpdateListItem" Id="14" ObjectPathId="10">
            <Parameters>
               <Parameter Type="Array">
                  <Object TypeId="{xxxxxxxxxxx}">
                     <Property Name="ErrorMessage" Type="Null" />
                     <Property Name="FieldName" Type="String">Title</Property>
                     <Property Name="FieldValue" Type="String">___test</Property>
                     <Property Name="HasException" Type="Boolean">false</Property>
                  </Object>
                  <Object TypeId="{xxxxxxxxxxx}">
                     <Property Name="ErrorMessage" Type="Null" />
                     <Property Name="FieldName" Type="String">Someone</Property>
                     <Property Name="FieldValue" Type="String" />
                     <Property Name="HasException" Type="Boolean">false</Property>
                  </Object>
                  <Object TypeId="{xxxxxxxxxxx}">
                     <Property Name="ErrorMessage" Type="Null" />
                     <Property Name="FieldName" Type="String">LookupField</Property>
                     <Property Name="FieldValue" Type="String" />
                     <Property Name="HasException" Type="Boolean">false</Property>
                  </Object>
                  <Object TypeId="{xxxxxxxxxxx}">
                     <Property Name="ErrorMessage" Type="Null" />
                     <Property Name="FieldName" Type="String">SomeTextField</Property>
                     <Property Name="FieldValue" Type="String" />
                     <Property Name="HasException" Type="Boolean">false</Property>
                  </Object>
                  <Object TypeId="{xxxxxxxxxxx}">
                     <Property Name="ErrorMessage" Type="Null" />
                     <Property Name="FieldName" Type="String">APerson</Property>
                     <Property Name="FieldValue" Type="String">[{"Key":"i:0#.w|dom\\xxxxxx","Description":"DOM\\xxxxx","DisplayText":"Some, Name","EntityType":"User","ProviderDisplayName":"Active Directory","ProviderName":"AD","IsResolved":true,"EntityData":{"Title":"","MobilePhone":"","SIPAddress":"some.person@mail.com","Department":"XX-XX","Email":"some.person@mail.com"},"MultipleMatches":[],"AutoFillKey":"i:0#.w|dom\\xxxxxxx","AutoFillDisplayText":"Person, Some","AutoFillSubDisplayText":"","AutoFillTitleText":"SomeString","DomainText":"some.domain.net","Resolved":true,"LocalSearchTerm":"some"}]</Property>
                     <Property Name="HasException" Type="Boolean">false</Property>
                  </Object>
                  <Object TypeId="{xxxxxxxxxxx}">
                     <Property Name="ErrorMessage" Type="Null" />
                     <Property Name="FieldName" Type="String">ContentType</Property>
                     <Property Name="FieldValue" Type="String">Element</Property>
                     <Property Name="HasException" Type="Boolean">false</Property>
                  </Object>
                  <Object TypeId="{xxxxxxxxxxx}">
                     <Property Name="ErrorMessage" Type="Null" />
                     <Property Name="FieldName" Type="String">ContentTypeId</Property>
                     <Property Name="FieldValue" Type="String">0x010020785F18D738D74797A0C6B07438E69E</Property>
                     <Property Name="HasException" Type="Boolean">false</Property>
                  </Object>
               </Parameter>
               <Parameter Type="Boolean">false</Parameter>
               <Parameter Type="Null" />
            </Parameters>
         </Method>
      </ExceptionHandlingScopeSimple>
   </Actions>
   <ObjectPaths>
      <StaticProperty Id="2" TypeId="{xxxxxxxxxxx}" Name="Current" />
      <Property Id="4" ParentId="2" Name="Web" />
      <Property Id="6" ParentId="4" Name="Lists" />
      <Method Id="8" ParentId="6" Name="GetById">
         <Parameters>
            <Parameter Type="String">xxxxxxxxxxx</Parameter>
         </Parameters>
      </Method>
      <Method Id="10" ParentId="8" Name="AddItem">
         <Parameters>
            <Parameter TypeId="{xxxxxxxxxxx}">
               <Property Name="FolderUrl" Type="String">/sites/site/lists/theList</Property>
               <Property Name="LeafName" Type="Null" />
               <Property Name="UnderlyingObjectType" Type="Number">0</Property>
            </Parameter>
         </Parameters>
      </Method>
   </ObjectPaths>
</Request>

This second post also somehow seems to create the user in the UserInformationList. So my question is.

Is there a way to create the users that are not existant in the UserInformationList yet and get back their Ids after they are created?

As I only developed SharePoint on the front-end I'm not too familiar with its architecture. Would be great if someone of you guys could help me out here


Solution

  • You can call EnsureUser method on the web which will create the user, if it does not exist, and return its ID.