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

Hi,

in that case you will have to use if else but the issue would be choice values won't be found

Regards
Ankur

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

if else also wont work 😞 

@SNowUser11 

Thanks for marking my response as helpful.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

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

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

Hi Ankur,

Thanks it worked now the only change i made is instead of value I took Label since the values were different and also as integers. But this gave a good approach to make that work Thanks