The task in hand was to update a SharePoint list programmatically. I followed Microsoft's instructions as described in http://msdn.microsoft.com/en-us/library/ms440289.aspx to no avail.
The funny thing was I had used this same code on the companyweb home page and it worked. But it would not on this subsite.
The UpdateListItems method would silently fail. The following error message was logged:
List does not exist The page you selected contains a list that does not exist. It may have been deleted by another user.
After quite a few hours double checking field names, changing permissions, etc. I found where the problem was. I was using:
listService.Url = "http://companyweb/_vti_bin/Lists.asmx"
and I should have been using:
listService.Url = "http://companyweb/Subsitename/_vti_bin/Lists.asmx"
You have to use the correct location for the web service when the list is located in a subsite.
Happy SharePointing!
Monday, August 29, 2011
Monday, May 16, 2011
Data View Web Part: generating a consecutive number.
Task in hand: A Data View Web Part pulls a list of records. The "ComplaintNumber" field is the primary key. I needed the UI generate a complaint number when a new record is being inserted.
Solution: In my AllItems.aspx I had this automatically generated code:
<td class="ms-vb">
<asp:TextBox runat="server" id="ff5{$Pos}" __designer:bind="{ddwrt:DataBind('i',concat('ff5',$Pos),'Text','TextChanged','ComplaintNumber',ddwrt:EscapeDelims(string(@ComplaintNumber)),'@ComplaintNumber')}" />
</td>
Which allows replacing the value of the ComplaintNumber field in the database by whatever number the user enters.
Under <xsl:template name="dvt_1.rowinsert"> I added the following line:
<xsl:variable name="mynewcomplaint" select="(/dsQueryResponse/NewDataSet/Row[position()=last()]/@ComplaintNumber)+1"></xsl:variable>
mynewcomplaint stores the value contained in the last node + 1 (e.g. if the last complaint number in the database is 15 then mynewcomplaint=16. Note that the expression position()=last() is evaluated and if the calculation returns true, the item is included in the rowset; if it returns false, the item is not included. Therefore, only the last item is included in this case.
Finally I added the text attribute to the Text Box and assigned to it the value of mynewcomplaint:
<td class="ms-vb">
<asp:TextBox runat="server" id="ff5{$Pos}" text="{$mynewcomplaint}" __designer:bind="{ddwrt:DataBind('i',concat('ff5',$Pos),'Text','TextChanged','ComplaintNumber',ddwrt:EscapeDelims(string(@ComplaintNumber)),'@ComplaintNumber')}" />
</td>
This way, when the user clicks on the "New" link ( <a href="javascript: {ddwrt:GenFireServerEvent('__cancel;dvt_1_form_insertmode={1}')}">New</a> ) a new complaint number appears in the text box.
Cheers!
Solution: In my AllItems.aspx I had this automatically generated code:
<td class="ms-vb">
<asp:TextBox runat="server" id="ff5{$Pos}" __designer:bind="{ddwrt:DataBind('i',concat('ff5',$Pos),'Text','TextChanged','ComplaintNumber',ddwrt:EscapeDelims(string(@ComplaintNumber)),'@ComplaintNumber')}" />
</td>
Which allows replacing the value of the ComplaintNumber field in the database by whatever number the user enters.
Under <xsl:template name="dvt_1.rowinsert"> I added the following line:
<xsl:variable name="mynewcomplaint" select="(/dsQueryResponse/NewDataSet/Row[position()=last()]/@ComplaintNumber)+1"></xsl:variable>
mynewcomplaint stores the value contained in the last node + 1 (e.g. if the last complaint number in the database is 15 then mynewcomplaint=16. Note that the expression position()=last() is evaluated and if the calculation returns true, the item is included in the rowset; if it returns false, the item is not included. Therefore, only the last item is included in this case.
Finally I added the text attribute to the Text Box and assigned to it the value of mynewcomplaint:
<td class="ms-vb">
<asp:TextBox runat="server" id="ff5{$Pos}" text="{$mynewcomplaint}" __designer:bind="{ddwrt:DataBind('i',concat('ff5',$Pos),'Text','TextChanged','ComplaintNumber',ddwrt:EscapeDelims(string(@ComplaintNumber)),'@ComplaintNumber')}" />
</td>
This way, when the user clicks on the "New" link ( <a href="javascript: {ddwrt:GenFireServerEvent('__cancel;dvt_1_form_insertmode={1}')}">New</a> ) a new complaint number appears in the text box.
Cheers!
Subscribe to:
Posts (Atom)
Famous quotes
Even if you do learn to speak correct English, whom are you going to speak it to?
Clarence Darrow (1857 -1938)
Clarence Darrow (1857 -1938)