How to clear out the field on target table via Web Service + Transform Map

andriyko
Giga Contributor

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!

10 REPLIES 10

Naveen31
Giga Contributor

Hi,

I have a requirement to clear the 'CA Template' reference field in Certificate form, when i select the "undefined" and after saving the field should be become  Blank and field should become mandatory. after that if i select another value it will populate what ever value i will select .I tried out the following code in the Transform script field of the 'CA Template'.

find_real_file.png

 

answer = (function transformEntry(source) {
var ch = source.u_ca_template.toString();
var check = new GlideRecord('x_palad_cert_ca_template');
check.addQuery('dn',ch);
check.query();
if (check.next()){
var check1 = check.dn;
}
// Add your code here
return check1; // return the value to be put into the target field

})(source);

find_real_file.png