Surendra Mourya
Surendra Mourya

Reputation: 611

Sharepoint 2013, JS link people picker field not working saving for multiple users

I am using below CSR code to set peoplepicker value to multiple person. I have multiple users to be assigned to my peoplepicker field. The code works when i pass current user, but it do not work for other values.

function renderAssignedTo(ctx) {
 //get current user properties
 //var currentUser = $().SPServices.SPGetCurrentUser({fieldNames: ["Title", "Name"]});   //get current user properties
 if(ctx.results!=undefined)
 {
     ctx.CurrentFieldValue = [];
     for(var i=0; i<ctx.results.length;i++)
     {
         var currentUserEntry = createUserEntity(ctx.results[i].Name,ctx.results[i].Title);
         ctx.CurrentFieldValue.push(currentUserEntry); 
     }
 }       
 return SPClientPeoplePickerCSRTemplate(ctx);
}

Here ctx is having array of user name and title. Those values need to be set for peoplepicker field in NewForm.aspx which accepts multiple value.

I took reference of this post

1: https://sharepoint.stackexchange.com/questions/112506/sharepoint-2013-js-link-return-default-field-rendering/112576 and Sharepoint 2013 - EditForm, people picker new value not saving

Upvotes: 0

Views: 832

Answers (1)

Lee
Lee

Reputation: 5493

Here is my sample test demo:

<script type="text/javascript">
        (function () {
            SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
                Templates: {
                    Fields: {
                        "UserField": {
                            "NewForm": setDefaultUser
                        }
                    }
                }
            });
        })();

        function setDefaultUser(ctx) {
            ctx.CurrentFieldValue = [{
                Description: "",
                DisplayText: "Lee",
                EntityGroupName: "",
                EntityType: "",
                HierarchyIdentifier: null,
                IsResolved: true,
                Key: "contoso\\lee",
                MultipleMatches: [],
                ProviderDisplayName: "",
                ProviderName: ""
            },
            {
                Description: "",
                DisplayText: "Administrator",
                EntityGroupName: "",
                EntityType: "",
                HierarchyIdentifier: null,
                IsResolved: true,
                Key: "contoso\\administrator",
                MultipleMatches: [],
                ProviderDisplayName: "",
                ProviderName: ""
            }
            ];
            // Return the html for the user field
            return SPClientPeoplePickerCSRTemplate(ctx);
        }
    </script>

enter image description here

Upvotes: 0

Related Questions