Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Catherine Zobki Absent Member.
Absent Member.
1628 views

Make Add Comments Mandatory

Jump to solution
Can anyone provide me the VB Scripting to make the "Add Comments" button mandatory? I don't want users to be able to create anonymous comments. Many thanks!
0 Likes
1 Solution

Accepted Solutions
Rohith Shetty Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
Hi Catherine,

Hope this code helps.

Step1:

'In workfolw, declare follwoing variables under common script section

Dim blnAddCommentClicked
Dim strCommentBeforeUpdate
Dim blnUpdateCommentError:blnUpdateCommentError = False
Dim changed:changed = false

'Step2:

Function Defects_ActionCanExecute(ActionName)
On Error Resume Next
If ActionName = "BugAddDevCommentsAction1" Then
blnAddCommentClicked = True
End If
Defects_ActionCanExecute = Project_DefaultRes
On Error GoTo 0
End Function

'Step3:
Function Defects_Bug_FieldCanChange(FieldName, NewValue)
On Error Resume Next
if not changed then
strCommentBeforeUpdate = Bug_Fields("BG_DEV_COMMENTS").Value
end if
If FieldName = "BG_DEV_COMMENTS" and blnAddCommentClicked = False Then
Msgbox "Cannot update the comments." & Chr(13)& "Changes made will not be saved."&Chr(13)&" Please use 'Add comment' button to insert new comment."
blnUpdateCommentError = true
blnAddCommentClicked = False
changed = true
End If
Defects_Bug_FieldCanChange = Project_DefaultRes
On Error GoTo 0
End Function

'Step4:
Function Defects_Bug_CanPost
On Error Resume Next
If blnUpdateCommentError And Not blnAddCommentClicked Then
Bug_Fields("BG_DEV_COMMENTS").Value = strCommentBeforeUpdate
blnUpdateCommentError = False
End If
blnAddCommentClicked = False
changed = false
Defects_Bug_CanPost = Project_DefaultRes
On Error GoTo 0
End Function

Regards
Rohith Shetty
0 Likes
14 Replies
Rohith Shetty Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
Hi Catherine,

Hope this code helps.

Step1:

'In workfolw, declare follwoing variables under common script section

Dim blnAddCommentClicked
Dim strCommentBeforeUpdate
Dim blnUpdateCommentError:blnUpdateCommentError = False
Dim changed:changed = false

'Step2:

Function Defects_ActionCanExecute(ActionName)
On Error Resume Next
If ActionName = "BugAddDevCommentsAction1" Then
blnAddCommentClicked = True
End If
Defects_ActionCanExecute = Project_DefaultRes
On Error GoTo 0
End Function

'Step3:
Function Defects_Bug_FieldCanChange(FieldName, NewValue)
On Error Resume Next
if not changed then
strCommentBeforeUpdate = Bug_Fields("BG_DEV_COMMENTS").Value
end if
If FieldName = "BG_DEV_COMMENTS" and blnAddCommentClicked = False Then
Msgbox "Cannot update the comments." & Chr(13)& "Changes made will not be saved."&Chr(13)&" Please use 'Add comment' button to insert new comment."
blnUpdateCommentError = true
blnAddCommentClicked = False
changed = true
End If
Defects_Bug_FieldCanChange = Project_DefaultRes
On Error GoTo 0
End Function

'Step4:
Function Defects_Bug_CanPost
On Error Resume Next
If blnUpdateCommentError And Not blnAddCommentClicked Then
Bug_Fields("BG_DEV_COMMENTS").Value = strCommentBeforeUpdate
blnUpdateCommentError = False
End If
blnAddCommentClicked = False
changed = false
Defects_Bug_CanPost = Project_DefaultRes
On Error GoTo 0
End Function

Regards
Rohith Shetty
0 Likes
Catherine Zobki Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
Rohith, you're the best! Thank you. You've addressed both issues I posted. The code in this thread will not allow users to post a comment unless they select "Add Comments" first, and it will not allow users to delete any previously posted comments. Thanks again.
0 Likes
Catherine Zobki Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
Rohith, per our offline exchange, I found a loop hole. If I click the "Add Comment" button AND update a previously saved comment in the same session, it works. So I can update an older comment as long as I click Add Comments before I do it.

Here is the updated code you sent. I wanted to post it here for others who may use it in the future.

Step1: Copy the below lines to Common script area

Dim blnAddCommentClicked
Dim strCommentBeforeUpdate
Dim blnUpdateCommentError:blnUpdateCommentError = False
Dim changed:changed = false

'Step2:

Function Defects_ActionCanExecute(ActionName)
On Error Resume Next
If ActionName = "BugAddDevCommentsAction1" Then
blnAddCommentClicked = True
End If
Defects_ActionCanExecute = Project_DefaultRes
On Error GoTo 0
End Function

Step3:


Function Defects_Bug_FieldCanChange(FieldName, NewValue)
On Error Resume Next
if not changed then
strCommentBeforeUpdate = Bug_Fields("BG_DEV_COMMENTS").Value
end if

