Staging Table choice field is not getting mapped to Target table choice field when blank space is provided.

vivek dhasmana
Kilo Contributor

Hello All Members,

I just started learning ServiceNow recently and trying hard to understand a problem that I am facing.

I have a staging table setup using import set option(xml) and I am trying to update a choice field type in target table(sys_user)  via staging table as its not a good practice to update target table directly.

So I am using a onbefore script to update a choice field type to --NONE-- in staging table by below script when there is a blank space provided by the user in order to update existing choice field.The script is working fine i guess and I am able to see that staging table is getting updated to --NONE--, The real issue is this --NONE-- is not getting reflected in the target table field and the previous choice type is remain unchanged.

I am using custom field and defined the field in both target as well as staging table and configured the mapping using transform map too. I just want to know why the staging table choice field is not getting mapped to target table(Other fields are working fine and getting updated successfully,Its only the choice field).

Could somebody please guide what approach should be followed in this,Thanks in advance.I have attached all screenshots for reference.

 

var gr = new GlideRecord('sys_dictionary');
gr.addQuery('name','my staging table name');
gr.query();
while (gr.next()) {
var ele = gr.element;
var val = source.getValue(ele);
if (!gs.nil(ele)) {

if (val !== " ") {

source.setValue(ele,val);

}
else {

source.setValue(ele,"NULL");
}
}
}

 

 

6 REPLIES 6

Rajesh M1
Giga Guru

Hi 

 

In your transform map have you checked "Copy Empty Fields"? Keeping this field as true will copy empty source fields and override existing target field values.

 

find_real_file.png

 

Mark answer as correct/helpful if it resolves your query/issue.

 

Best Regards,

Rajesh M.

Hi Rajesh,

Thanks for the suggestion, However I have already tried this and checking "Copy Empty Fields" checkbox is clearing out other fields as well which I don't want.

I want to clear only my custom made choice field(u_team) to get reset to --NONE-- when i send ""(single space).Also if there is any other way to reset the choice field if someone passes single space then please do let me know.