Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Transform Map Source field script returning UNDEFINED for sys_id

Camila Godoy
Tera Expert

Hi team

I am getting these source values from an excel

RoomLocation
Room123NY

 

Using a transform to generate the data.

 

The field map source consists on the script below.

The target table source is a location field with reference to cmn_location.

 

The reason I need the script below is because we can have Room123 in different cities.

 

However, when I ran the transform map the location received UNDEFINED value.

Note that I am testing with data that source matches location.

 

answer = (function transformEntry(source) {

var l = new GlideRecord('cmn_location');
var qc = l.addQuery('full_name', 'CONTAINS', source.location);
qc.addOrCondition('state', 'CONTAINS', source.location);
l.query(); //Execute the query

while (l.next()){
if (l.name==source.room){
return l.sys_id; // return the value to be put into the target field

}

}

})(source);

 Please let me know if you have ran into this.

more info of the target field.

CamilaGodoy_0-1676474510727.png

 

thank you!
Camila

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Camila Godoy 

update script as this

Ensure you use correct field names from source table; As per my understanding it should be u_room, u_location

answer = (function transformEntry(source) {

	var sysId;
	var l = new GlideRecord('cmn_location');
	l.addQuery('name', source.u_room);
	var qc = l.addQuery('full_name', 'CONTAINS', source.u_location);
	qc.addOrCondition('state', 'CONTAINS', source.u_location);
	l.query(); //Execute the query
	if (l.next()){
		sysId = l.sys_id;
	}
	return sysId;

})(source);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Camila Godoy 

update script as this

Ensure you use correct field names from source table; As per my understanding it should be u_room, u_location

answer = (function transformEntry(source) {

	var sysId;
	var l = new GlideRecord('cmn_location');
	l.addQuery('name', source.u_room);
	var qc = l.addQuery('full_name', 'CONTAINS', source.u_location);
	qc.addOrCondition('state', 'CONTAINS', source.u_location);
	l.query(); //Execute the query
	if (l.next()){
		sysId = l.sys_id;
	}
	return sysId;

})(source);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Thank you so much!! You were right. I was naming the source wrong.

here is my final code.

 

answer = (function transformEntry(source) {
	var sysId;
	var l = new GlideRecord('cmn_location');
	var qc = l.addQuery('full_name', 'CONTAINS', source.u_location);
    qc.addOrCondition('state', 'CONTAINS', source.u_location);
    l.query(); //Execute the query
    
while (l.next()){
	if (l.name==source.u_room){
				sysId = l.sys_id;
	}
	}
	return sysId;	// return the value to be put into the target field
	
})(source);

@Camila Godoy 

Glad to help

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