How to clear out the field on target table via Web Service + Transform Map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2015 11:32 AM
I have a web service with fields: "assigned_to", "assignment_group" and "task_id".
And transform map where target table is Task[task].
Transform map has field map:
task_id -> sys_id
assigned_to - > assigned_to
assignment_group -> assignment_group
Transform map has "Copy empty fields" set to "false".
Lets say I have an incident with assigned_to field set to some user.
According to wiki page Creating New Transform Maps - ServiceNow Wiki it should be possible to clear out the field by passing "NULL" string.
The POST data looks like:
{"task_id": "d48ec9460fd70240197f0cbce1050e42", "assigned_to": "NULL"}
Then response contains:
...
"status": "ignored",
"status_message": "No field values changed",
...
The field "assigned_to" gets updated(cleared) If "Copy empty fields" is "true". So, now "Copy empty fields" options is "true".
Lets say I have an incident with "assignment_group=Database", "assigned_to=''".
I want to update "assigned_to" field. POST data is:
{'task_id': 'd48ec9460fd70240197f0cbce1050e42', 'assigned_to': 'ee826bf03710200044e0bfc8bcbe5de6'}
The target record is updated, it has correct "assigned_to", but now "assignment_group=''" is empty, it was cleared.
So, if I want to clear out the field, I have to use "NULL"+"Copy empty fields". In that case all the fields that were not passed in POST data will be cleared on target record.
Without "Copy empty fields" option, fields that are not passed in POST data are not updated, but setting of "NULL" does not clear out the field.
What magic combination of checkboxes in transorm map will give me desired functionality/behaviour?
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2015 12:27 PM
Just update the transform map to go by a script. Don't copy empty fields.
if(source.assigned_to == 'NULL')
answer = '';
else
answer = source.assigned_to;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2016 02:16 AM
Hi all,
yesterday I had the same issue:
I wanted to use a Source Script in a Field Mapping. The "answer" variable simply wouldn't work correctly when trying to clear the value of a reference field.
It seems like the display value for the reference was set to "NULL" but the field would still show a reference in it (the XML of course shows the sys_id).
Here is how I solved it:
I use the target object instead of the answer variable.
Below I pasted in some lines from my script
notes:
- mgr = GlideRecord
- I usually use the get and set methods
..
...
if (mgr.next()) {
// A)
// if the user exists, put him in as the new manager
target.setValue("manager",mgr.getValue("sys_id")); // use target - answer variable doesn't work properly
} else {
// B)
// if the user doesn't exist, delete the manager
target.setValue("manager","NULL"); // use target - answer variable doesn't work properly for clearing reference fields
}
Maybe it helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2016 02:20 AM
My next step to solve this would have been to use an onBefore script like Dinesh has done here:
Re: Field Map Transform script
But he also uses the target object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 10:40 AM
I was able to get this working with the following onBefore script:
Note: The team sent in the value 'empty', rather than 'NULL' used by many others on the community.
if(source.u_assigned_to == 'empty'){
target.assigned_to = '';
} else {
target.assigned_to = source.u_assigned_to;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2019 04:51 AM
I've managed to achieve clearing a field value using a transform map by using an onBefore script, something like
target.<table field> = source.<import set field>