Populate custom reference with document Id type field

Rocky5
Kilo Sage

Hello Experts,

 

On metrics form we have a ootb 'ID' field ('Document id' type) that stores the record to which the metric is belonged to. So, I have custom field created on it called 'Project'. So, If the 'ID' field has project record in it then I want to populate project field with same record as 'ID' field. How can I do that?

 

Rocky5_0-1690913307345.png

 

 

Thanks,

Rocky.

1 REPLY 1

Dominik9
Tera Guru

Hi Rocky

 

May one option could be to create a business rule where you query the project table for the "ID" record. If the record exist you set the project field in your metric record. Something like: 

Filter conditions: ID changes

Script (Adapt script with your table/field values): 

(function executeRule(current, previous /*null when async*/) {
	
	var grMetric = new GlideRecord('metric');
	if (grMetric.get(current.id.toString())){
		current.project = current.id.toString();
	} else {
		current.project = '';
	}

})(current, previous);

If the project field has to be populated immediately you could do the same with a client script glideajax call. 

 

Best regards

Dominik