- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2015 04:35 PM
Hi,
I am trying to import data into my user table. I have the following questions:
1. How do i skip a field getting copied from source to target if source is empty. (not a row but field) - Can i do something at onbefore script or field map script
2. Also, say i want to skip a particular field only and update the rest what would be the best way to achieve it.
3. Although a field is coalesced, we are seeing multiple entries being created in the target table. Is not supposed to just update instead of creating new rows in the table.
Need help for above questions pls.
Thanks
Message was edited by: Venkat R
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2015 11:12 PM
Hi, Venkat.
1. How do i skip a field getting copied from source to target if source is empty. (not a row but field) - Can i do something at onbefore script or field map script
By default a transform map won't update target fields if the source field is empty. There's a checkbox on the transform map form called 'Copy empty fields' which is off by default. If you check it then target fields would be updated with a blank value. I
2. Also, say i want to skip a particular field only and update the rest what would be the best way to achieve it.
I'm not sure I quite understand what you are after here. If you want to skip a field just don't include it in the field map or transform scripts. If you want to conditionally skip a field then, as Berny mentioned, you can use a transform script to conditionally set target fields based on the source field value. You don't put the source/target fields in the field map list but instead use a Before transform script (or the script on the main transform map form) to set the target field
3. Although a field is coalesced, we are seeing multiple entries being created in the target table. Is not supposed to just update instead of creating new rows in the table.
If the ID field is truly the only field with Coalesce checked then something else is causing the duplicates. In your instance I know you have tenant separation so there could be tenant-separation query business rules that are preventing the transform process from finding the record with the matching ID.
Thanks.
- Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2015 07:51 PM
Hi Venkat,
http://wiki.servicenow.com/?title=Transform_Map_Scripts#gsc.tab=0
Kindly check this section of wiki for complete transform map script understanding.
1) You can write down onBefore transform map script where your one of the code line would be
if(source.u_fieldNameThatIsToBeCheckedForNull != '')
{
ignore = true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2015 10:41 PM
Hi Venkat,
Here goes some suggestions:
On 1) Here is one way of doing it:
if (source.u_mail.toString().length > 0){
answer = source.u_mail.toLowerCase();
}
On 2) You will just need to make sure you're not adding that field to the field transform map.
On 3) It will create a new record whenever a match was not found using the coalesce field. Make sure the values you're trying to coalesce on are exactly the same.
I hope this is helpful and please let us know if you have any other further questions.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2015 01:43 PM
Hello Berny,
Thanks for your suggestions. Though your pointers are helpful I have these follow up questions:-
For 1) You gave me the source script within a if condition. What happens if the condition is not met. Does it skip the update of the target or or does it add null value to the target.
For 2) All the fields have to be there in the field map. So say I have a field map of 15 fields. And while I update rows, I dont want to update for specific fields within that row but for others I need to update. So basically in short I want to know whether we can do ignore operation at field level rather than row level which is available now.
For 3) I have the field coalescing on ID but it is creating with multiple same ID.
Regards,
Venkat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2015 01:54 PM
Hi Venkat,
you're welcome buddy!
on #1, i believe the way it works is that no value will be assigned to the target field if there's no assignment to the answer variable. Meaning, i believe that it may even keep the value the field had before doing the transform.
on #2, not all fields have to be in the field map. You can always use the transform scripts to update a target field when xyz conditions are met or choose to ignore it according to the conditions you can script at any of the transform scripts.
on #3, check if you have multiple field with the coalesce as true. That may be the issue.
Thanks,
Berny