- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2022 09:30 PM
HI,
I have written the below OnBefore script on Transform map on Hardware table. However it is not working ..
If both the assigned to and loc is empty then below target fields mentioned should update and if the assigned to or loc is empty , the the fields in target table should update.
Need Help !
if ((source.u_assign_to == "") && (source.u_loc == "")) {
target.assigned_to = "";
target.managed_by = "";
target.owned_by = "";
target.u_loc = "";
target.install_status = "6";
target.substatus = "1";
} else
if (source.u_assign_to != "" || source.u_loc != "") {
target.install_status = "1";
target.stockroom = "";
target.u_inuse = true;
}
Thanks,
M
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2022 02:04 AM
Hi @manasa
Your script is incorrect. Please use the modified version below:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
if (JSUtil.nil(source.u_assign_to) && JSUtil.nil(source.u_loc)) {
target.assigned_to = "";
target.managed_by = "";
target.owned_by = "";
target.u_loc = "";
target.install_status = "6";
target.substatus = "1";
} else {
target.install_status = "1";
target.stockroom = "";
target.u_inuse = true;
}
})(source, map, log, target);
Let me know if you are facing an issue. Would suggest to make use of JSUtil to check if value of source field is empty or not, I am saying this from my personal practical experience as sometimes "== blank' did not work for me. So I recommend using JSUtil.nil or JSUtil.notNil to check for empty or non empty values.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2022 02:00 AM
Hi,
If your main concern is system not executing if part even if both values are empty then reason could be, in programming language empty values are stored in 3 different ways, it can null or undefined or "".
You could try below,
if((source.u_assign_to == "" || source.u_assign_to ==undefined || source.u_assign_to ==null) && (source.u_loc == "") || source.u_loc == undefined || source.u_loc ==null)
or you can use nil() function as below
if(source.u_assign_to.nil() &&
for more info on nil() function, you can see below documentation example
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2022 02:04 AM
Hi @manasa
Your script is incorrect. Please use the modified version below:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
if (JSUtil.nil(source.u_assign_to) && JSUtil.nil(source.u_loc)) {
target.assigned_to = "";
target.managed_by = "";
target.owned_by = "";
target.u_loc = "";
target.install_status = "6";
target.substatus = "1";
} else {
target.install_status = "1";
target.stockroom = "";
target.u_inuse = true;
}
})(source, map, log, target);
Let me know if you are facing an issue. Would suggest to make use of JSUtil to check if value of source field is empty or not, I am saying this from my personal practical experience as sometimes "== blank' did not work for me. So I recommend using JSUtil.nil or JSUtil.notNil to check for empty or non empty values.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke