com.glide.script.RhinoEcmaError: "target" is not defined.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 02:24 AM
Hi All, I m getting below error in system logs in transform map field script
com.glide.script.RhinoEcmaError: "target" is not defined.
Coalesce Field map script is not working, Please give suggestions!
Coalesce = True
Use source script check box checked
Field mapping script
answer = (function transformEntry(source) {
var sourceMAC = source.u_mac_address.toString();
var hwPriMAC = target.mac_address.toString();
var hwSecMAC = target.u_additional_mac_address.toString();
log.info("PrimaryMAC17081997: " + hwPriMAC + "SecMAC17081997: " + hwSecMAC);
var cleanedhwPriMAC = hwPriMAC.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
var cleanedhwSecMAC = hwSecMAC.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
log.info("cleanedhwPriMAC17081997: " + cleanedhwPriMAC + "cleanedhwSecMAC17081997: " + cleanedhwSecMAC);
if (sourceMAC == cleanedhwPriMAC) {
log.info("matchif17081997");
return hwPriMAC;
} else if (sourceMAC == cleanedhwSecMAC) {
log.info("elseif17081997");
return hwSecMAC;
} else {
log.info("NoMatchFound17081997");
return '';
}
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 02:31 AM
Hello @Community Alums ,
Please give a try to the script below and let me know how it works for you.
answer = (function transformEntry(source, target) {
var sourceMAC = source.u_mac_address.toString();
var hwPriMAC = target.mac_address.toString();
var hwSecMAC = target.u_additional_mac_address.toString();
log.info("PrimaryMAC17081997: " + hwPriMAC + " SecMAC17081997: " + hwSecMAC);
var cleanedhwPriMAC = hwPriMAC.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
var cleanedhwSecMAC = hwSecMAC.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
log.info("cleanedhwPriMAC17081997: " + cleanedhwPriMAC + " cleanedhwSecMAC17081997: " + cleanedhwSecMAC);
if (sourceMAC == cleanedhwPriMAC) {
log.info("matchif17081997");
return hwPriMAC;
} else if (sourceMAC == cleanedhwSecMAC) {
log.info("elseif17081997");
return hwSecMAC;
} else {
log.info("NoMatchFound17081997");
return '';
}
})(source, target);
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 02:36 AM
Hi @Aniket Chavan , Thanks for your prompt reply,
I tried above code but still i m getting same error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2024 09:57 AM
Hi @Community Alums
Have you got answer for this one?
I am getting the same error for the transform map field map script.
Please let me know if you have any leads.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2025 07:42 AM
It seems that if you are getting this error, adding target to the function definition fixes it.
I did the same thing where we are checking to see if the user_name field is populated on the target record then do not update it. Else send over the source. (The customer has two sources of truth for user data, but only the data from LDAP wins). While I feel that the user_name should always be populated, there are times where it is not. So in the field mapping for the user_name, (coalesce = true) I have a script that says, if the target is empty send over the source, otherwise send over the target (so we do not get an undefined). It failed with the error of Target is not defined. I added target to the function definition and it worked from there out.
Here's an example:
answer = (function transformEntry(source, target) {
//If the target field is empty then populate it with the source.
//Otherwise return the target data so that we do not have undefined returned.
if (!target.user_name) {
return source.u_ad_user_name;
} else {
return target.user_name;
}
})(source);