Dependent questions are pre-populated and treated as value "0" when re-taking a previously submitted risk assessment even if never answered


Description

Dependent questions are pre-populated when re-taking a previously submitted risk assessment, even though these dependent questions where never answered, and treated as having value as "0".

 

Steps to Reproduce

1. Take the OOB Change Risk assessment record, pick a metric, and change one of its metric defitnition value to "0".
2. Make this metric depended on another metric.
3. Create a change record, and take the risk assessment with this dependent metric skipped.
4. Retake this risk assessment, make this dependent question appear. Observe that the option with value as "0" is already pre-selected.
The expected behavior is that previously skipped question should not have an option pre-selected.

The recording of the steps can also be seen on CSTASK070600.

Workaround

Modify Script Include: ChangeRiskAsmt sys_id: 884c5254d7233200532c24837e61032c add following function:

 

 

	_copyAsmt: function(previousAsmtInstanceSysId, asmtInstanceSysId) {
		if (this._log.atLevel(global.GSLog.DEBUG))
			this._log.debug("[_copyAsmt] previousAsmtInstanceSysId: " + previousAsmtInstanceSysId + " asmtInstanceSysId: " + asmtInstanceSysId);

		if (!previousAsmtInstanceSysId || !asmtInstanceSysId)
			return;

		// Object tracks multi-selection answers, updating one and inserting the others
		var multiSelection = {};
		var answerGr = new GlideRecord(this.ASMT_METRIC_RESULT);
		answerGr.addQuery(this.INSTANCE, previousAsmtInstanceSysId);
		answerGr.orderBy("metric");
		answerGr.query();

		if (this._log.atLevel(global.GSLog.DEBUG))
			this._log.debug("[_copyAsmt] answerGr table: " + answerGr.getTableName() + " encodedQuery: " + answerGr.getEncodedQuery());

		while (answerGr.next()) {
			var previousQuesGr = new GlideRecord(this.ASMT_INSTANCE_QUES);
			previousQuesGr.get(answerGr.instance_question + "");

			var answerMetricSysId = answerGr.metric + "";
			var newQuesGr = new GlideRecord(this.ASMT_INSTANCE_QUES);
			newQuesGr.addQuery(this.INSTANCE, asmtInstanceSysId);
			newQuesGr.addQuery("metric", answerMetricSysId);
			newQuesGr.query();
			var hasNextNewQuestion = newQuesGr.next();

			// If String type question copy string
			if (previousQuesGr.isValidField("string_value"))
				newQuesGr.setValue("string_value", previousQuesGr.getValue("string_value"));

			// If reference type question copy reference id
			if (previousQuesGr.isValidField("reference_id"))
				newQuesGr.setValue("reference_id", previousQuesGr.getValue("reference_id"));

			// Copy question value
			newQuesGr.setValue("value", previousQuesGr.getValue("value"));

			// If choice/multi-selection type question copy selected choices
			if (hasNextNewQuestion && !multiSelection[answerMetricSysId]) {
				newQuesGr.update();
				multiSelection[answerMetricSysId] = true;
			} else
				newQuesGr.insert();
		}
	},

 


Related Problem: PRB1405506