If instr(strCommentBeforeUpdate,"/body>")>0 Then
arrCommentBefore= Split(strCommentBeforeUpdate,"/body>")
strCompare = arrCommentBefore(0)
eLSE
strCompare = strCommentBeforeUpdate
End If

If FieldName = "BG_DEV_COMMENTS" and blnAddCommentClicked = False Then
Msgbox "Cannot update the comments." & Chr(13)& "Changes made will not be saved."&Chr(13)&" Please use 'Add comment' button to insert new comment."
blnUpdateCommentError = true
blnAddCommentClicked = False
changed = true
ElseIf FieldName = "BG_DEV_COMMENTS" And Not Instr(1,NewValue,strCompare) > 0 and blnAddCommentClicked Then
Msgbox "Cannot modify previous comment. Changes made will not be saved."
blnUpdateCommentError = true
changed = true
Exit Function
End If
strCompare = ""
Defects_Bug_FieldCanChange = Project_DefaultRes
On Error GoTo 0
End Function

Step4:

Function Defects_Bug_CanPost
On Error Resume Next
If blnUpdateCommentError And changed Then
Bug_Fields("BG_DEV_COMMENTS").Value = strCommentBeforeUpdate
blnUpdateCommentError = False
End If
blnAddCommentClicked = False
changed = false
Defects_Bug_CanPost = Project_DefaultRes
On Error GoTo 0
End Function
0 Likes
Catherine Zobki Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
The updated code worked great. I'm closing this thread again. Thanks again, Rohith!
0 Likes
Vladimir Skrbek Acclaimed Contributor.
Acclaimed Contributor.

Re: Make Add Comments Mandatory

Jump to solution
Hi,

yes this is good solution for the HPQC comments. But I think the comments process in HPQC is not good.

The right process should be:
- User click on Add button
- There will be open window with memo field
- User will write their comments and click ok

The reason is:
- the user does not change any other comments and can easyly add new comment
- user does not need to care about headding of teh comments
- you can enforce simply the comment is mandatory
- you can simply add heading to the comment history like username, fulname, date, time, state, ...

I resolve this in thisway.
- create memo field with name "Comment History" just for reading
- field "Dev comment" is used only for adding new comment
- so whenever user write something to the "dev comment" field and click on OK or do a post then this comment is written to the begining of the new memo field "Comment History" with some prefix like username, date, time, state, ...
- and I disabled the button Add comment because it is not needed
- and one more, whenever I need I can enforce user to put the comments

Best Regards
Skrbek
0 Likes
Jonathan Kong Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
I am also very interested in this commenting feature so I have tried the updated code. It doesn't seem to be functioning correctly.

(1) In the main Defects view, even though a message box appears when trying to add comments w/o clicking the Add Comment button, the comments will post after a refresh of the view.

(2) In the Defect Details window the message box appears when trying to modify the comments w/o clicking the Add Comment button but the user can still click OK and have the comments updated

Is there a work around for these issues? All in all, it is a very promising feature to have. Thanks.
0 Likes
Catherine Zobki Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
Did you use the second posting of code from me? The original had a loop hole in it. I cannot reproduce the issue you're describing.
0 Likes
Jonathan Kong Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
I'm using the 2nd updated code you posted on a QC 9.2 patch 9 instance.

Do you have Steps2-4 in the Defects module script section or is this feature entirely implemented in the common scripts section of your instance?

Thanks for the quick reply Catherine!
0 Likes
Catherine Zobki Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
Hi, Jonathan. I only put the first bit of code in the common area, then put the others in their respective sections.

Just to clarify, you're saying if you're looking at the main defect view, with your columns, then update the Description at the bottom without using Add Comments, then click the two circular arrows to refresh, the comment posts anyway? I get the expected behavior when I do it, so maybe we can compare notes offline. catherine.zobkiw@gsk.com
0 Likes
Highlighted
AKR Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
Hello,
Is there a way I can always insert the comment at the top instead of appending the same.
0 Likes
QC_Tester Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
Catherine,

I used the code you proivded but there seems to be some problem with it. Can you e-mail me the updated code that you were talking about or reply to this thread with an attachment?

Thanks,
HS1234
0 Likes
QC_Tester Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
Here is what I am experiencing:

This code works wonderfully when I add comments through the defect grid, i.e. without opening the defect.
However if I open a particular defect and then use the add comment button to add a comment, it will not let me and keep throwing the error message at me.
Please help!
0 Likes
Nicholas Cartwr Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
I also have the same problem as QC Tester, on further investigation I found that the action name when clicking 'Add Comment' button from the open defect is "AddDevComment".

so I amended the 'If' statement in Defects_ActionCanExecute to:

If ActionName = "BugAddDevCommentsAction1" or ActionName = "AddDevComment" Then
blnAddCommentClicked = True
End If

This seems to have sorted the problem.
0 Likes
Nicholas Cartwr Absent Member.
Absent Member.

Re: Make Add Comments Mandatory

Jump to solution
One thing I was wondering if it would be possible would be to have the comments as Read Only until the ADD COMMENTS button is pressed. However, I'm struggling to do this. Anyone have any ideas?
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.