- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2020 03:27 PM
I have an onbefore transform script running, which should not update the record if the work notes are the same. The record keeps updating the work notes even if there is no change and the Source string equals the target record string.
comments in this case are >>> "Testing 123"
here is my script
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var notes = target.work_notes.getJournalEntry(1);
var worknoteContent = notes.split("(Work notes)\n");
var lastWorknote = worknoteContent[1];
// gs.log(source.u_comments);
// gs.log(lastWorknote);
if (source.u_comments == lastWorknote) {
ignore = true;
}
// Add your code here
})(source, map, log, target);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2020 08:26 AM
IF anyone is looking to compare strings in an onBefore transform script, the geniuses at SN helped me with this
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var notes = target.work_notes.getJournalEntry(1);
var worknoteContent = notes.split("(Work notes)\n");
var lastWorknote = worknoteContent[1];
var string = lastWorknote.toString();
var string1 = source.u_comments;
//gs.log("------->>> SOURCE = " + source.u_comments + "------->>> TARGET = " + lastWorknote + "-->String" + string + "-->u_comments:" + source.u_comments.toString() + "WorknoteContent:" + worknoteContent + "-->lastworkfnote:" + lastWorknote + "Equals : " + string.indexOf(string1));
// gs.info("------->>> TARGET = " + lastWorknote);
//var string1=source.u_comments.toString();
//if (string == source.u_comments.toString()) {
if (string.indexOf(string1) >= 0) {
ignore = true;
}
// Add your code here
})(source, map, log, target);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2020 04:41 PM
You are comparing comments with worknotes. try replacing worknotes with u_comments in the if condition
if (source.u_work_notes == lastWorknote) // please replace u_work_notes with actual name of worknotes field in the staging table.
Please mark this correct & helpful if it answered your question.
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2020 04:50 PM
Hi muhammed u_comments, is a string field on my staging table, I am trying to compare the string on my staging table to the last work note on the target table. If source.u_comments = Test and the last work note on the target = Test, it should ignore insert. But this isn’t happening with my current code

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2020 05:00 PM
Ah okay. if you want to compare with only last worknotes entered. Then in the getJournalEntry() function you need to pass -1 rather than 1. 1 is for all the worknotes.
try this. i have placed some logs let me know what you get in logs.
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var notes = target.work_notes.getJournalEntry(-1);
gs.log("SH - " + source.u_comments);
gs.info("SH - " +notes);
if (source.u_comments == notes) {
ignore = true;
}
})(source, map, log, target);
Please mark this correct & helpful if it answered your question.
Thanks & Regards,
Sharjeel
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2020 07:53 AM
-1 is for all journal entry's, i got that from the docs
Script for the image above
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var notes = target.work_notes.getJournalEntry(1);
var worknoteContent = notes.split("(Work notes)\n");
var lastWorknote = worknoteContent[1];
gs.log("------->>> SOURCE = " + source.u_comments);
gs.info("------->>> TARGET = " + lastWorknote);
if (source.u_comments == lastWorknote) {
ignore = true;
}
// Add your code here
})(source, map, log, target);