Onbefore Transform script not working - record still updating

DanielCordick
Mega Patron
Mega Patron

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);

1 ACCEPTED SOLUTION

DanielCordick
Mega Patron
Mega Patron

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);

 

View solution in original post

7 REPLIES 7

You are right. try this, this script should work for you.

(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.toString() == lastWorknote.toString()) {

    ignore = true;
  } 

}

 

Regards,
Muhammad

This did Not work either, record still updated again with the same comment

DanielCordick
Mega Patron
Mega Patron

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);