Plugin Developer Discussion

Discussion for FogBugz Plugin developers

BugEvent sChanges

When I change a Plugin Field value (for a 3rd party plugin) via the Bug page, the change is recorded in the sChanges filed of the BugEvent table.

I've written my own plugin for a report, and I want to update this field and have the bugEvent display the sChanges like normal, but I can't seem to record the event for sChanges, and I couldn't find any solid documentation.

Here's the summary of my calls:

==================

CBug bug = api.Bug.GetBug(Convert.ToInt32(api.Request[api.AddPluginPrefix("ixBug")]));
                
bug.SetPluginField("customfields@fogcreek.com","billable",api.Request[api.AddPluginPrefix("billValue")].ToString());

CBugEvent bugEvent = api.BugEvent.GetBugEvent(bug.Commit());

bugEvent.AppendChangeLine(String.Format("'Billable' changed from {0} to {1}",bug.GetPluginFieldOrig("customfields@fogcreek.com","billable"),bug.GetPluginField("customfields@fogcreek.com","billable")));


======================================================


Keep in mind a few things:

1)  This DOES successfully update the Billable plugin field.
2)  I CAN record the event with standard "Notes" style text (in the 's' column of BugEvent table), but what I'm trying to do is simply record the bug change in the 'sChanges' field.

I can't seem to figure this out. 

Thanks for your help!
David Wilson Send private email
Tuesday, December 22, 2009
 
 
Hi David-
I think you just want to use the AppendChangeLine method on BugEvent. Does that make sense?
http://www.fogcreek.com/fogbugz/library/70/html/4E5ED9EE.htm
Thanks!
Brett
Brett Kiefer Send private email
Wednesday, December 23, 2009
 
 
Brett.  I did that (you can see it in the code above), but while it updates the object in memory, it does not save the changes to the database.

I eeven tried doing a second "bug.Commit()" after that line, but still it didn't work.  All that said, I finally figured it out for myself... so for anyone else having this issue, here's the solution I found:


1)  First, Implement the Interface 'IPluginBugCommit'.  (It's part of FogCreek.FogBugz.Plugins.Interfaces, which you'll likely already have a 'using' statement for).

2)  The interface has 3 Method Members (BugCommitBefore, BugCommitAfter, and BugCommitRollback).  These expose the CBug and the associated CBugEvent objects, so that we can access the CBugEvent during the commit (rather than after the commit like my code was doing before).

3)  Here's my final code.  It has my update method, as well as the BugCommitBefore method that I took advantage of:

=================================================
protected void UpdateBillable() {
    CBug bug = api.Bug.GetBug(Convert.ToInt32(api.Request[api.AddPluginPrefix("ixBug")]));
    bug.SetPluginField("customfields@fogcreek.com",customFieldBillableColumn,api.Request[api.AddPluginPrefix("billCat")].ToString());
    bug.Commit();
}

public void BugCommitBefore(CBug bug,BugAction nBugAction,CBugEvent bugevent,bool fPublic) {
    bugevent.AppendChangeLine(String.Format("Billable changed from '{0}' to '{1}'",bug.GetPluginFieldOrig("customfields@fogcreek.com",customFieldBillableColumn),bug.GetPluginField("customfields@fogcreek.com",customFieldBillableColumn)));
}


=================================================
David Wilson Send private email
Wednesday, December 23, 2009
 
 
Hi David-
Sorry about that, I clearly didn't read your code carefully before responding. Yes, the issue makes sense now, and it is not clear from the interfaces that we are exposing that you can do that. Thank you for posting the solution, and we will try to make this clear in future revisions of the API.
Thanks!
Brett
Brett Kiefer Send private email
Wednesday, December 23, 2009
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz