Transform map field script to map with sys id

_bhishek
Tera Guru

Hello All,

 

I have 2 model category with same name as Tablet device in model table and . I want to  map only one model category(reference field on model table) in model table transform map when there is import which is correct and we don't want to map with old model .Could you please help me with field script of same .I think we can map with sys ID of correct model.

Thanks.

1 ACCEPTED SOLUTION

Hello @_bhishek 

 

Sure thing,

 

First you'll need to create new system property records with a string value and set the value to the sys_id of the related model.

JoeS1_0-1683128499077.png

 

Then update your field map script to get the system property value like this:

answer = (function transformEntry(source) {

	// Add your code here
	if (source.u_model == 'Alienware M14x') {
		return 'get(sys_property)';
	}
	else if(source.u_model == 'Alienware M17x') 
	{
		return gs.getProperty('cmdb.model.sys_id.alienware_m17x');
	}
	else
	{
		var gr = new GlideRecord("cmdb_model");
		gr.addQuery("name", source.u_model);
		gr.query();
		if (gr.next()) {
			return gr.getUniqueValue();
		}
	}

})(source);

 Now this does require a property for each sys_id you need to return. So the GlideRecord query can return sys_id's but however you can't use a system property.

View solution in original post

11 REPLIES 11

Joe S1
Kilo Sage

Hello,

 

Yes, you're correct you can just create a new Field Map that Uses a source script and set your return value to the sys_id of the Model you want to use. Then map the Target field to the correct field of the table you're importing into.

JoeS1_0-1682623382498.png

 

Hello Joe,

 

Thanks for your response.

I am testing my requirement with below script .Could you please check and tell me what I am doing wrong.

if (source.u_model == 'Alienware M14x') {
    answer = 'G Series';
}
elseif (source.u_model == 'Alienware M17x'
{
    answer = "46c41083a9fe1981017c3925c2004930";
}
else
{
    answer = source.u_model;

Ankur Bawiskar
Tera Patron
Tera Patron

@_bhishek 

the target field is of type reference right?

if yes then you need to set the sys_id of the record but here you are giving name

You are writing the script in field map script? share screenshot

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

Hello Ankur,

 

I have made some changes.Looks like it is working now ,I have tested with few records.Please take a look and let me know if you see any issue .

_bhishek_0-1682682133914.png