Get listitems from Current Site - sharepoint

I am trying to create a Page Layout, that should have a lookup field. Lookup field should always get populated with a list's items.
This list will exist in all subsites, so whereever I create this page, list should get populated with listitems from current site.
I tried using site column lookup field, but it always point to list under top site and not the current site.
Any suggestion on how to make it work or better alternative? Thanks!
Let me know if I can provide more info.

The most straightforward solution I can think of is using a cross site lookup column and creating a seperate fields for each subsite. However, you will need to create and use different Page Layouts for each subsite.
You can use http://sp2010filteredlookup.codeplex.com/ for cross site lookups.

Solution 1 - Use http://sp2010filteredlookup.codeplex.com/
Use filtered lookup solution. So let's say you have your custom Page Layout and custom Page Content Type.
Every time you create new subsite, you should remember go to Pages list settings and edit Page Content Type by adding cross site lookup (with the same field "internal name").
So you still have one Page Layout (and one Content Type). But for each Pages library instance, Content Type contains diff fields (but with the same Internal Name). It will allow you run CAML queries and other things needed without any problems.
Solution 2 - develop custom sharepoint field type.
In edit mode, control will render "dropdown list" and populate data from list instance that is on current subsite. In the field settings you can have relative list url.
Solution 3 - hidden text field / js snippet solution
Page Content Type can contain hidden text field (it can contains selected field value in json format for example). Develop js snippet that will handle all the logic (rendering in edit/view mode, saving etc) and put it on Page Layout (aspx).
I would suggest to use solution #1 or #2.

Related

Liferay: Dynamically populate 'select' structure field

I am building a liferay theme, which has two columns side by side. The right column is where the web contents will be displayed.
My implementation aims to build a menu (left column) that gets the titles from the web content titles and builds hierarchy (parent, child) based on a 'select' structure field that I added to each web content.
So far I was able to build this system using
Liferay.Service('/journalarticle/get-articles'...)
and some javascript coding.
Now the 'select' fields i use in my structure have predefined hard coded options.
How can i populate dynamically this option list so that whoever is managing content will automatically have all titles from all web contents available to choose a 'parent' from? So far a developer has to update this option list each time there is a new web content added.
#chadct : AFAIK Liferay not provide this default functionality, this is not good practice to populate dynamically value in structure field. But you wanted to achieve that functionality, then there are 4 solution :
Add one text field in structure which contains articleId of your parent web content.
You can add related article for that web content and write some sort of code to get article which consider as a parent of that web content.
Create Select DOM options form template which hold the list of article according to groupId and render on web content view mode, then you can select parent content from there and update content expando with articleId of parent webcontent. Remember this contains AJAX post request. and only show that control who is admin or loggedin user or depends on Role. Refer AJAX post calling
Hook edit_structure.jsp and add your logic here as you want.
Note : last one is worst but also a solution, Remember you need to modify your current solution.

TreelistEx field with Search

I have a requirement from a client to modify the treelistex field to include a search box on top of the left content tree list box. This will allow searching of items instead of the user having to click through the content tree. This Sitecore installation has pages numbering in the thousands hence clicking through takes time and knowing where the page item exists.
How can I achieve this functionality? I will use the _system Lucene index from Sitecore to search the various items. The items need to be search based on item name, title field, content field and date fields.
Thanks
Interestingly, something just like this was posted to Shared Source the other day! Check out the Specialized Treelist from Shared Source.
Search using the built in Sitecore Lucene indexes

SharePoint 2010 List developing a custom AddForm and EditForm

