Respected Contributor.. Praveena_PNC Respected Contributor..
Respected Contributor..
222 views

Workflow to verify if linked entities exists for a bug before posting

Jump to solution

I need to build a workflow to check a defect just before it is posted, if there exists linked entity of any type other than bugs or requirements. I started with the code below in the bug_canpost function, but no luck so far.Any suggestions?

Dim MyComm 'tdc Command to do query
Dim Query 'text of the query
Dim MyRecSet 'RecordSet where the result of the query is stored
Set MyComm = tdconnection.Command
Query = "Select LN_ENTITY_TYPE from LINK where ln_bug_id = '" & Bug_Fields("BG_BUG_ID").Value

'load the text of the query into the
'command area
MyComm.CommandText = Query

'Execution of the query
Set MyRecSet = MyComm.Execute

if MyRecSet.RecordCount > 0 then
MsgBox "Linked entity exists "
else
MsgBox "Linked entity does not exists "
end if

Set MyRecSet = Nothing
Set MyComm = Nothing

0 Likes
1 Solution

Accepted Solutions
Respected Contributor.. Praveena_PNC Respected Contributor..
Respected Contributor..

Re: Workflow to verify if linked entities exists for a bug before posting

Jump to solution

I finally have a working code. To summarize, the requirement was to ensure that there is a linked entity to every defect created. This entity should be a test case/test set/test instance/test step/test instance/ test run. In other words,  another defect/ requirement is not sufficient as a linked entity. This needs to be applied to both new and existing defects. The piece of code below, I had placed under Bug_CanPost. The code changes the bug status to "No Linked Test" when that is the case. When the code recognizes that there is a link, it changes the status back to New or makes no change to existing status(in case the previous status was not No linked Test).This workflow is triggered only when a change is made to a defect and posted.

Dim td1, com1, bugNo, rec1, LastValue1
If bug_fields("BG_USER_TEMPLATE_05").Value = "Defect" and Bug_Fields("BG_DETECTED_BY").Value <> "grm-alm-serviceid" and ActiveModule <> "ManualRun" Then
set td1 = TDConnection
set com1 = td1.Command
bugNo = Bug_Fields("BG_BUG_ID").value
com1.CommandText = "SELECT count(LN_BUG_ID) FROM LINK WHERE LN_BUG_ID = '" & bugNo & "' and ln_entity_type <> 'REQ' and ln_entity_type <> 'BUG'"
set rec1 = com1.Execute
LastValue1 = rec1.FieldValue(0)
If LastValue1 > 0 Then
If Bug_Fields("BG_STATUS").Value = "No Linked Test" then
Bug_Fields("BG_STATUS").Value = "New"
End If
Else
Bug_Fields("BG_STATUS").Value = "No Linked Test"
End If
set com1 = nothing
set rec1 = nothing
End If

This piece of code I placed in Bug_MoveTo function to disable edit on the bug status until an appropriate entity is linked. Once linked the bug status field is enabled for edit:

If Bug_Fields("BG_STATUS").Value = "No Linked Test " then
Bug_Fields("BG_STATUS").IsReadOnly = True
End If

0 Likes
9 Replies
Respected Contributor.. Praveena_PNC Respected Contributor..
Respected Contributor..

Re: Workflow to verify if linked entities exists for a bug before posting

Jump to solution

the above code always shows "linked entity exists" ,no matter the defect has linked entities or not.

0 Likes
Highlighted
Knowledge Partner Knowledge Partner
Knowledge Partner

Re: Workflow to verify if linked entities exists for a bug before posting

Jump to solution

Are you aware that a new defect hasn't yet received a value for BG_BUG_ID when it is posted?

Did you check the value of the RecordCount? I wouldn't be surprised if you are getting back all rows in the LINK table.

Jan Czajkowski

[Please do not contact me off line for receiving support. Use the forum!]
0 Likes
Respected Contributor.. Praveena_PNC Respected Contributor..
Respected Contributor..

Re: Workflow to verify if linked entities exists for a bug before posting

Jump to solution

Sorry Jan, I meant this for existing bugs and I have a solution as below:

  Dim td1, com1, bugNo, rec1, LastValue1
  If bug_fields("BG_USER_TEMPLATE_05").Value = "Defect" and Bug_Fields("BG_DETECTED_BY").Value <> "grm-alm-serviceid" Then
    set td1 = TDConnection
    set com1 = td1.Command
    bugNo = Bug_Fields("BG_BUG_ID").value
    com1.CommandText = "SELECT count(LN_BUG_ID) FROM LINK WHERE LN_BUG_ID = '" & bugNo & "' and ln_entity_type <> 'REQ' and ln_entity_type <> 'BUG'"
    set rec1 = com1.Execute
    LastValue1 = rec1.FieldValue(0)
      If LastValue1 > 0 Then
        MsgBox "Linked entity exists"
        If Bug_Fields("BG_STATUS").Value = "No Linked Test" then
          Bug_Fields("BG_STATUS").Value = "New"
        End If
      Else
        MsgBox "Linked entity does not exist"
        Bug_Fields("BG_STATUS").Value = "No Linked Test"
      End If
  set com1 = nothing
  set rec1 = nothing
  End If

