Transform map Field Map updates wrong choice for empty values

SNowUser11
Kilo Guru

HI,

When I ma transforming a record for a specific Choice field when source.u_state is empty it enters a random choice for the record and does not update it as 'NONE' which is system default. I dont want to create another Choice value with None does not makes sense. Neither Copy empty fields work.

But then how can it be set to None when there is no value in that source.u_state? Any suggestions please.

Thanks

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

sample script below

Ensure you give valid table name and the target field

Use source script for this field map

answer = (function transformEntry(source) {

	// Add your code here
	var tableName = 'incident';
	var fieldName = 'category';
	var rec = new GlideRecord('sys_choice');
	rec.addQuery('name=' + tableName + '^element=' + fieldName + '^value=' + source.u_state);
	rec.query();
	if(rec.next()){
		return rec.value;
	}
	
	return ""; // return the value to be put into the target field

})(source);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

10 REPLIES 10

You are welcome

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader