- 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-04-2022 10:26 PM
Hi Manasa, Could you please try using This below code inspite of directly using the glide record in place of target
Refer the code below-
var gr = new GlideRecord('target.table_name');
gr.get(target.sys_id);
if ((source.u_assign_to == "") && (source.u_loc == "")) {
gr.setValue(assigned_to, "");
//change
for below fields also..
target.managed_by = "";
target.owned_by = "";
target.u_loc = "";
target.install_status = "6";
target.substatus = "1";
gr.update();
} else if (source.u_assign_to != "" || source.u_loc != "") {
gr.setValue(install_status, "1");
//change
for below fields also..
target.stockroom = "";
target.u_inuse = true;
gr.update();
}
If the problem persists, could you please check and share the comments from transform history.
Please mark the answer as helpful and correct if it resolves the issue.
Please mark the answer as helpful and correct.
Best Regards,
Rajat Choudhary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2022 12:58 AM
Thanks Rajat.. let me try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2022 02:05 AM
Please mark the answer as helpful and correct.
Best Regards,
Rajat Choudhary

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2022 01:07 AM
Hi,
Only issue is as below
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 != "") { //Since is a not you need an && and not an ||
target.install_status = "1";
target.stockroom = "";
target.u_inuse = true;
}