0

I´m developing a TFS 2012 web access custom control and I need to change some workitem field values when the save workitem button is clicked.

I’ve just developed the same custom control for Visual Studio and I’ve performed these changes in the IWorkItemControl.FlushToDatasource method but I don't know how to achieve the same at web access control.

I’ve tried to change the workitem field values in the invalidate function when the workitem is being saved,

invalidate: function (flushing) {
    if (this._workItem.isSaving()) {
         this._workItem.getField("FieldName").setValue("newValue");
    }
},

But it does not work, although the changes made while saving the workitem are included in the list of updated fields, they are not saved.

Any idea how can it be implemented by using the Javascript API?

Thanks.

Oscar

Krypton
  • 3,337
  • 5
  • 32
  • 52
Oscar
  • 1
  • I think the problem would be that the work item isn't saved after you make the changes. – Andrew Clear Sep 13 '13 at 15:28
  • The problem is that once the saving process has finished, only the changes made before clicking the save button are stored into database, the workitem remains in Dirty State due to the changes made while the workitem is being saved. I need that changes made while saving the workitem are saved at the same time that changes made before the save button is clicked. In the control for VS, it can be performed in the FlushToDatasource method but I’ve not been able to find the way for doing the same through JavaScript API – Oscar Sep 13 '13 at 15:53
  • Hi @Oscar, [here](http://blogs.msdn.com/b/serkani/archive/2012/06/22/work-item-custom-control-development-in-tf-web-access-2012-development.aspx) you can find a nicely explained series by **Serkan** for this issue. – Beytan Kurt Jul 15 '14 at 14:21

1 Answers1

2

Can you try this:

    _control: null,
    _init: function() {
        alert("_init() called!");

        debugger;
        if (this._workItem) {
            var originalEstimate = this._workItem.getField("Microsoft.VSTS.Scheduling.OriginalEstimate").getValue();
            alert('OriginalEstimate value is ' + originalEstimate);
            console.log('this in _init');
            console.log(this);
        } else {
            alert('_workItem is null or undefined!');
            console.log('this in _init');
            console.log(this);
        }

        this._base();
        this._control = $("<div style='width:100%;height:100%;background-color:lightblue;'><button type='submit'>CLICK ME!</button></div>").appendTo(this._container).bind("click", delegate(this, this._onClick));
    },

    invalidate: function(flushing) {
        alert("invalidate(flushing) called!");
        var value = this._getField().getValue();

        debugger;
        if (this._workItem) {
            var originalEstimate = this._workItem.getField("Microsoft.VSTS.Scheduling.OriginalEstimate").getValue();
            alert('OriginalEstimate value is ' + originalEstimate);
            console.log('this in _init');
            console.log(this);
        } else {
            alert('_workItem is null or undefined!');

            console.log('this in _init');
            console.log(this);
        }

        alert(value);
    },

    clear: function() {
        alert("clear() called!");
    },

    _onClick: function() {
        alert("Butona tıklandı!");
    }
Salih KARAHAN
  • 299
  • 1
  • 4
  • 18