0

I am using PnP powershell to create a survey list but cant figure out how to edit survey option properties. Is it possible to do it through PnP powershell? What i want to do is to set "Show usernames in survey results" to "false" and "Allow multiple responses" to "true".

enter image description here

Thanks.

0

Unfortunately, you don't have option to change this 2 settings in PnP powershell, In fact this are not available in SharePoint powershell also. You have to rely on list.asmx webservice to do this.... Below is example using CSOM, you either have to convert to powershell or us in C#.

Ref link - https://social.msdn.microsoft.com/Forums/exchange/en-US/d664cb09-fbd7-495c-880f-61e3268bfd94/creating-sharepoint-online-survey-list-programmatically-and-set-properties-allowmultipleresponses?forum=sharepointdevelopment

XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndProperties = xmlDoc.CreateNode(XmlNodeType.Element, "List", "");
XmlAttribute ndTitleAttrib = (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, "Title", "");
XmlAttribute ndDescriptionAttrib = (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, "Description", "");
XmlAttribute ndDirectionAttrib = (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, "Direction", "");
XmlAttribute ndMultiresponse = (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, "AllowMultiResponses", "");
XmlAttribute ndShowUser = (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, "ShowUser", "");

ndTitleAttrib.Value = "First Survey";
ndDescriptionAttrib.Value = "Custom Survey";
ndDirectionAttrib.Value = "LTR";
ndMultiresponse.Value = "TRUE";
ndShowUser.Value = "TRUE";

ndProperties.Attributes.Append(ndTitleAttrib);
ndProperties.Attributes.Append(ndDescriptionAttrib);
ndProperties.Attributes.Append(ndDirectionAttrib);
ndProperties.Attributes.Append(ndMultiresponse);
ndProperties.Attributes.Append(ndShowUser);


string webServiceUrl = ctx.Web.Url + "/_vti_bin/Lists.asmx";

StringBuilder sbEnvelope = new StringBuilder();
sbEnvelope.Append("");
sbEnvelope.Append("");
sbEnvelope.Append(String.Format(
    "" +
        "" +
            "{0}" +
            "{1}" +
            "{2}" +
            "{3}" +
            "{4}" +
            "{5}" +
        "" +
    ""
    , id, ndProperties.OuterXml, String.Empty, String.Empty, String.Empty, version));
sbEnvelope.Append("");

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(webServiceUrl);
req.Method = "POST";
req.ContentType = "text/xml; charset=\"utf-8\"";
req.Accept = "text/xml";
req.Headers.Add("SOAPAction", "\"http://schemas.microsoft.com/sharepoint/soap/UpdateList\"");
req.UserAgent = "FrontPage";
req.UseDefaultCredentials = false;

Uri targetSite = new Uri(ctx.Web.Url);
SharePointOnlineCredentials spCredentials = (SharePointOnlineCredentials)ctx.Credentials;
string authCookieValue = spCredentials.GetAuthenticationCookie(targetSite);
req.CookieContainer = new CookieContainer();
req.CookieContainer.Add(
    new Cookie("FedAuth",
        authCookieValue.TrimStart("SPOIDCRL=".ToCharArray()),
        String.Empty,
        targetSite.Authority));

using (IO.Stream stream = req.GetRequestStream())
{
    using (IO.StreamWriter writer = new IO.StreamWriter(stream))
    {
        writer.Write(sbEnvelope.ToString());
    }
}

WebResponse response = req.GetResponse();
using (IO.Stream responseStream = response.GetResponseStream())
{
    XmlDocument xDoc = new XmlDocument ();
    xDoc.Load(responseStream);

    if (xDoc.DocumentElement != null && xDoc.DocumentElement.InnerText.Length > 0)
    {
        Debug.WriteLine(String.Concat(DateTime.Now.ToShortTimeString(), " Response of the Survey List Update: ", xDoc.DocumentElement.InnerText));
    }
}

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.