Conditional Script for setting coalesce field in Transform Map

Mahak2
Kilo Guru

Hello guys,

At present I am using the Serial Number as Coalesce field in my Transform Map for Integration .

Now the problem is there are some CIs in my instance whose Serial Number is either empty or is using the different type of serial number as created by discovery which is Baseboard .And my data source is bringing the Bios Serial Number.

And hence due to these duplicates are being created. 

To solve this I am thinking to write the script 

As per that first priority for coalesce will be Serial Number .

But if it is empty or not matches I want to check the name of the Ci as 2nd option of coalesce .

How to achieve this ?

Can anyone help?

 

Regards ,

Mahak

1 ACCEPTED SOLUTION

Hi Mahak,

if you have removed the coalesce then the action == 'update' won't work

also action == "insert" won't work

try to modify the code as suggested by me earlier

target object won't give you the target field value as you have removed the field map and coaslece

Regards
Ankur

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

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Mahak,

you will have to handle this via onBefore transform script and query the target table with serial number field.

if not found then you can check the name of the Ci in another field and based on that decide to update/insert record

Regards
Ankur

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

Hello Ankur,

SHould we use the ONbefore script or in the COalesce field use the target field as sys id and then check for the conditions?


var gr = new GlideRecord('ABC');

var rr = gr.addQuery('serial_number',source.u_bios_serialnumber);
rr.addOrCondition('name' , t);
rr.addOrCondition('dns_domain', source.u_computer_domain_name);
gr.query();

if(gr.next())
{

return gr.sys_id;}
else
{

return '' ;

}

Using this no data is getting inserted in the target table.

 

Also i have tried using the below Onbefore script but that was also not working:

 

if(action == "update" && source.u_bios_serialnumber == target.serial_number && target.discovery_source != "ABC")

{


ignore=true;

}
else if(action == "insert" && (source.u_operation_system == 'Windows Server 2008 Enterprise Edition')||(source.u_operation_system == 'Windows Server 2008 R2 Standard Edition')||(source.u_operation_system == 'Windows Server 2008 Standard Edition')||(source.u_operation_system == 'Windows Server 2012'))
ignore = false;
}
else if(action == 'insert' && source.u_bios_serialnumber != target.serial_number && source.u_computer_domain_name == target.dns_domain && t == target.name && target.discovery_source != "ABC")
{
ignore = true;
}

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

 

Can you please help here what should i do .

And additionally i am using dns domain also because some CI's have same name but diffferent dns domain and serial number ,and we want to insert those CI's and exclude the ones which are having the same name,different serial number and same Domain name.

Regards,

Mahak

 

 

 

Hello Ankur,

@Ankur Bawiskar can you please help here?

@Mahak 

handle only with onBefore script and not field map

Regards
Ankur

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