Unable to clear existing choice field with none by passing space or nothing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2018 03:16 AM
Hi All, I am very new to service now and stuck with a problem.
I have created a custom attribute named Team on target table and configured everything to map between source and target table.I have some value inside choice field and which i want to clear when i send blank space or leave the field as blank, The problem is the onBefore event script is not working properly i guess and when I am sending blank space,The target field is showing as the last updated field in choice list(Want to make is 'none'). Below is my onBefore event script. Any help is highlty appreciated.
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");
}
}
}
- Labels:
-
Personal Developer Instance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 12:42 PM
It is unclear what you are trying to achieve. You mention source and target, are you trying to set a value when importing? If you are, it seems a bit excessive to try and write a script on the transform to pass a blank value to the target field. I do not see that information in your script as to what values you are pulling in from the source column, nor do I see anything that indicates what target field you are trying to set.
Please provide some screen shots of what you have built so we can better understand what you have and what you want to achieve.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 10:55 PM
Ok I will elaborate the issue more along with screenshots
->I have created a custom field with choice lists at Service now.
->I am using Transform map to to set the choice field value from source table to target(sys_user SN table)
->I am able to update and change the existing choice field value at SN side.
-->The issue is when I am sending a blank space it is not clearing the choice field value at target.
I want to clear the choice field value at target table which is sys_user in this case when i send blank space(I am passing string value type from source side).Currently it is not clearing the value at target field and showing previous set values.I am using below onBefore script to achieve this but somehow it is not working for choice field, FYI It is working for Normal field value( clearing the target when i am sending blank space)
if(!source.password.nil())
{
target.user_password.setDisplayValue(source.password);
source.password.setDisplayValue("");
}
var gr = new GlideRecord('sys_dictionary');
gr.addQuery('name','my table name');
gr.query();
while (gr.next()) {
var ele = gr.element;
var val = source.getValue(ele);
if (!gs.nil(ele)) {
if (val !==" ") {
log.info("This is an information message if part "+gr.getDisplayValue()+ " " + val);
source.setValue(ele,val);
}
else {
log.info("This is an information message else part "+gr.getDisplayValue()+ " " + val);
//g_form.setValue(gr.getDisplayValue(),'--None--');
source.setValue(val,"NULL");
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2018 06:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2018 02:22 AM
Hi ccajohnson,
If I check the Copy empty Fields checkbox then all the fields along with custom field is getting cleared and becoming null or empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2018 02:30 AM
Hi Everyone.
I am trying to map choice field values from staging table to target table(sys_user in this case) and when I pass single space I want the staging table choice field to be reset to(--NONE--) which then will update the target SN table.Please let me know if anyone is able to achieve this(choice field manipulation) using on Before script or any other method.
Thanks in advance.
Regards
Vivek Dhasmana