none
Binding list to form not working with '&' character in list field data

    Question

  • Hi,

    I have a SharePoint list with a field called Title. I have a form based on this list with the field bound to the form as a label (for workflow to access). Here is the code for the form field.

    <asp:Label runat="server" id="ff2{$Pos}" text="{@Title}" __designer:bind="{ddwrt:DataBind('u',concat('ff2',$Pos),'Text','','ID',ddwrt:EscapeDelims(string(@ID)),'@Title')}" />

    I have a workflow that runs through a form action button which take ff2 (title) and  does other stuff. The problem I have is with records where the value of 'title' contains the '&' character (example ab&cd). Blank is pulled in by the workflow when I get the value of ff2.

    I am guessing it has to do with the data binding and/or escape (special) characters coming through but I don't know how to fix it. Any help will be greatly appreciated

    Wednesday, July 21, 2010 3:07 AM

All replies

  • Hello DelMot,

    I believe you're onto something in regards to the character encoding. Edit your list item that is having issues to use &amp; or any of the other encoded versions of &. If this lets your workflow function you can use JavaScript to do a find/replace on that character with an encoded one.

    After that you'll need to adjust your view so that the Title is as follows:

    <xsl:value-of select="@Title" disable-output-escaping="yes"/>
    

    This will mean using a DataFormWebPart instead of a ListViewWebPart.

    Take a look at this page:

    http://www.the-art-of-web.com/javascript/escape/

    The escaping that makes sense to me is &amp;. It should be possible to use the PreSaveAction function SharePoint provides you to peform a JavaScript replace on the &.

    Here is some information about the PreSaveAction. http://www.endusersharepoint.com/2010/05/27/sharepoint-extending-the-dvwp-%e2%80%93-part-5-doing-stuff-before-save-on-submit-presaveaction/ This whole series of articles is great.

    Replace:

    http://www.w3schools.com/jsref/jsref_replace.asp


    Regards,
    Dalibor K
    Microsoft Online Community Support
    Wednesday, August 11, 2010 12:17 AM
  • Hello DelMot,

    I've investigated this a bit more and I think the issue comes down the the data type associated with a single line of text. A single line of text does not like ampersands. Here is what I tried as possible workarounds:

    &amp;
    %26
    %26amp%3B

    I also created a parameter to store the encoded ampersand and a variable but both got removed.

    A workaround you could try is to not use single line of text columns. If you use a multiple line of text column it seems to work just fine but you get the additional HTML markup.

    For example, I just kept logging to the history list. I would log the single line of text data and the multiple line of text data. The single line of text would always get removed if the ampersand was in there.

    I might be missing something obvious but I believe you're better of just using a multiple line of text column instead of fighting this.


    Regards,
    Dalibor K
    Microsoft Online Community Support
    Tuesday, September 14, 2010 12:24 AM