Sharepoint List Item View to Reflect Calendar View (How To?) - sharepoint

I have recurrence item in calendar, let's say it will repeat 5 times from start date 5/23/2018
In Calendar view, it will repeat the item from 5/23 to 5/28.
However in all item view(list view), it will only show once, it won't repeat the item 5 times.
Is there a way, to make list view replicate the calendar view?
Thanks

You can switch the view to "Current Events." In that view, recurrent events are displayed individually.

It can't be done using OOTB.
The best you get with OOTB is to create a view using view type 'Standard View, with Expanded Recurring Events.":
This will repeat the recurring item in the view
However this will only show event from today onwards(will not show past events)
The other way will be to code manually
It can be done using spservice and camlquery
var camlQuery = "<Query><Where><DateRangesOverlap><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='RecurrenceID' /><Value Type='DateTime'><Year /></Value></DateRangesOverlap></Where><OrderBy><FieldRef Name='EventDate' /></OrderBy></Query>";
var camlOptions = "<QueryOptions><RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion><ExpandRecurrence>TRUE</ExpandRecurrence></QueryOptions>";
// Make the web service call to retrieve events.
$().SPServices({
operation: "GetListItems",
async: false,
listName: 'Test Calendar',
CAMLQuery: camlQuery,
CAMLQueryOptions: camlOptions,
completefunc: function(xData, Status) {
$(xData.responseXML).find("z\\:row, row").each(function() {
console.log($(this).attr('ows_title'))
});
}
});

Related

sharepoint list item click event and value change

So my goal is to allow the user to click the item on the list and it automatically changes a value on the item. Mostly I want a easy to allow the user to mark the item as being read. This list will be updated every week, so it will allow the user to know what is new easier. I have already set up the views so the users can only see their own data on the personal view.
I have looked online and I'm not having great luck. This is what I have so far.
<script src="https://code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"></script><script type="text/javascript">
$(document).ready(function() {
$(".ms-listviewtable > tbody > tr").click(function(){ //only works before ajax runs
setTimeout( function() {
//alert("Hello! I am an alert box!!");
var ctx = SP.ClientContext.get_current("https://...");
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
var clientContext = new SP.ClientContext();
var oList = clientContext.get_web().get_lists().getByTitle('Ticket');
this.oListItem = oList.getItemById(items[0].id);
this.oListItem.set_item('read','yes');
this.oListItem.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}, 200); //had to be put in place to give time for the list to be selected
});
});
These are the issues I have.
the first time I click a item it tells be SP.ListOperation.Selection.getSelectedItems is null. However if I click the same item it will give me the ID number. Then if I click it a third time it will tell me its null again.
It does not change the vaule, but it does give me the right ID number after I click it two times.
EDIT,
see comments below
Using this code:
$("table.ms-listviewtable").on("mouseup", "tr.ms-itmhover", function() {
//your code
});

Getting tasks in the order in which they appear in a task list

In SharePoint task lists, we can Move Up or Move Down a task in the list. The web part in AllItems.aspx remembers the sequence. How do we retrieve (using CAML queries) the sequence in which these items appear?
Edit: I have tried ordering by date modified but apparently changing the order in which they appear in the task list does not influence this field.
The following CAML query allows to retrieve items in the same order as they have been adjusted via Move Up/Move Down buttons:
<Query>
<OrderBy>
<FieldRef Name="Order" Ascending="TRUE"/>
</OrderBy>
</Query>
Task list contains column called Order that stores those settings.
Here is an example that utilizes JSOM API:
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var list = web.get_lists().getByTitle(listTitle);
var items = list.getItems(createOrderQuery());
ctx.load(items);
ctx.executeQueryAsync(
function() {
//print items
items.get_data().forEach(function(item){
console.log(item.get_item('Title'));
});
},
function(sender,args){
console.log(args.get_message());
});
function createOrderQuery(){
var qry = new SP.CamlQuery();
qry.set_viewXml('<View Scope="RecursiveAll"><Query><OrderBy><FieldRef Name="Order" Ascending="TRUE"/></OrderBy></Query></View>');
return qry;
}

How to add button + to subgrid of hierarchical relation?

I have a hierarchical relation inside an entity X, I Have parent lookup which allow to give parent to a record of this entity, and I have created a Subgrid attached to this lookup within the same form of the entity:
The problem is that the display of the button + is unstable in this subgrid, sometimes it appears sometimes no. I dont know if this problem is related to some setting or it is a bug of dynamics crm online last version?
For information, I don't have this problem with other sub-grids.
Thanks in advance,
if you want to add a custom button you may do this as follows
function CreateButton() {
var connectionSubGridPlusBtn = document.getElementById("Connections_addImageButton").parentNode.parentNode;
//Connections_addImageButton is the id of + button
if (connectionSubGridPlusBtn != null) {
//New Button
var div = document.createElement("div");
div.className = "ms-crm-contextButton";
div.innerHTML = "<button id='newButton' type='button' style='width:80px;cursor: pointer;padding:0px' >New Button</button>";
connectionSubGridPlusBtn.appendChild(addVendorDiv);
//Event and url for new
document.getElementById("newButton").onclick = function () {
//Write codefor the button click event
}
}
}
call this function on load of the form
The entity has to be created before you're able to add related entities. You can add disable all required fields, and perform a save in the onload, and you should always see the plus sign.
A slightly better solution is to override the create button for the entity, and rather than directing to the create form, perform a rest entity creation, then direct to that form. Then you don't have to perform a save in the on load.

Problems importing SharePoint events into FullCalendar

I'm trying to get events from a SharePoint site and insert them into FullCalendar using the method described by Josh McCarty here.
An empty calendar shows up successfully using the snippets in Josh's article, however there seems to be an error when the Events List in SharePoint is being queried. I'm doing a slight modification from his example, because my List is in the host web site, not the app, so I have to use the webURL parameter.
When I look in the Chrome Dev console I see "Request format is unrecognized" as an error.
This technique uses SPServices, and a Caml query to fetch events, but I suspect something is wrong with my Caml.
My code (below) is almost verbatim from the example, but gives me an error at or around the line that I marked with debugger; //REQUEST FORMAT IS UNRECOGNIZED occurs here.
// Add events to the calendar. This is where the "magic" happens!
events: function( start, end, callback ) {
// Create an array to hold the events.
var events = [];
// Set the date from which to pull events based on the first visible day in the current calendar view.
// For a month view, this will usually be several days into the previous month.
// We can use FullCalendar's built-in getView method along with the formatDate utility
// function to create a date string in the format that SharePoint requires.
// It must be in the format YYYY-MM-DDTHH:MM:SSZ. Due to time zone differences,
// we will omit everything after the day.
var startDate = $.fullCalendar.formatDate( $( '#calendar' ).fullCalendar( 'getView' ).start, "u" ).split( "T" )[0];
// Get the current view of the calendar (agendaWeek, agendaDay, month, etc.).
// Then set the camlView to the appropriate value to pass to the web service.
// This way we will only retrieve events needed by the current view
// (e.g. the agendaWeek view will only retrieve events during the current week rather
// than getting all events for the current month).
var calView = $( '#calendar' ).fullCalendar( 'getView' ).title;
var camlView = "";
switch( calView ) {
case "agendaWeek":
camlView = "<Week />";
break;
case "agendaDay":
camlView = "<Week />";
break;
default: // Default to month view
camlView = "<Month />";
}
// Set the camlFields, camlQuery, and camlOptions to the appropriate values to pass to the web service.
// You can add additional <ViewFields /> or adjust the CAML query if you have some custom columns that
// you want to filter by or display data from. The values below are the pretty much the minimum you'll
// want to start from to get it working.
var camlFields = "<ViewFields><FieldRef Name='Title' /><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='Location' /><FieldRef Name='Description' /><FieldRef Name='fRecurrence' /><FieldRef Name='RecurrenceData' /><FieldRef Name='RecurrenceID' /><FieldRef Name='fAllDayEvent' /></ViewFields>";
var camlQuery = "<Query><CalendarDate>" + startDate + "</CalendarDate><Where><DateRangesOverlap><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='RecurrenceID' /><Value Type='DateTime'>" + camlView + "</Value></DateRangesOverlap></Where><OrderBy><FieldRef Name='EventDate' /></OrderBy></Query>";
var camlOptions = "<QueryOptions><CalendarDate>" + startDate + "</CalendarDate><RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion><ExpandRecurrence>TRUE</ExpandRecurrence></QueryOptions>";
var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
debugger;
// Make the web service call to retrieve events.
$().SPServices({
operation: "GetListItems",
async: false,
webURL: hostUrl,
listName: paidTimeOffListName, // This is the GUID or display name of your calendar. If the calendar is on a different site, you can use the display name with the webURL option (see SPServices.CodePlex.com for more information).
CAMLViewFields: camlFields,
CAMLQuery: camlQuery,
CAMLQueryOptions: camlOptions,
completefunc: function( xData, Status )
{
debugger; //REQUEST FORMAT IS UNRECOGNIZED occurs here.
//.find( '[nodeName="z:row"]' ) unsupported past jQuery 1.7
$(xData.responseXML).SPFilterNode('z:row').each( function()
{
debugger;
// Check for all day events
var fADE = $( this ).attr( 'ows_fAllDayEvent' );
var thisADE = false;
var thisStart = $( this ).attr( 'ows_EventDate' );
var thisEnd = $( this ).attr( 'ows_EndDate' );
if ( typeof fADE !== "undefined" && fADE !== "0" )
{
thisADE = true;
}
// Get the list item ID and recurrence date if present. This will be used to generate the ID query string parameter to link to the event (or the specific instance of a recurring event). The ID query string parameter must be in the format "ID.0.yyyy-MM-ddTHH:mm:ssZ" for recurring events (where "ID" is the list item ID for the event). Event ID's are returned as just a number (for non-recurring events) or several numbers separated by ";#" in 2007 or "." in 2010 to indicate individual instances of recurring events. By splitting and joining the ID this way, thisID will be set to a valid query string parameter whether an event is recurring or not for both versions of SharePoint.
var thisID = $( this ).attr( 'ows_ID' ).split( ';#' ).join( '.' );
// FullCalendar documentation specifies that recurring events should all have the same id value when building the events array (the id is optional, but I'm including it for completeness). We can get the list item ID (which is the same for all instances of recurring events) without the recurrence information by simply splitting thisID.
var eventID = thisID.split( '.' )[0];
// Get the event title. This is displayed on the calendar along with the start time of the event.
var thisTitle = $( this ).attr( 'ows_Title' );
// Get the event description. I don't use it in this example, but you could use it for something, perhaps as a tooltip when hovering over the event.
var thisDesc = $( this ).attr( 'ows_Description' );
// Add the event information to the events array so FullCalendar can display it.
events.push({
title: thisTitle,
id: eventID,
start: thisStart,
end: thisEnd,
allDay: thisADE,
// Adjust this URL to link to the display form for your calendar events. You can include a Source parameter to allow users to easily return to the FullCalendar page.
url: '/Lists/Calendar/DispForm.aspx?ID=' + thisID + '&Source=' + window.location,
description: thisDesc
});
});
callback( events );
}
});
}
I believe I've figured out what the problem is, although unfortunately, it seems to be unfixable.
SPServices won't work cross-domain (as far as I can tell), and since I'm trying to make this call from inside of a SharePoint app to a list not stored in the app, it's considered a cross domain request.
One workaround would be to use something else to get the info, such as REST.
EDIT: Info in the article here seems to contradict my belief:
SPServices supports anonymous access to read from lists, and it works cross-site and cross-domain by simply specifying the webURL in the Web Service operations where it makes sense to do so. Of course, your authentication model has to allow cross-domain access.
So perhaps it is possible.

