// Update the TR State field for the bug based either on incoming ecr, or if this is null
        // get the current TR State from the bug. If missing link for a maintenance product or if
        // having a link for a non-maintenance product, also show this.
        static public void updateBug(Status status, String user,
                                     Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem workItem)
        {
            // Check if we are connected when we should be
            bool   isProdInMaint = ProductMapper.getInstance().IsProductInMaintenance(workItem);
            String currentLink   = HandlerSettings.GetIDFromLink(workItem);
            bool   hasLink       = currentLink.Length > 0;

            if (isProdInMaint && (!hasLink && status.TRAbout == null))
            {
                // Error - should have link and nothing in the status.TRAbout so have not created.
                workItem.Fields[TFSMapper.ERICSSON_DEFECT_STATE_FIELD].Value = trStateToString[TRStateInfo.ErrorMissingTR];
            }
            else if (!isProdInMaint)
            {
                // OK - clear any status fields and return
                ECRMapper.disconnectBug(workItem);
                return;
            }
            else
            {
                // OK - prod is in maint and has link - normal case

                // Check if state is updated
                String newTrState = null;
                if (status.TRState != null)
                {
                    String currentTrState = getTRState(workItem);
                    String updatedTrState = status.TRState;
                    if (!updatedTrState.Equals(currentTrState))
                    {
                        newTrState = updatedTrState;
                        workItem.Fields[TFSMapper.ERICSSON_DEFECT_STATE_FIELD].Value = newTrState;
                    }
                }

                if (status.TRAbout != null)
                {
                    // We will store the relative path of the "Edit TR" link in the bug, reason being that the Link
                    // that we need to define for the UI to allow click to navigate require a non blank UriRoot value,
                    // see http://msdn.microsoft.com/en-us/library/dd936107.aspx.

                    String updatedLink = HandlerSettings.GetIDFromUri(status.TRAbout.ToString());
                    if (updatedLink.Length > 0)
                    {
                        if (!currentLink.Equals(updatedLink))
                        {
                            workItem.Fields[TFSMapper.ERICSSON_DEFECT_LINK_FIELD].Value = updatedLink;
                        }
                    }
                }
            }

            // Put the error and expected state string into system history field
            String message = status.GetMessage();

            // Append any defined guiding message
            TRSyncState newSyncState   = getSyncState(status, workItem);
            String      guidingMessage = "";

            switch (newSyncState)
            {
            case TRSyncState.SyncStateNone:
                guidingMessage = HandlerSettings.SyncNoSyncMessage;
                break;

            case TRSyncState.SyncStateOK:
                guidingMessage = HandlerSettings.SyncSuccessMessage;
                break;

            case TRSyncState.SyncStateWarning:
                guidingMessage = HandlerSettings.SyncWarningMessage;
                break;

            case TRSyncState.SyncStateError:
                guidingMessage = HandlerSettings.SyncErrorMessage;
                break;
            }

            if (message.Length > 0 || guidingMessage.Length > 0)
            {
                workItem.History = message + ((guidingMessage.Length > 0) ? " " + guidingMessage : "");
            }

            // Put the sync state in the Sync State field
            String currentSyncStateStr = workItem.Fields[TFSMapper.ERICSSON_DEFECT_SYNCSTATE].Value.ToString();
            String newSyncStateStr     = trSyncStateToString[newSyncState];

            bool incomingChange = user.Equals(HandlerSettings.TFSProviderUser, StringComparison.OrdinalIgnoreCase);

            newSyncStateStr = String.Format(newSyncStateStr, incomingChange ? "(in)" : "(out)");

            if (!currentSyncStateStr.Equals(trSyncStateToString))
            {
                workItem.Fields[TFSMapper.ERICSSON_DEFECT_SYNCSTATE].Value = newSyncStateStr;
            }
        }