Trigger Demand Assessment when state moves to Submitted

Adam Geil
Kilo Sage

We're exploring having our Demand Assessments trigger when the demanding state moves to Submitted instead of Screening in order to better match our internal procedures.

 

I'm hoping someone can validate my work hear and make sure I'm not overlooking something. Our Demand states are OOB. Here are the state values for quick reference:

ValueLabelSequence
1Draft1
2Submitted2
3Screening3
'-4Qualified4
5Incomplete5
10Deferred6
7Rejected7
8Approved8
9Completed9

 

 

 

I believe this can be done by modifying the checkAndUpdateDemandIfAssessmentsComplete function in the DemandUtils script include in the following way. 

Original:

	checkAndUpdateDemandIfAssessmentsComplete : function(instanceSysId) {
		var gr = new GlideRecord('asmt_assessment_instance_question');
		gr.addQuery('instance', instanceSysId);
		gr.query();
		if (gr.next()) {
			var questionGR = new GlideAggregate('asmt_assessment_instance_question');
			questionGR.addQuery('source_id', gr.getValue('source_id'));
			questionGR.groupBy('instance');
			questionGR.query();
			while (questionGR.next()) {
				if (!(questionGR.instance.state == 'complete' || questionGR.instance.state == 'canceled'))
					return false;
			}
			// All assessments completed
			var demandGR = new GlideRecord('dmn_demand');
			if (demandGR.get(gr.getValue('source_id')) && demandGR.state == 3) {
				demandGR.state = -4;
				demandGR.update();
			}
			return true;
		}
		return false;
	},

 

Modified:

	checkAndUpdateDemandIfAssessmentsComplete : function(instanceSysId) {
		var gr = new GlideRecord('asmt_assessment_instance_question');
		gr.addQuery('instance', instanceSysId);
		gr.query();
		if (gr.next()) {
			var questionGR = new GlideAggregate('asmt_assessment_instance_question');
			questionGR.addQuery('source_id', gr.getValue('source_id'));
			questionGR.groupBy('instance');
			questionGR.query();
			while (questionGR.next()) {
				if (!(questionGR.instance.state == 'complete' || questionGR.instance.state == 'canceled'))
					return false;
			}
			// All assessments completed
			var demandGR = new GlideRecord('dmn_demand');
			if (demandGR.get(gr.getValue('source_id')) && demandGR.state == 2) {
				demandGR.state = 3;
				demandGR.update();
			}
			return true;
		}
		return false;
	},

 

 

Additionally, I believe we would need to modify the Create OnDemand Assessment business rule trigger Condition.

Original:

previous.state == 2 && current.state == 3

 

Modified:

previous.state == 1 && current.state == 2

 

3 REPLIES 3

BharathChintala
Mega Sage

@Adam Geil 

follow these steps

BharathChintala_0-1679427233963.png

Open Demand in list

BharathChintala_1-1679427286474.png

don't touch anything else.

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

Hi @BharathChintala ,

I changed the condition of Demand metric type, regenerate assessable records, however, it is only working when state changes to screening. For the rest, it is not working, assessment is not calculating.

Do you have any idea?

Thanks in advance

Hi @An Le,

 

It's been awhile since I implemented this, but I believe we implemented it exactly as I described in the original post. The trigger for demand assessments don't rely on the Conditions for the Assessment Metric Type.