Gokrish Absent Member.
Absent Member.
1107 views

Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

Hi, I'm new to the workflow scripting.. I'm trying to make few fields conditionally mandatory based on defect status. This is the code I've written inside Defects Module Script-> Bug_FieldChange..

 

Sub Bug_FieldChange(FieldName)

WizardListCust ' Added by wizard


'Added the below script for conditional mandatory 
msgbox ("Here 0")
'On Error Resume Next


if FieldName="BG_STATUS" then
Select case Bug_Fields("BG_STATUS").Value
case "Closed"
Bug_Fields("BG_USER_05").IsRequired=True
msgbox ("here')
case "Fixed"
Bug_Fields("BG_USER_05").IsRequired=True
End Select
End if

' On Error GoTo 0

End Sub

 

I've commented the on error statements. When I change the defect status, nothing happens and it still accepts a blank in 'BG_USER_05' field. 

I even tried to display few messages to see if it reaches the block or not. But no luck.

Any quick help on this is highly appreciated.. Thanks,

0 Likes
1 Solution

Accepted Solutions
Highlighted
cmt8455 Absent Member.
Absent Member.

Re: Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

Hi Gokrish. Try this code in Bug_FieldCanChange. I assumed that BG_USER_05 can be blank under any other circumstances than what you mentioned, if not you'll need to alter the code accordingly. Note when a user tries to change the Status to Closed or Fixed & BG_USER_05 is blank, Bug_FieldCanChange will revert the status to the prior value. The user will need to complete BG_USER_05 & change the Status again.

Function Bug_FieldCanChange(FieldName, NewValue)
Bug_FieldCanChange = True
On Error Resume Next
If FieldName = "BG_STATUS" And NewValue = "Closed" Or NewValue = "Fixed" Then
    If Bug_Fields.Field("BG_USER_05").Value = "" Then
         Bug_FieldCanChange = False
         msgbox "You cannot change Status to Closed or Fixed if <Field Name> is blank."
    Else
        Bug_FieldCanChange = True
    End If
Else
    Bug_FieldCanChange = True
End If
On Error GoTo 0
End Function

12 Replies
Highlighted
cmt8455 Absent Member.
Absent Member.

Re: Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

Hi Gokrish. Try this code in Bug_FieldCanChange. I assumed that BG_USER_05 can be blank under any other circumstances than what you mentioned, if not you'll need to alter the code accordingly. Note when a user tries to change the Status to Closed or Fixed & BG_USER_05 is blank, Bug_FieldCanChange will revert the status to the prior value. The user will need to complete BG_USER_05 & change the Status again.

Function Bug_FieldCanChange(FieldName, NewValue)
Bug_FieldCanChange = True
On Error Resume Next
If FieldName = "BG_STATUS" And NewValue = "Closed" Or NewValue = "Fixed" Then
    If Bug_Fields.Field("BG_USER_05").Value = "" Then
         Bug_FieldCanChange = False
         msgbox "You cannot change Status to Closed or Fixed if <Field Name> is blank."
    Else
        Bug_FieldCanChange = True
    End If
Else
    Bug_FieldCanChange = True
End If
On Error GoTo 0
End Function

Damodar-Reddy Acclaimed Contributor.
Acclaimed Contributor.

Re: Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

Gokrish,

The code seems fine.

is this project linked to any template?

(If this helped, accept as solution )
(Posts and opinions made here are my own and do not reflect the opinions of my employer)
0 Likes
Gokrish Absent Member.
Absent Member.

Re: Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

Thank you. I will try this. 

0 Likes
Gokrish Absent Member.
Absent Member.

Re: Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

Hi, I believe the project is linked to the template. In the script editor i could see sections for both template & project. 

 

P.S: I'm sorry, I'm not the one who set up the project. I'm only trying to fix this conditional mandatory issue. 🙂 

 

0 Likes
Damodar-Reddy Acclaimed Contributor.
Acclaimed Contributor.

Re: Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

If it's linked to the template,

you cannot have the changes in the project script.

those are supposed to be written in the Template script in the Original template and apply CPC (CROSS PROJECT CUSTOMIZATION).

P.S: All the linked projects might be affected with this change, have an eye...!!

(If this helped, accept as solution )
(Posts and opinions made here are my own and do not reflect the opinions of my employer)
0 Likes
Gokrish Absent Member.
Absent Member.

Re: Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

Sorry for being ignorant. Could you please advice how to confirm if the project is linked to the template? 

0 Likes
Damodar-Reddy Acclaimed Contributor.
Acclaimed Contributor.

Re: Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

No Problem,

you can check this in 2 ways.

-->If you have access  to Site Administration:

Login & Click on the template & you can see the option (Tab) called. Linked Projects.

here you can see whether the project is linked or no.

--> Or Else, If you access to the the Template, click on customization & CPC (Cross Project Customization).

There you can see the list of projects linked to it, you can validate the same from here too.

--> If nothing, contact your QC/ALM Admin for more details.

 

(If this helped, accept as solution )
(Posts and opinions made here are my own and do not reflect the opinions of my employer)
Gokrish Absent Member.
Absent Member.

Re: Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

hi cmt8455,

I tried your suggestion. Still no luck.

I even tried to put a messagebox to display the Bug_Fields.Field("BG_USER_05").Value outside the check, still nothing happened.

I really wonder if the script gets picked up while the fields are being updated. I've attached a screenshot of how my code looks. 

0 Likes
Gokrish Absent Member.
Absent Member.

Re: Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

Thanks cmt8455 & Damodar. Its working now. The function call to Bug_FieldChange was commented out in the template. When I uncommented it, the below code started working. However there is one issue.

If FieldName = "BG_STATUS" And (NewValue = "Closed" Or NewValue = "Fixed" Or _
NewValue = "Ready for Release" or NewValue = "Ready for Test" or NewValue = "Rejected") Then
'Check if Root Cause is not populated
If Bug_Fields.Field("BG_USER_05").Value = "" Then
Bug_FieldCanChange = False
msgbox "Please update Root Cause before resolving the defect"
Else
Bug_FieldCanChange = True
End If
Else
Bug_FieldCanChange = True
End If

When I select the status to the above list (say for ex: Fixed), the alert gets triggered but the status is updated to 'Fixed' instead of reverting to the old one.

Can you please assist?

0 Likes
cmt8455 Absent Member.
Absent Member.

Re: Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

You're welcome Gokrish. Since you're working with a template, you should be using the Sub Template_Bug_FieldCanChange function in the template project. You should also remove the code from Bug_FieldChange in the linked project as well. You will not need to call the sub in the project.

Gokrish Absent Member.
Absent Member.

Re: Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

Hi cmt8455, its still not retaining the old value after giving the alert. 

After the alert, it changes to the new value which it shouldn't be. 

Please advice.

0 Likes
Gokrish Absent Member.
Absent Member.

Re: Bug_FieldChange(FieldName) not changing the field properties

Jump to solution

Thank you cmt8455 & Damodar.

It is working as expected now. 

1. I've written the script in template scripts

2. I've carefully added additional checks like (project name) to ensure this condition shoudn't impact any other project linked to this template.

Hope it will not impact any other project. Its a good learning. Thanks again. 

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.