Workflow Scripting: Default values into Memo field overwrite existing data (2459 Views)
Reply
Occasional Advisor
Sarah Hammond
Posts: 8
Registered: ‎04-26-2010
Message 1 of 6 (2,459 Views)
Accepted Solution

Workflow Scripting: Default values into Memo field overwrite existing data

[ Edited ]

Hi all,

 

One of my project managers requested a form to template into the defect description field when a particular value is selected from another field.  I found a sample in the QC Admin guide that I was able to modify to the following code and it works beautifully with one exception--it will overwrite any existing data in the field.  I have very basic programming skills and I'm sure the solution is a simple one, however I don't have the time to devote to figuring this out on my own.  The requirement is that if the Description field has data in it to append the values at the bottom.  Any ideas?

 

Sub Bug_FieldChange(FieldName)
'Code to default values into the Description field when the user selects a
'Defect Type of Enhancement.

    On Error Resume Next

    If FieldName = "BG_USER_01" then
    Select case Bug_Fields("BG_USER_01").Value
    case "Enhancement"

         Bug_Fields("BG_DESCRIPTION").value =_
         "<html><body><b>Summary of Enhancement:</b>"&_
         "<br><br><br><b>Design Documentation:</b>"&_
         "<br><br><br><b>Detailed Build Steps:</b>"&_
         "<br><br><br><b>New Records:</b>"&_
         "<br><br><br><b>Modified Records:</b>"&_
         "<br><br><br><b>New Categories:</b>"&_
         "<br><br><br><b>Modified Categories:</b>"&_
         "<br><br><br><b>Testing Steps:</body></html>"

    Case Else
         Bug_Fields("BG_DESCRIPTION").IsNull
    End Select
    End If
    PrintError "Bug_FieldChange"
    ON Error GoTo 0
End Sub

 

Thanks,

Sarah

Honored Contributor
Trudy Claspill
Posts: 3,778
Registered: ‎09-09-2010
Message 2 of 6 (2,455 Views)

Re: Workflow Scripting: Default values into Memo field overwrite existing data

Sub Bug_FieldChange(FieldName)
'Code to default values into the Description field when the user selects a
'Defect Type of Enhancement.

    On Error Resume Next

Dim OriginalValue

    If FieldName = "BG_USER_01" then
    Select case Bug_Fields("BG_USER_01").Value
    case "Enhancement"
         OriginalValue = ""
         if len(Bug_Fields("BG_DESCRIPTION").value) > 0 then
              OriginalValue = Bug_Fields("BG_DESCRIPTION").value 
         Bug_Fields("BG_DESCRIPTION").value =_
         OriginalValue & "</b>" & _
         "<html><body><b>Summary of Enhancement:</b>"&_
         "<br><br><br><b>Design Documentation:</b>"&_
         "<br><br><br><b>Detailed Build Steps:</b>"&_
         "<br><br><br><b>New Records:</b>"&_
         "<br><br><br><b>Modified Records:</b>"&_
         "<br><br><br><b>New Categories:</b>"&_
         "<br><br><br><b>Modified Categories:</b>"&_
         "<br><br><br><b>Testing Steps:</body></html>"

    Case Else
         Bug_Fields("BG_DESCRIPTION").IsNull
    End Select
    End If
    PrintError "Bug_FieldChange"
    ON Error GoTo 0
End Sub

 

I would suggest something like this.

[If this post solves or helps solve your issue, mark the thread as solved and give KUDOS to the author for their assistance.]

(Opinions expressed in my postings are mine alone, and do not reflect the opinions of my employer.No warranties express or implied for any solution/suggestion posted.)
Occasional Advisor
Sarah Hammond
Posts: 8
Registered: ‎04-26-2010
Message 3 of 6 (2,437 Views)

Re: Workflow Scripting: Default values into Memo field overwrite existing data

[ Edited ]

I tried your solution and at first QC gave me the following error on the Case Else line.

 

[Error] (L413: c5): Expected statement

 

It looked like it was expecting an End statement, so I added an "End If" just above the Case Else line at which point it passed the syntax check without error.  However, when I tested it the default values didn't drop in at all.  Here's what the script looks like now.  What am I missing? 

 

Sub Bug_FieldChange(FieldName)
'Code to default values into the Description field when the user selects a
'Defect Type of Enhancement.

    On Error Resume Next

Dim OriginalValue

    If FieldName = "BG_USER_01" then
    Select case Bug_Fields("BG_USER_01").Value
    Case "Enhancement"
         OriginalValue = ""
         If len(Bug_Fields("BG.DESCRIPTION").value) > 0 then
            OriginalValue = Bug_Fields("BG_DESCRIPTION").value
         Bug_Fields("BG_DESCRIPTION").value =_
         OriginalValue & "</b>"&_
         "<html><body><b>Summary of Enhancement:</b>"&_
         "<br><br><br><b>Design Documentation:</b>"&_
         "<br><br><br><b>Detailed Build Steps:</b>"&_
         "<br><br><br><b>New Records:</b>"&_
         "<br><br><br><b>Modified Records:</b>"&_
         "<br><br><br><b>New Categories:</b>"&_
         "<br><br><br><b>Modified Categories:</b>"&_
         "<br><br><br><b>Testing Steps:</body></html>"
         End If
    Case Else
         Bug_Fields("BG_DESCRIPTION").IsNull

    End Select
    End If
    PrintError "Bug_FieldChange"
    ON Error GoTo 0
End Sub

Honored Contributor
RoniRobinson
Posts: 623
Registered: ‎07-21-2011
Message 4 of 6 (2,432 Views)

Re: Workflow Scripting: Default values into Memo field overwrite existing data

The way this code is written, you will only get the default value if the value in BG_user_01 = Enhancement.  Is that what you used to test?  If you other default values for other selections, you will need to add each of those case statements.

Occasional Advisor
Sarah Hammond
Posts: 8
Registered: ‎04-26-2010
Message 5 of 6 (2,412 Views)

Re: Workflow Scripting: Default values into Memo field overwrite existing data

I prettied up the HTML a bit and got the script to work the way I wanted.  For anyone interested, here's what the finished script looks like.

 

Sub Bug_FieldChange(FieldName)
    On Error Resume Next

Dim OriginalValue
    If FieldName = "BG_USER_01" then
    Select Case Bug_Fields("BG_USER_01").Value
    Case "Enhancement"
         OriginalValue = ""
         If len(Bug_Fields("BG_DESCRIPTION").value)>0 then
            OriginalValue = Bug_Fields("BG_DESCRIPTION").value
         Bug_Fields("DESCRIPTION").value=_
         OriginalValue & "</b>"&_
         "<html><body><b></b>"&_
         "<br><br><br><b>Summary of Enhancement:</b>"&_
         "<br><br><br><b>Design Documentation:</b>"&_
         "<br><br><br><b>Detailed Build Steps:</b>"&_
         "<br><br><br><b>New Records:</b>"&_
         "<br><br><br><b>Modified Records:</b>"&_
         "<br><br><br><b>New Categories:</b>"&_
         "<br><br><br><b>Modified Categories:</b>"&_
         "<br><br><br><b>Testing Steps:</body></html>"
         End If
    Case Else
         Bug_Fields("BG_DESCRIPTION").IsNull
    End Select
    End If
    PrintError "Bug_FieldChange"

    ON Error GoTo 0
End Sub

 

Thanks to everyone for their help!

Advisor
AndrewKerr
Posts: 17
Registered: ‎12-21-2010
Message 6 of 6 (2,186 Views)

Re: Workflow Scripting: Default values into Memo field overwrite existing data

I love it when someone tries to take another persons' credit
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.