
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2024 11:08 PM
Hi!
Would like to ask some help regarding transform map scripting, this is to copy a new data uploaded from source field and target field which is located in another table.
Tried BR and unable to make it work, did some research and found about transform map scripting and I'm still trying to learn it.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 01:03 AM
try this
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
/* 1. Get the value of source field */
var sourceValue1 = target.name;
/* 2. Glide record on Table in which you want to update the record */
var gr = new GlideRecord('service_offering');
gr.initialize();
gr.name = sourceValue1 + new GlideDateTime().getLocalDate();
gr.insert();
})(source, map, log, target);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 05:56 AM
Thanks @Ankur Bawiskar, it's working now!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2024 06:57 AM
If i understand correctly, your requirement is to copy the record in service_offering when you have a new record in cmdb_ci_service.
To achieve this there can be multiple methods but the easy way was the solution you were trying before with BR.
1. Your After BR should be on the source table (cmdb_ci_service). Check only insert checkbox as it has to run only for new records . All this data will be in the current object which you will use in step 2.
2. Use this current object to create a record in your target table ( service_offering ). Set all the required fields you want in the target table by dot walking the current object.
I did have a look at your BR in previous comments but seems it was not correct. Also you should avoid hardcoded sys_ids . You can get them from current object.
Try the solution and let me know for issues with snaps to explain.
Thanks,
Tanuj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2024 08:45 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2024 09:01 PM
Would you please check my script to see what I missed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 01:12 AM
Sure, I can help you with that. Transform Map scripting in ServiceNow is used to map source data to target data. Here's a simple example of how you can do it:
1. Navigate to System Import Sets > Create Transform Map.
2. Click on New to create a new Transform Map.
3. Fill in the required fields (Name, Source table, Target table).
4. In the 'Field Maps' related list, click on 'Auto Map Matching Fields' or manually create field maps.
5. In the 'onBefore' or 'onAfter' script fields, you can write a script to manipulate the data during the transformation process.
Here's a simple example of a script you might use:
javascript
(function transformEntry(source, target, map, log, isUpdate) {
// This is an example script that copies data from the source 'u_source_field' to the target 'u_target_field'
target.u_target_field = source.u_source_field;
})(source, target, map, log, action);
In this script:
- source refers to the Import Set Row (the data you're importing).
- target refers to the target table (where you want the data to go).
- map is the Transform Map.
- log is a GlideRecord for the Import Log.
- action is a string that will be either 'insert' or 'update', depending on whether the Transform Map is inserting a new record or updating an existing one.
Remember to replace 'u_source_field' and 'u_target_field' with the actual field names you're using.
This script should be placed in the 'onBefore' script field if you want it to run before the transformation happens, or in the 'onAfter' script field if you want it to run after the transformation.
Please note that this is a very basic example and you might need to adjust it to fit your specific needs.
nowKB.com