Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

Multiple if status == statements


#1

Hi Everyone,

I am in need of some assistance.
I am not a js guys, but have been asked to customize the ui script for our testrail installation.

Basically what they are wanting is to have something like

if status == 1 { make comment mandatory}
else if or ???
if status == 3 {make defect id number mandatory}

and on different projects.

I have hacked together 2 scripts which i found on this forum

"
name: Failed Mandatory
version: 1.0
author:
includes:
excludes:

js:
(document).ready( function() { .subscribe(‘result_dialog.loaded’, ‘uiscript_require_elapsed’, function(o) {
$(’#addResultDefects’).prev().append(’ *’);

        });

        $.subscribe('result_dialog.validate', 'uiscript_require_elapsed', function(o) {

            var defeito = $.trim(o.values.defects)

            if ($.trim(o.values.status_id) == 5) {
                if (defeito == '') {
                    $('#addResultErrors').append("ATTENTION: Defect ID Requried");
                    $('#addResultErrors').show();
                    $('#addResultDefects').prev().append(' <span class="required"><font color="#CF1B5D"> ID Requried! </font></span>');
                    o.event.stopPropagation();
                    return;
                }
	}
        });
    }
);

"

and

"
name: Blocked and Retest
version: 1.0
author:
includes:
excludes:

js:
(document).ready( function() { .subscribe(‘result_dialog.loaded’, ‘uiscript_require_elapsed’, function(o) {
$(’#addResultComment’).parent().parent().prev(‘label’).append(’ *’);

        });

        $.subscribe('result_dialog.validate', 'uiscript_require_elapsed', function(o) {
			
				var defeito = $.trim(o.values.defects)
				
            if ($.trim(o.values.status_id) == 2 || $.trim(o.values.status_id) == 4 ) {
                if ($.trim(o.values.comment) == '') {

                    $('#addResultErrors').append('ATTENTION: Please insert a rich and detailed comment');
                    $('#addResultErrors').show();
                    $('#addResultComment').parent().parent().prev('label').append(' <span class="required"><font color="#CF1B5D"> ADD A COMMENT! </font></span>');

                    o.event.stopPropagation();
                    return;
				}
			}       
        });
    }
);

"
The scripts work fine when one one is set to run, however when both are set to run none of them work.

Please can someone help me figure out what I’m doing wrong!!

thanks


#2

Hi Timothy,

I had this same issue.

It seems that if you have 2 active UI scripts that are supposed to run when the result_dialog is validated then they don’t work.

The solution I found was to put the 2 if statements into a single UI script one after the other. That way you only have one script doing the validation. Doing it this way worked for me.