Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Mail script to get all variables attached to ritm

sbenson
Tera Contributor

I want to get all the variables that are attached to RITM but if value is blank than skip it.

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

I have something I already use and it's working fine for me so it should work for you too.

var scReqItem = new GlideRecord("sc_req_item");
scReqItem.addQuery("sys_id", current.sysapproval.toString());
scReqItem.query();
while (scReqItem.next()) {	
	var varown = new GlideRecord('sc_item_option_mtom');
	varown.addQuery("request_item", current.sysapproval.toString());
	varown.orderBy("sc_item_option.order");
	varown.query();
	while (varown.next()) {
		var visible = varown.sc_item_option.item_option_new.visible_summary;
		var question = GlideappAbstractChoiceListQuestion.getQuestion(varown.sc_item_option.item_option_new);
		question.setValue(varown.sc_item_option.value);
		if (question.getLabel() != "" && question.getDisplayValue() != "" && visible == true) {
			if (question.getType() == 20 || question.getType() == 19)
				continue;
			template.space(2);
			template.print(' ' + question.getLabel() + " = " + question.getDisplayValue() + "\n"  + "<br />");
		}
	}
}

View solution in original post

3 REPLIES 3

Mike Patel
Tera Sage

I have something I already use and it's working fine for me so it should work for you too.

var scReqItem = new GlideRecord("sc_req_item");
scReqItem.addQuery("sys_id", current.sysapproval.toString());
scReqItem.query();
while (scReqItem.next()) {	
	var varown = new GlideRecord('sc_item_option_mtom');
	varown.addQuery("request_item", current.sysapproval.toString());
	varown.orderBy("sc_item_option.order");
	varown.query();
	while (varown.next()) {
		var visible = varown.sc_item_option.item_option_new.visible_summary;
		var question = GlideappAbstractChoiceListQuestion.getQuestion(varown.sc_item_option.item_option_new);
		question.setValue(varown.sc_item_option.value);
		if (question.getLabel() != "" && question.getDisplayValue() != "" && visible == true) {
			if (question.getType() == 20 || question.getType() == 19)
				continue;
			template.space(2);
			template.print(' ' + question.getLabel() + " = " + question.getDisplayValue() + "\n"  + "<br />");
		}
	}
}

I had to tweak a little but was able to get what I wanted.

How can I use different language in this?