1

As per the title, I need to be able to update the column order by script. I've created and updated fields using Lists.UpdateList web service Method via SPServices, but can't see an option for changing the field order.

is this possible?

Thanks.

PS Just in case there's other options to achieve what I'm after, or I'm overlooking something, what I'm actually trying to achieve overall is the updating of lists and forms via script instead of the UI. So changes are repeatable and reusable and can be developed and tested on development and QA sites and then easily, accurately and reliably be applied to production sites after. This is the only thing i haven't been able to do so far.

2
  • If the property is not exposed in the webservice then you can't change it with code, so the answer is no Apr 12, 2017 at 14:40
  • Thanks. The web service doesn't seem to be very well documented, so I was hoping I'd missed something, or there was another way to achieve it.
    – BFG
    Apr 13, 2017 at 15:35

1 Answer 1

1

You can try to write your own web service or http handler and call it using ajax. I'm not able to test code on SP 2007, but it works on 13. C# reorder func:

function void ReorderColumns(SPList myList, StringCollection orderedFields)
{
    foreach (SPField field in myList.Fields)
    {
        if (!orderedFields.Contains(field.InternalName))
        {
            orderedFields.Add(field.InternalName);
        }
    }

    StringBuilder sb = new StringBuilder();
    XmlTextWriter xmlWriter = new XmlTextWriter(new StringWriter(sb));
    xmlWriter.Formatting = Formatting.Indented;
    xmlWriter.WriteStartElement("Fields");

    for (int i = 0; i < orderedFields.Count; i++)
    {
        xmlWriter.WriteStartElement("Field");
        xmlWriter.WriteAttributeString("Name", orderedFields[i]);
        xmlWriter.WriteEndElement();
    }
    xmlWriter.WriteEndElement();
    xmlWriter.Flush();
    string rpcTemplate = @"<?xml version=""1.0"" encoding=""UTF-8""?>  
        <Method ID=""0,REORDERFIELDS"">  
        <SetList Scope=""Request"">{0}</SetList>  
        <SetVar Name=""Cmd"">REORDERFIELDS</SetVar>  
        <SetVar Name=""ReorderedFields"">{1}</SetVar>  
        <SetVar Name=""owshiddenversion"">{2}</SetVar>  
        </Method>";
    string rpcCall = string.Format(
        rpcTemplate,
        myList.ID,
        SPHttpUtility.HtmlEncode(sb.ToString()),
        myList.Version);
    myList.ParentWeb.ProcessBatchData(rpcCall);
}

Where orderedFields is ordered collection of fields internal names. Try it.

2
  • Thanks, looks good. I could be wrong, but sadly I don't think I can use/deploy C# code though. Where does it need to go? I don't have any access to the backend servers.
    – BFG
    Apr 13, 2017 at 15:33
  • Can u put some files to layouts folder on WFE servers or admins can do it for you? If you do, try to create ashx file (handler) which doesn't need to be compiled. Example Apr 17, 2017 at 6:44

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.