Is it possible load data without field map

nagaklv
Tera Contributor

Hello Community,

 

Is there any possibility without field map to update traget table records with import sets.If so can anyone help me with sample script and it will not create new records it should check source sys I'd with traget sys I'd if identity it should update the target records.

 

Thanks,

1 ACCEPTED SOLUTION

Ahmmed Ali
Mega Sage

Hello,

 

You can use below script in transform map script to update target record:

var gr = new GlideRecord(target.getTableName());
gr.addQuery("sys_id", source.getValue("FIELD_NAME_HOLDING_SYS_ID_IN_SOURCE_TABLE"));
gr.query();
if(gr.next()){
//update fields here as per your requirement
gr.FIELD_NAME = source.FIELD_NAME;
gr.update();
}else{
ignore = true;
}

 

But I am wondering why you do not want to user field map and go for script. unless you need to manipulate/format data and then copy to target field, it is recommended to use field map as it is easiest way to configure transform map.

 

Thank you,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

10 REPLIES 10

Ahmmed Ali
Mega Sage

Hello,

 

You can use below script in transform map script to update target record:

var gr = new GlideRecord(target.getTableName());
gr.addQuery("sys_id", source.getValue("FIELD_NAME_HOLDING_SYS_ID_IN_SOURCE_TABLE"));
gr.query();
if(gr.next()){
//update fields here as per your requirement
gr.FIELD_NAME = source.FIELD_NAME;
gr.update();
}else{
ignore = true;
}

 

But I am wondering why you do not want to user field map and go for script. unless you need to manipulate/format data and then copy to target field, it is recommended to use field map as it is easiest way to configure transform map.

 

Thank you,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Will this script to avoid creation of new records in traget table??

Yes, the script is checking if there is already record present in target table with provided sys_id, if yes then it will update existing data. if no, then it will just ignore the update.

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

it's not working and it's creating new records in change table and not updating the value in the description.Below is the script we are trying

 

var gr = new GlideRecord('change_request');
gr.addQuery("sys_id", source.getValue("u_element_id"));
gr.query();
if (gr.next()) {
//update fields here as per your requirement
gr.description= source.u_value;
gr.update();
} else {
ignore = true;
}