Server data Import with transform map

_bhishek
Tera Guru

Hi All,

 

I am updating server data in service now .I have coalesce on name field. There are duplicates servers available with names but only one server  Name among duplicates is operational .I want to update the server CI which is operational and no updates should happen in other duplicate CIs.

Also I am Updating assigned to .Mapped with email from user table. want to reference active user in case duplicate email ids found in service now while import .

Please help.

Thanks 

 

3 REPLIES 3

Mark Manders
Mega Patron

Use scripted field mapping to only update the active ones (query to the table and find the active one).

 

But you should first look at your data. Why do you have multiple servers with the same name, if the name needs to be unique? Otherwise you wouldn't coalesce on it. If it's old data, rename the old, non-operational ones by adding **old** to the name. If the coalesce is on name, you should only have one record with that name.

 

And the same goes for users. If you have multiple users with the same email address, that will be the same user, right? There is only one person behind the inbox of that email address. In case it is re-used, because your company hired Jack Smith and a year ago another Jack Smith left and they are now just giving that 'retired' email address to the new guy, you should remove it from the old one. 

 

I think you need to do some data cleaning instead of updating the transform map.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Ankur Bawiskar
Tera Patron
Tera Patron

@_bhishek 

you can use onBefore transform script and ignore the update if the target status is non-operational

something like this for ignoring the updates

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Add your code here
    if (target.operational_status.toString() != '1' && action == 'update') {
        log.info('Server is not operational so update is skipped');
        ignore = true;
    }

})(source, map, log, target);

To handle the user, you can use field map script and search only the active user and return only that user

Ensure "Referenced value field name" field on field map for user has sys_id in it

answer = (function transformEntry(source) {

	// Add your code here
	var incomingValue = source.u_user_name; // give your field name which holds the user data
	var gr = new GlideRecord("sys_user");
	gr.addQuery("name", incomingValue); // query with correct field, I used name
	gr.addActiveQuery();
	gr.query();
	if (gr.next()) {
		return gr.getUniqueValue();
	}
	else{
		return -1; // don't allow update
	}

})(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

Hi Ankur,

 

Thanks for your response .

I am facing issues with this .When I am using on before script to just update only operational CIs.If there are 3 CIs one is operational and other 2 operational .It is checking the 1st CI if that is non -operational ,it is just ignoring that one and no action /update for other whether it is operational or non-operational.

I used the script as mentioned for field map .But if there duplicate email id ,One user is active and other is inactive.It is not working as expected.

Could you please check.

 

Thanks.