How to set value of a choice field, that has Reference qual set up?

michaelpelenski
Kilo Contributor

Hello, Community experts

I'm targeting to automate Vendor's risk rating definition, that will be based on conditions, that come out of GRC module.

When reviewing risk rating field dictionary, I've noticed that it's values come from sn_grc_choice table, and there is a reference qual set up: 

javascript: new sn_grc.GRCChoiceUtils().getGRCChoices('risk_rating', current.sys_class_name)

When I attempt to set the value of this choice field via Business rule, neither of approaches I've treid so far work: 

setValue(); setDisplayValue(), assigning value through a variable, etc. ended up in a new value appearing in the dropdown choice list rather then setting one of exising values. 

What am I doing wong here? How to map the values correctly for such type of a field? 

P.S. Regular choice fields, that get configured through choice list work fine for me, but this one makes me go crazy.

 

1 ACCEPTED SOLUTION

Can you try the below script. I made few improvements. Where are you running this business rule?

(function executeRule(current, previous /*null when async*/) {

	var risk_ratings = new GlideRecord('sn_grc_choice');
	risk_ratings.addQuery('choice_category','risk_rating');
        risk_ratings.addQuery('name','high');
	risk_ratings.query();
	// gs.addInfoMessage('found ' + risk_ratings.getRowCount(), 'risks');
	if (risk_ratings.next()){
		var risk = risk_ratings.getValue('sys_id');
		gs.addInfoMessage('sys id is ' + risk);
		var vendor = new GlideRecord('core_company');
		vendor.addQuery('name', 'test');
		vendor.query();
		// gs.addInfoMessage('Vendors count ' + vendor.getRowCount(), 'risks');
		while(vendor.next()){
			vendor.setValue('risk_rating', risk);
vendor.update();
			gs.addInfoMessage('Risk rate is set to '+risk);
		}
	}
})(current, previous);

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

6 REPLIES 6

I guess the reason could be in an attribute set to field risk_rating at core_company table: 

Read only click through 

I'll try to set this attribute to false and give it another shot with your suggested approach.

Well, setting attribute to false didn't work out. ( continuting trying