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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can have field map script for this

1) check if that choice value is present in sys_choice for this field

2) if yes then return that value

3) if not then return ''; so that it sets the none value

Regards
Ankur

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

Hi Ankur,

Yes all choice are available in choice list and we have created then well before import. Issue is only when there is no value then it updates any random choice from the available choice list instead it should set it to 'None'.  Let me try the way with sys_choice and let you know if empty ones are updated as 'None'

Thanks

Hi,

Since choice value of None has empty string so I have used that

return '';

Regards
Ankur

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

Tried what is happening is my target table is cmdb_ci_business_app and target field is install_status . What is happening the IF condition eventhough it matches i checked log it perfectly executes IF block but it does not update since this table is extended from cmdb_ci and in cmdb_ci the value of same choice is different.

what I mean is in cmdb_ci  , column 'Status' , choice Migrate is having value=104 but 

in cmdb_ci_business_app  , column 'Status' , choice Migrate is having value=Migrate and hence it does not update the record with Migrate

Any suggestions please Thanks