Sharepoint 2010 event receiver ItemUpdated fires twice - sharepoint-2010

I attach three events to my CustomLists:
ItemAdded
ItemUpdated
ItemDeleting
On one list I have a workflow, which is changing columns in that list. So when I edit an entry in that list, the ItemUpdated-Event fires two times. On the other lists (without any workflows) my receiver is working fine.
How can I find out if a workflow called my event receiver?
Is there a difference between a workflow which fires the event, or a user who fires the event?

You can add hidden field to the list which is always sets by workflow (and only by workflow). Then you will see if workflow called the event receiver.
Or
You can create HandleEventFiring class in your workflow project and use DisableAllEventFiring and EnableAllEventFiring before and after updates in workflow
public class HandleEventFiring : SPItemEventReceiver
{
public void DisableAllEventFiring()
{
this.DisableEventFiring();
}
public void EnableAllEventFiring()
{
this.EnableEventFiring();
}
}

To answer your first question:
Yes, you can find your workflow. The easiest way would be to use the SharePointManager 2010 and
Navigate to your site collection is located
Lists -> [Your List] -> Event Receivers
Check each Event Receiver's properties and delete the event receiver that is firing twice.
I don't know if I understand your second question correctly, but here goes:
A workflow can be started manually by a user or automatically if a List Item is
Added
Updated or
Deleted
Other than that there is not much of a differance.

Related

How to add event listeners for appointment item in outlook taskpane add in?

I have been following this example for adding event listeners but it doesn't work. Is there any way to listen when changes are made while creating an appointment in calendar (i.e. when attendees are added)?
The link I followed:
https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/pinnable-taskpane#implement-the-event-handler
I need to create a taskpane that will display emails as they are added as attendees.
To listen for when attendees are added in calendar, you can register for the RecipientsChanged event. This event triggers when the recipient list of the selected item or the appointment location is changed in Outlook. Support for this event was added in requirement set 1.7. Documentation about this event can be found here. Supported events include RecurrenceChanged, RecipientsChanged, and AppointmentTimeChanged.
To add the event, you would need to call addHandlerAsync like:
Office.context.mailbox.item.addHandlerAsync(Office.EventType.RecipientsChanged, handler, callback);
where you can specify the handler and callback. Documentation for addHandlerAsync can be found here.

How to get the user's new page selection in a Notebook control under Windows?

In my app, when a user has made changes to the data on one page of my notebook control, I want to prompt them to save or discard their changes when they switch to a different page. I have bound the EVT_BOOKCTRL_PAGE_CHANGING event for this, and have created a handler method.
However, I can't tell what page the user is switching to. According to the wxBookCtrlEvent docs,
under Windows, GetSelection() will return the same value as GetOldSelection() when called from the EVT_BOOKCTRL_PAGE_CHANGING handler and not the page which is going to be selected.
Is there a workaround?
I guess as a workaround, you could use a mouse handler checking for when the left button is clicked. In a handler for that event you could do a hit test to see where the click was made and store the value of the tab that was clicked. Something like this:
void MyFrame::OnLeftDown( wxMouseEvent& event )
{
long flags;
int ht = m_notebook1->HitTest( wxPoint(event.GetX(),event.GetY()), &flags);
if( (flags & wxBK_HITTEST_NOWHERE) == 0 )
{
//store the value of ht somewhere
}
event.Skip();
}
void MyFrame::OnNotebookPageChanging( wxNotebookEvent& event )
{
//use the stored value of ht here
}
under Windows, GetSelection() will return the same value as
GetOldSelection() when called from the EVT_BOOKCTRL_PAGE_CHANGING
handler and not the page which is going to be selected.
So, call GetSelection from EVT_BOOKCTRL_PAGE_CHANGED to get the new page.
No, there is no workaround (if there were a reliable way to do it, wxWidgets would have been already doing it), the underlying native control simply doesn't provide this information.
You can either ask whatever you need to ask the user about in any case, independently of the page they're switching to, or ask them after they will have already switched -- which is, of course, going to look weird if you then decide to switch back.
If you really, really need this functionality, you might use non-native wxAuiNotebook instead.