I have a SharePoint list that has MANY columns in it. The default AddForm and EditForm rendering is very cumbersome for the users. Most of these fields hold simple Number (integer) values. The default rendering for those two forms (using the ListFieldIterator I suppose) render the columns one by one vertically down the page. My thought was to design an input form with three basic "zones" (left/middle/right) and use a Custom Field for all of these "Number" fields. The Custom Field would contain two custom variable properties "Zone" and "Order". (Zone could contain middle/right and order would be the "order" in that zone the field would appear, the "left" zone would be for the fields that are not these "Number" fields, things like Date, Customer, etc. etc.) I would design the page with an HTML table and 6 Columns (1 for the "label" and one for the "TextBox" for each of the three "zones"). Then I could put a control (something similar to the "ListFieldIterator"). The control in the first zone would render the "static" fields, the zones in the other two zones would render the appropriate Custom Fields (based on the Custom Variable Property "Zone" and "Order").
Does this make sense? For the life of me, I can't figure out how to do this. I had thought about "giving up" and just using my ASP .Net skillset and creating FormViews and GridViews bound to the proper (ListView) DataSources. That has even proved challenging.
Does anyone have any ideas on how I could accomplish this? (InfoPath isn't an option and I want to stay with the "Custom Field" idea so the fields aren't laid out statically and can be moved around or even new ones added by the "administrator" of the Application (SharePoint List).
Any guidance is MUCH appreciated. I have been working on this all week and just seem "stuck".
Thanks,
Shayne
------ A Better explanation of my "application" and what I want to do-----
I have a SharePoint List that has about 60 fields in it. If I pushed this application out using the default Add/Edit SharePoint List Forms (and Rendering Templates), the users would hate it. The default forms use a rendering template that basically lays out all the list fields, one per (HTML) Row. Within that Row there are two (HTML) columns. The first one contains the "Label" for the field, and the second (HTML) column is the actual editor for the "FormField" (Text Box or whatever). Because of the number of fields in the list, the user would have to scroll several pages just to get to the bottom.
This list has about 10 "static fields" that I want to lay out on the left side of the page and then about 50 that are simply "task" fields. These store an integer and track "how many of these tasks did I do today". (This is a "port" of an MS Access application.) Depending on the "Add" page the user selects (I have a "parent" content type that contains every field and then a "child" content type for each "group" of users that will be using this form that contains just the fields/tasks that group tracks) the proper fields are rendered on the page. The problem is they are all rendered vertically and there is too much scrolling. These users (and admins) will NOT have access to SharePoint Designer or InfoPath. So, the "layout" for these fields must be iterator/repeater style (the users shouldn't have to get Development involved just to add a new "task" field to their application!).
The solution I had come up with is to use a Custom Field Type with two Custom Property Variables for each of these "task" fields. The Custom Property Variables (Zone and Order) would allow the administrators of the "application" to control where they want these fields to appear on the Add and Edit forms. The Zone Property can contain one of two values: "1st Task Column" (middle of the form) or "2nd Task Column" (right part of the form). (The "left" column of the forms would be used for those 10 or so "static" fields that all groups/depts/content types share.)The Order would just contain the order to sort the fields in, within their "zone". Obviously, the "zone" would indicate where on the form the field would appear (middle or right). I thought I might be able to use three Divs and render the appropriate List Columns in the appropriate DIVS. Or, following the default rendering template, instad of DIVs I could possibly use 6 (HTML) Columns instead of 2.
I quickly figured out how to make a new Field Type with Custom Properties (I used the Property Schema element in the XML definition, even though Microsoft says NOT to use that in SharePoint 2010, it was just so easy and I couldn't figure out how to add them otherwise. Now I know how to add them the "right" way, I just don't know if it is worth changing them.)
For the last few days, I have tried to figure out how to actually render these "zones". Remember, I want the users of this application to be able to add new fields dynamically, so I can't put any static field references in these forms. I have read about the Rendering Templates and the ListFieldIterator (and the new Content Iterator), but I can't seem to pull it all together and create an actual solution. The part that is throwing me off is how to query and render three different "sets" of fields at once (since the rendering is going to happen from "top to bottom").
Any help is very much appreciated!
Shayne
If InfoPath it out and you want to stay within the SharePoint infrastructure for forms, then the term you need to search for is DataFormWebPart. You may have heard of DataViewWebPart before, well this is the form equivalent. Just like the DVWP, this does lots and lots of XSLT to make its magic happen.
The trick is can you implement your grid/zone idea within the context of the DFWP's XSL. That I can't tell you but hopefully this is a starting point.
Defiantly Info Path is the solution here are some tutorials:
Video: http://channel9.msdn.com/blogs/laurhar/infopath-2010-customize-a-sharepoint-list-form
http://p2p.wrox.com/content/articles/customizing-sharepoint-2010-list-forms-infopath-2010
http://blog.libinuko.com/2010/03/21/sharepoint-2010-howto-start-customize-list-form-neweditview-using-infopath-designer-2010/
if you don't want to use InfoPath I would recomment JavaScript/jQuery you have just to modify (Edit) the page then inject some jQuery code to do what you want. Here are some articles about similar topics:
http://akanoongo.blogspot.com/2008/04/how-to-hide-fields-in-sharepoint-list.html
http://spground0.blogspot.com/2011/03/sharepoint-2010-custom-list-form-issues.html
http://ghamson.wordpress.com/2011/01/19/using-jquery-to-attach-regular-expression-validation-to-a-sharepoint-list-form-field-sp2010-ps2010-projectserver-in/
The only way you can achieve this type of custom form designing within the SharePoint framework is to apply it through post-rendering techniques using client-side code. And solutions like this tend to add considerably to page-load.
Simply changing the render template is not enough if you want it to be a dynamic and codeless experience for end users to author.
I can think of only one solution which comes close to fitting all criteria. It's "free", can be password protected, and also allows tab groups, rules and many other settings.
Dynamic Forms For SharePoint - http://spjsblog.com/dffs

Sharepoint: Change page layout and content type for specific page

I have a page layout in a solution I have deployed. The page layout also has a custom content type associated.
I wish to update this page layout and content type, but only for a specific place on the site. The reason is that for important "operation updates" we want the ability to send out SMS's to subscribed users (a built-in feature of Sharepoint for lists) as well as e-mail them.
The way this works is that I wish to add a boolean field that decides whether SMS's are send or not, and a field to put in e-mail adresses you want notified of the message.
My approach so far has been:
Create an event receiver that checks whether the fields are selected / filled out and do the actual sending.
Alter the layout page with the 2 new fields.
Alter the content type with the 2 new fields.
However, I am afraid of the complications for the rest of the site. For now, future uses of the page layout is not a concern, just the existing uses.
I know that updating a content type through XML definitions does not happen automatically, so on that side I'm safe, but how do I keep the layout page "contained" to the specific page in question?
EDIT: How do I show the two fields only when editing the page, not when showing it? Currently, my development site shows the edit form just right, but when I go to show the page it shows "yes" where boolean field is located and any e-mail adresses entered where the e-mail field.
Are you sure the page layout is associated with the content type, and that it's not a page that is associated with the content type?
If you want fields to be automatically added, you can:
Create a custom rendering template
that is used by the New/Edit/Display
forms for your list
(http://weblogs.asp.net/sharadkumar/archive/2008/07/07/how-to-customize-rendering-of-sharepoint-list-form-fields-part-1.aspx)
Create a custom ListFieldIterator (or use the default one)
that will automatically pick up new
fields in your content type
(http://msdn.microsoft.com/en-us/library/aa543922.aspx)
Use code in a DLL to iterate through
your content type's fields and thus
create the necessary controls for
your page all in code. If you use
FieldControls
(http://msdn.microsoft.com/en-us/library/dd571480.aspx),
it will automatically create the
default template rendering for the
field (i.e., it will display radio
buttons, drop down boxes, etc., as
defined by the fields in the content
type).
In your EDIT, when you say 'when editing the page', I'm assuming you mean 'when viewing the edit page for the list', and not 'when editing the page definition in Sharepoint Designer'.
Assuming that assumption is accurate, you can have the edit page for the list show something completely different from the view page for the list (and from the new page for the list). The pages are, by default, defined completely separately, and are edited completely separately. However, if you are using something (such as the ListFieldIterator) that automatically picks up the list of fields for the content type, you can create a custom Field Control for the fields you want to hide and have the view template for the field control set to display nothing.

Placing Share Documents subfolder as a webpart in SharePoint

I want to place a Webpart on a page that holds a subfolder of the Document Library in SharePoint, but somehow, the only thing I get is the root folder of the document library.
Is there a Webpart that fills this need?
Here is how to do it in Sharepoint 2010 with only Javascript, no SharePoint Designer necessary.
create a document library web part on your web part page
change the view to show all items without folders and set the item limit to a sufficiently large number so that there are no batches
add Content Editor web part below document library web part
Add the following javascript and change the the first variable to meet your needs
Note: If you have more than one Document Library web part, you will need to add to this code.
<script type="text/javascript" language="javascript">
//change this to meet your needs
var patt = /FOLDER%20TO%20SEARCH/gi;
var x = document.getElementsByTagName("TD"); // find all of the TDs
var i=0;
for (i=0;i<x.length;i++)
{
if (x[i].className =="ms-vb-title") //find the TDs styled for documents
{
var y = x[i].getElementsByTagName("A"); //this gets the URL linked to the name field
//conveniently the URL is the first variable in the array. YMMV.
var title = y[0];
//search for pattern
var result = patt.test(title);
//If the pattern isn't in that row, do not display the row
if ( !result )
{
x[i].parentNode.style.display = "none"; //and hide the row
}
}
}
</script>
By default I don't think that is possible.
The list web part that would show the Shared Documents understands how to render the library, but doesn't understand how to filter to only show the contents of one subfolder.
It would be nice to create a Filter Web Part and to provide that filter to the List web part so that it filters according to the sub folder defined within the fileref field of the document library. However the filters it appears to be able to consume are Type, Modified and Modified By. So you could filter it to just the documents you touched, but not the ones in a given location.
End result: Roll your own web part.
The reason is that the folder selected by the webpart is not controlled by the webpart itself, but by a querystring parameter.
e.g.
"?RootFolder=%2fDocuments%2fMyFolder1&FolderCTID="
So folders are not "real" folders as such, despite the "lie" that is the webdav interface
e.g. \\sharepointsite\documents
There should be a way of including the desired RootFolder parameter, like a linking to the page with the querystring included (far from ideal).
I do not know of any webparts that do this.
I was able to do this by creating a new Column and specifying a keyword for the entire Shared Documents list.
Then I had to add metadata.
Add the WebPart again to the page.
Create a View that enabled the display of the files as a flat list, and filter on the new Column (i.e. where Keyword is/contains ----).
Then I get the list I want on the page with the web part.
I have a work around I've used that doesn't required Designer. Not as elegant, but achievable by any power user.
After you've added the library web part, go to the page and click down to the folder you want to be the default. See that the page link now shows something like :
www.mysite.com/sharepoint/default.aspx?RootFolder=%2Fsubfoldername&FolderCTID=...
Copy that link. Delete &FolderCTID and everything that follows. In this case what remains is :
www.mysite.com/sharepoint/default.aspx?RootFolder=%2Fsubfoldername
Use this link for navigation to the page and the library will display as you want within that page. Be aware it does not replace the default view for that page.
Another way of face this issue would be to just use the Content Search WebPart ( CSWP ) and filter the results based on :
folder path
url depth
You will need a UrlDepth value that matches your requirement. The best thing is to use a high value, like 10, and then reduce until it shows just the files you need.
Regarding folder path, remove the (quotes) ", this way the query will perform a "contains" lookup, instead of "equal to":
Result will be something like this:
path:[your site]/Docs/our_team UrlDepth:7
If the folder name contains spaces, you may need to wraps it with quotes. something like:
path:[your site]/Docs/"our team"
One alternative I've used is to drop a Page Viewer Web Part on the page and choose "Folder" as the type of thing to view. Then specify the webdav UNC to the folder such as "\some_sharepoint-site\some_site\shared documents\some_folder\"
Place the document library list view web part on any page.
Edit the web part.
From filter select column "Content Type" and value "Folder"
Save and you are done.
By doing that it will show you root folder files only.

Resources