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 on Hardware Asset Department

athavichith
Mega Sage

I'm trying to import set to set the department field on the alm_asset table. My data sources only contains the assigned_to. How can I set the department by referencing the assigned_to.department?

2 REPLIES 2

Mohammed8
Mega Sage

Hi @athavichith,

For this use case you can use field map script option, 

1)Create a new field map, Check the use source script checkbox

2)Target field will be Department, target table would be alm_asset

3)Write a script, Here is pseudo code:

 

var assignedTo = source.u_assigned_to; 
var deptId = "";

if (assignedTo) {
var userGr = new GlideRecord('sys_user');
userGr.addQuery('sys_id', assignedTo);
userGr.query();

if (userGr.next()) {
deptId = userGr.department + "";
}
}

return deptId;

if you find this answer useful, mark it as helpful/solution accepted.

 

Thanks and Regards,

Mohammed Zakir

VernYerem
Tera Expert

We ran into this issue. We have assets that are assigned via ServiceNow flows, assigned via swapping in an INC, and even manual issuances. We ended up making a business rule that pulled the department from the user when the 'assigned_to' attribute is changed. This makes sure that no matter what sets the assignment, it pulled the department. If you go this route, you just need to enable running business rules on your transform map.