- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2025 01:32 AM
Hi,
I have a transform map to the core_company table, i modified my csv file to add a column i called action_type, i want to update, create or delete through the action defined. I created a script in the transform, but it doesn't work, can someone help me with the code please
(function transformEntry(source, target, map, log, isUpdate) {
var action = source.u_action_type + '';
if (action == 'ignore') {
ignore = true;
return;
}
if (action == 'delete') {
var existing = new GlideRecord('core_company');
if (target.u_name) {
if (existing.get('u_name', target.u_name)) {
existing.deleteRecord();
log.info('Record deleted: ' + target.u_name);
} else {
log.warn('Record not found for deletion: ' + target.u_name);
}
} else {
log.warn('u_name is not defined in target; cannot delete.');
}
ignore = true;
return;
}
})(source, target, map, log, isUpdate);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2025 04:03 AM
Hi @Jeff W NZAO B ,
you can try below code
create onBefore type transform script
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var action= source.u_action_type.toString().toLowerCase(); // u_action_type column name of csv
var existingCompany = new GlideRecord("core_company");
existingCompany.addQuery('name',source.u_name); // u_name column name
existingCompany.query();
if(action =='insert'){
if(existingCompany.next()){
target.sys_id= existingCompany.sys_id;
}
}
if(action =='delete'){
if(existingCompany.next()){
gs.log('Record deleted: ' + target.name); // target.name is core_company table name field
existingCompany.deleteRecord();
}
gs.log('Record not found for deletion: ' + target.name);// target.name is core_company table name field
igonre= true;
}
})(source, map, log, target);
Please mark my answer correct & helpful, if it helps you
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2025 04:11 AM - edited ‎05-13-2025 04:13 AM
Hi @Jeff W NZAO B ,
From your description I can understand that you have 3 type of action they are insert, update or delete.
In the transform map you will need to create do the field mapping and making one of the field as unique. For example you can consider name as unique field. This will sort out your insert and update actions.
For Delete action, you can create a new "onbefore" transform map script and use the following code:
Please mark the answer helpful and correct if it helps the issue. Happy scripting 🙂
-Shantanu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2025 04:03 AM
Hi @Jeff W NZAO B ,
you can try below code
create onBefore type transform script
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var action= source.u_action_type.toString().toLowerCase(); // u_action_type column name of csv
var existingCompany = new GlideRecord("core_company");
existingCompany.addQuery('name',source.u_name); // u_name column name
existingCompany.query();
if(action =='insert'){
if(existingCompany.next()){
target.sys_id= existingCompany.sys_id;
}
}
if(action =='delete'){
if(existingCompany.next()){
gs.log('Record deleted: ' + target.name); // target.name is core_company table name field
existingCompany.deleteRecord();
}
gs.log('Record not found for deletion: ' + target.name);// target.name is core_company table name field
igonre= true;
}
})(source, map, log, target);
Please mark my answer correct & helpful, if it helps you
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2025 12:53 AM
Thanks, instead of deleting, i did a turn to false the state of the data. So i renamed the action_type to active_status, so i keep the data but it's said if it's active true or false
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2025 04:11 AM - edited ‎05-13-2025 04:13 AM
Hi @Jeff W NZAO B ,
From your description I can understand that you have 3 type of action they are insert, update or delete.
In the transform map you will need to create do the field mapping and making one of the field as unique. For example you can consider name as unique field. This will sort out your insert and update actions.
For Delete action, you can create a new "onbefore" transform map script and use the following code:
Please mark the answer helpful and correct if it helps the issue. Happy scripting 🙂
-Shantanu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2025 12:54 AM
Thanks, instead of deleting, i did a turn to false the state of the data. So i renamed the action type to active status, so i keep the data but it's said if it's active true or false