SharePoint 2007 : Get all list items in a list regardless of view from web service?

I need to check for duplicates. Currently I have items stored in sub folders in a list.
How can I retrieve all items in the list from a web service, so I can check for duplicates?
Here is code from object model: I want to do exactly this, but from a web service
private static void PrintItemTitles()
{
string strUrl = "http://localhost:8099/";
using (SPSite site = new SPSite(strUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["MyList"];
SPListItemCollection items = list.Items;
foreach (SPListItem item in items)
if (item != null)
Console.WriteLine(item.Title);
}
}
}
Use SPList.Items doesn't return all items? Well, then try SPList.GetItems(SPQuery).
Have a following SPQuery:
SPQuery query = new SPQuery();
query.ViewFields = "<FieldRef Name='ID'/><FieldRef Name='Title'/>";
query.Query = String.Format("<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{0}</Value></Eq></Where>", someItemTitle)
query.MeetingInstanceId = -1; //In case if you query recurring meeting workspace - get items from all meetings
query.RowLimit = 10; //Will you have more than 10 duplicates? Increase this value
query.ViewAttributes = "Scope='RecursiveAll'"; //Also return items from folders subfolders
Note: There could be some mistakes in code, because i`m writing from top of my head
By executing this query and if it returns more than one item, then you have a duplicate!
Edit: Ahh, sorry, you are talking about Web Services.
Then this code won't help. There are 2 options then:
Option 1: You CAN create a view that
does include items even from folders
(flat view). See here for
instructions.
Option 2: According to Lists Web Service's GetListItems method, you can pass QueryOptions parameter. Pass in
<QueryOptions>
<MeetingInstanceID>-1</MeetingInstanceID> <!-- Again, if you query recurring meeting, you want ALL items -->
<ViewAttributes Scope='RecursiveAll' /> <!-- or Recursive if that does not work -->
</QueryOptions>
Good luck!
You can use the Lists.asmx web service, but that is quite hard to do as it returns quite a lot of information. I would deploy a custom web service on my SharePoint environment that contains that code and returns the list items.

Resources