How do I add/remove density colors on the Windows Universal App CalendarView control after loading?

CalendarViewDayItemChanging seems to be the way to add 'density colors' (coloured bars in a DayItem box) to a Windows Universal App CalendarView.
However CalendarViewDayItemChanging is only fired when the DayItem box is loaded i.e. on initial loading and possibly when navigating to a far enough date and back again such that the virtualisation re-loads the DayItem.
However when I create an appointment on the selected date I need to add a density color bar immediately, similarly if I remove an appointment, I need to remove that bar.
How do I get the control to reload or re-render that particular DayItem?
Notes:
There is only the SelectedDates available as a property
There is no obvious way to ge the DayItem collection
Setting the Visibility to Collapsed then Visible instantaneously does not trigger a reload.
There was a similar issue on the MSDN blogs here: https://social.msdn.microsoft.com/Forums/en-US/54c81ada-4147-474b-8425-524ec69bc749/uwp-calendarview?forum=wpdevelop
I think your best bet currently is to have your Appointment creation on a separate page and store a List of Appointments locally or in a db. That way when you navigate back to the Page with your calendar view you can reload the Calendar using the updated Appointment list.
I used the MyCalendarView.UpdateLayout method to force the control to hit the CalendarViewDayItemChanging event again.
I called the method from the DataContextChanged event on my UserControl. This way anytime I change the DataContext the density colors get updated. This is sufficient for my needs. It sounds like you want to do it on a different event.
private void UserControl_DataContextChanged(Windows.UI.Xaml.FrameworkElement sender, Windows.UI.Xaml.DataContextChangedEventArgs args)
{
if (this.DataContext is ObservableCollection<Event>)
{
eventCalendar.UpdateLayout();
}
}

Data into classes, timing, procedure

I have a style/good code question. It's one of those "not that important because it's working" things but still, I'd like some insight from the community. I'm in C# but the methodology could apply to anything OOP
So I have a class, it's essentially a container for data. I pass the class to the database instead of passing 10 parameters. The database writing class drops each data member into it's respective SQL parameter and executes the stored procedure in my database.
My question is, when I am collecting data into the class I have all of them attached to Change events. Like
private void chkIce_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
if (chk.CheckState == CheckState.Checked)
outTruck.setWeather(2, true);
else
outTruck.setWeather(2, false);
}
and
private void txtTrailer_TextChanged(object sender, EventArgs e)
{
TextBox txt = (TextBox)sender;
newRecord.TrailerNumber = txt.Text.ToString();
}
This goes in and sets the ice value of my class to true/false based on what the user selects. Or sets the text. It's pretty straightforward, but there is a bit of code overhead as in each control has it's own event (also the cast on sender line might be overkill). The other way would be to collect all the data at submit. Drop it all into the class then. There was something else called entity framework and ORM, but I am at the moment stuck in .NET 3.5(we are with the times) and I've read that does not apply until you get to 4.0. I've not really read if there is a standard, it seems to be more preference than anything. So, fellow stack overlowieans...what are your thoughts?
Since it looks like you're in a web page with post back, I think it's easier to have that submit button handler functions where you instantiate your object, and manually set each property to the value of its corresponding UI element. Doing the data setting on every event handler (selection changed, focus out, etc.) would require the entire page to reload. (Then, you would have to persist that object across those post backs - a tedious and error prone feat, though doable.)
Even in a desktop project, I would collect all of the values from all UI elements to build my object, in that submit button's event handler.
You would want to implement event handlers on certain UI elements if the change of state in that UI element will affect something other than the object itself. For example, a checkbox may determine whether or not the user will be able to submit - because checking it so might add a feature that costs more where the total price of their order might exceed their current balance. This is when you would check to see whether the submit button should remain enabled or become disabled.

List item event receiver on lists in multiple webs - SharePoint 2010

I have multiple webs instantiated using the same template. When the web is created a custom list is created as well. Is there a way to define a global event receiver to handle to handle the ItemAdded event for all the lists defined with that template?
No, i don't think this is possible. But you can register your event receiver on the custom list within the template, and all your (newly created lists, obviously) will have the event receiver registered automatically.