0

I have been trying to develop a set of pages that each has a form on the page where the user can type a response to questions on each page, and the form is saved when they submit it. If the user returns to that page, we must show the user's previous data, so they can edit and add to it.

I've been using Sharepoint designer, as I'm only new to SP and I don't know how to make a custom web part yet. I have it so it can create a record in a list, and save it. But when I return to the page, it is not selecting the correct row based on a match on the current user.

Is there a way to select the list row where the current user's ID is matched to the saved ID in the list? I have tried using Datasource Properties > "Filter..." to retrieve the correct row, but it only gets the very first row every time. This is what a screenshot of the settings look like:

enter image description here

I believe the following is the code that these settings create. Sorry the formatting isn't great - I'm not sure how to word wrap on here. The line in question is the longest line, which is line 3.

<WebPartPages:DataFormWebPart runat="server" SuppressWebPartChrome="False" Description="" PartImageSmall="" DataSourceID="" MissingAssembly="Cannot import this Web Part." FrameType="Default" ConnectionID="00000000-0000-0000-0000-000000000000" DetailLink="" ExportControlledProperties="True" IsVisible="True" AllowRemove="True" AllowEdit="True" ID="g_bfe9ae06_92c1_40bb_a521_eec50fa168ae" Dir="Default" FrameState="Normal" ViewContentTypeId="" AllowConnect="True" PageSize="-1" AllowMinimize="True" IsIncludedFilter="" ShowWithSampleData="True" HelpMode="Modeless" ExportMode="All" ViewFlag="0" Title="mjcooper (1)" HelpLink="" AllowHide="True" AllowZoneChange="True" PartOrder="2" UseSQLDataSourcePaging="True" PartImageLarge="" IsIncluded="True" NoDefaultStyle="TRUE" __MarkupType="vsattributemarkup" __WebPartId="{BFE9AE06-92C1-40BB-A521-EEC50FA168AE}" __AllowXSLTEditing="true" WebPart="true" Height="" Width="">
<DataSources>
  <SharePointWebControls:SPDataSource runat="server" DataSourceMode="ListItem" SelectCommand="<View><Query><Where><And><Eq><FieldRef Name="ContentType"/><Value Type="Text">Item</Value></Eq><Eq><FieldRef Name="Author"/><Value Type="Integer"><UserID/></Value></Eq></And></Where></Query><ViewFields><FieldRef Name="ContentTypeId"/><FieldRef Name="Title"/><FieldRef Name="File_x0020_Type"/><FieldRef Name="comments1"/><FieldRef Name="comments2"/><FieldRef Name="ID"/><FieldRef Name="ContentType"/><FieldRef Name="Modified"/><FieldRef Name="Created"/><FieldRef Name="Author"/><FieldRef Name="Editor"/><FieldRef Name="_HasCopyDestinations"/><FieldRef Name="_CopySource"/><FieldRef Name="_UIVersion"/><FieldRef Name="_UIVersionString"/><FieldRef Name="Attachments"/><FieldRef Name="_ModerationStatus"/><FieldRef Name="FileRef"/><FieldRef Name="FileDirRef"/><FieldRef Name="Created_x0020_Date"/><FieldRef Name="FSObjType"/><FieldRef Name="FileLeafRef"/><FieldRef Name="PermMask"/></ViewFields></View>" UseInternalName="True" ID="mjcooper1">
    <SelectParameters>
      <WebPartPages:DataFormParameter ParameterKey="ListItemId" PropertyName="ParameterValues" DefaultValue="0" Name="ListItemId"></WebPartPages:DataFormParameter>
      <WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{0163A995-471E-49B5-99F8-3FE73AFD52AE}" Name="ListID"></WebPartPages:DataFormParameter>
    </SelectParameters>
    <UpdateParameters>
      <WebPartPages:DataFormParameter ParameterKey="ListItemId" PropertyName="ParameterValues" DefaultValue="0" Name="ListItemId"></WebPartPages:DataFormParameter>
      <WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{0163A995-471E-49B5-99F8-3FE73AFD52AE}" Name="ListID"></WebPartPages:DataFormParameter>
    </UpdateParameters>
    <InsertParameters>
      <WebPartPages:DataFormParameter ParameterKey="ListItemId" PropertyName="ParameterValues" DefaultValue="0" Name="ListItemId"></WebPartPages:DataFormParameter>
      <WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{0163A995-471E-49B5-99F8-3FE73AFD52AE}" Name="ListID"></WebPartPages:DataFormParameter>
    </InsertParameters>
    <DeleteParameters>
      <WebPartPages:DataFormParameter ParameterKey="ListItemId" PropertyName="ParameterValues" DefaultValue="0" Name="ListItemId"></WebPartPages:DataFormParameter>
      <WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{0163A995-471E-49B5-99F8-3FE73AFD52AE}" Name="ListID"></WebPartPages:DataFormParameter>
    </DeleteParameters>
  </SharePointWebControls:SPDataSource>
</DataSources>

Is there something I'm missing here? I would have thought that filtering on [Current User] should work?

0

I can see where the problem is. What you are trying to do is not working because you used an EditForm, which by default, retrieves the item to be edited by ID. The relevant parameter here is ListItemId. Also, the DataSourceMode is, once again by default on an EditForm, set to "ListItem", which is wrong for your case.

You need to start from scratch, with an empty DataView. Then, click on "choose a data source", point to your list. At this point, select the fields you want to show in the form, and click on "Insert selected fields as" > "Single item form".

Now, click on Filter and add your condition with the [Current User] parameter. The datasource will now show "List" in the DataSourceMode property. Now, when you navigate to the page, you should see the question entered by the [Current User]. As a side note, this will work with the assumption that each user can insert a single answer. If you have multiple rows for the same user, the form will show only the first one.

  • Thanks MdMazzotti. So will this solution work if the user has not been on the page before, and therefore does not have a row in the list? – Jayden Lawson Feb 27 '14 at 14:25
  • If the user doesn't have a row, the form will show up empty (no fields will be shown). You can easily tell it from your xslt code, by testing the value of the dvt_RowCount variable (if = 0, then the user doesn't have any row). You may show something specific, like a message string, in this case to warn the user – MdMazzotti Feb 27 '14 at 14:33
  • I see - thanks. I guess that's the issue, as first time users of the page need to type in their intial response and save it. With the code I have been using, it does a simple test, and shows an "add" or "insert" form. After there are records, it displays the EditForm. Is there still a way to use your method, even if the user is on the page for the first time? – Jayden Lawson Feb 28 '14 at 3:01
  • I'm not quite following you...Why don't you simply use two separate pages, one for inserting and one for editing? In SharePoint we usually have 3 pages per list, a display form, a new form and an edit form. This helps keeping things easier. Anyhow, if you really want to have just one page for both inserting and editing, you should be able to use the same test you said you had done in your code. Or am I missing something? – MdMazzotti Feb 28 '14 at 9:01
  • It's because it is a course where the participant reads the page, then responds to questions and prompts, and must provide their answers next to the questions. It's ok though - I'll work with your answer and my previous code. Thanks for the help! – Jayden Lawson Mar 1 '14 at 12:42

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.