but it is not very clean. I am still trying to iron out the crinkles. I put this in the bug_canpost, but I am not sure . I am thinking Bug_MoveTo . Please advise

0 Likes
Respected Contributor.. Praveena_PNC Respected Contributor..
Respected Contributor..

Re: Workflow to verify if linked entities exists for a bug before posting

Jump to solution

So when I place the above code in the Bug_CanPost, the code does not recognize that there is a linked entity when a defect is opened from a failed test step when running a test instance.

The same code when I place in Bug_MoveTo, works well and recognizes that there is  a linked entity in the above scenario, but the problem is that the workflow gets triggered even when a bug is selected in the grid view. That is an issue, because the user logged in would not be responsible for all the defects to be linked. 

Suggestion?

0 Likes
Knowledge Partner Knowledge Partner
Knowledge Partner

Re: Workflow to verify if linked entities exists for a bug before posting

Jump to solution

If you move your code to CanPost it should work for existing defects, and users shouldn't be bothered just when browsing.

But for new defects there is no way you could get it working as far as I know.

Jan Czajkowski

[Please do not contact me off line for receiving support. Use the forum!]
0 Likes
Knowledge Partner Knowledge Partner
Knowledge Partner

Re: Workflow to verify if linked entities exists for a bug before posting

Jump to solution

If you move your code to CanPost it should work for existing defects, and users shouldn't be bothered just when browsing.

But for new defects there is no way you could get it working as far as I know.

Jan Czajkowski

[Please do not contact me off line for receiving support. Use the forum!]
0 Likes
Respected Contributor.. Praveena_PNC Respected Contributor..
Respected Contributor..

Re: Workflow to verify if linked entities exists for a bug before posting

Jump to solution

In fact it does work for new defects, meaning that the defect status changes to "No linked Test" for new defects created directly from the defect module. Unfortunately, when the defect is created from a failed test step, that also gets created as "No linked test". Where in that should save as simply "New", because technically it is created from a test step/test instance being run.

0 Likes
Respected Contributor.. Praveena_PNC Respected Contributor..
Respected Contributor..

Re: Workflow to verify if linked entities exists for a bug before posting

Jump to solution

Is there a way to capture from where a defect is created?

0 Likes
Respected Contributor.. Praveena_PNC Respected Contributor..
Respected Contributor..

Re: Workflow to verify if linked entities exists for a bug before posting

Jump to solution

I finally have a working code. To summarize, the requirement was to ensure that there is a linked entity to every defect created. This entity should be a test case/test set/test instance/test step/test instance/ test run. In other words,  another defect/ requirement is not sufficient as a linked entity. This needs to be applied to both new and existing defects. The piece of code below, I had placed under Bug_CanPost. The code changes the bug status to "No Linked Test" when that is the case. When the code recognizes that there is a link, it changes the status back to New or makes no change to existing status(in case the previous status was not No linked Test).This workflow is triggered only when a change is made to a defect and posted.

Dim td1, com1, bugNo, rec1, LastValue1
If bug_fields("BG_USER_TEMPLATE_05").Value = "Defect" and Bug_Fields("BG_DETECTED_BY").Value <> "grm-alm-serviceid" and ActiveModule <> "ManualRun" Then
set td1 = TDConnection
set com1 = td1.Command
bugNo = Bug_Fields("BG_BUG_ID").value
com1.CommandText = "SELECT count(LN_BUG_ID) FROM LINK WHERE LN_BUG_ID = '" & bugNo & "' and ln_entity_type <> 'REQ' and ln_entity_type <> 'BUG'"
set rec1 = com1.Execute
LastValue1 = rec1.FieldValue(0)
If LastValue1 > 0 Then
If Bug_Fields("BG_STATUS").Value = "No Linked Test" then
Bug_Fields("BG_STATUS").Value = "New"
End If
Else
Bug_Fields("BG_STATUS").Value = "No Linked Test"
End If
set com1 = nothing
set rec1 = nothing
End If

This piece of code I placed in Bug_MoveTo function to disable edit on the bug status until an appropriate entity is linked. Once linked the bug status field is enabled for edit:

If Bug_Fields("BG_STATUS").Value = "No Linked Test " then
Bug_Fields("BG_STATUS").IsReadOnly = True
End If

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.