- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2024 11:37 AM
I have a field named Contract Status that contains the following choice list: Active, Completed, Cancelled, Terminated. There are instances where there are invalid values added to the spreadsheet (e.g. Canceled (with one L)). I tried two (2) scenarios but it's not the outcome I'm looking for:
1. In the Field Maps, the Choice action field is set to Ignore. When I load the data with an invalid value, two things are happening: if there is no value in that existing record, the invalid value will update to (empty), which is great! But my problem lies here... when an existing record has an existing value (e.g. Active) and the field in the spreadsheet has an invalid value (e.g. XYZ), the field isn't updated to (empty). It keeps the existing value (e.g. Active). I want the record to update to be (empty) instead.
2. In the Field Maps, the Choice action field is set to Reject, but I want the record to be updated so this route doesn't work for me.
I'm not sure if I need to run an onBefore Transform Script? Sorry, very new to this. Any feedback would be appreciated. Can provide more context as well if this is confusing. Thank you!
Screenshot for reference:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2024 12:41 PM - edited 04-12-2024 12:43 PM
Try the following:
answer = (function transformEntry(source) {
var sourceStatus = source.getValue('your_source_field_name');
sourceStatus = sourceStatus.toLowerCase();
if ( sourceStatus == "active" || sourceStatus == "completed" || sourceStatus == "cancelled" || sourceStatus == "terminated") {
return sourceStatus;
} else {
return '';
}
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2024 02:24 PM - edited 04-11-2024 02:26 PM
Hi @Phong Lo,
You can use onBefore Transform Script or Field Map with 'Use source script'.
Both would work but I would prefer using the Field Map's script.
Within the script, you can add your logic of using the source value if it's a valid choice, otherwise clear the target value.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2024 06:24 AM
I wrote the following code in the 'Use source script' but it's clearing all the fields to empty when I upload data. Am I missing something?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2024 12:41 PM - edited 04-12-2024 12:43 PM
Try the following:
answer = (function transformEntry(source) {
var sourceStatus = source.getValue('your_source_field_name');
sourceStatus = sourceStatus.toLowerCase();
if ( sourceStatus == "active" || sourceStatus == "completed" || sourceStatus == "cancelled" || sourceStatus == "terminated") {
return sourceStatus;
} else {
return '';
}
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2024 01:44 PM
That worked. Thank you!
