Ask Your Question
1

How do I modify field values in JavaScript?

asked 2019-06-04 12:40:47 -0500

Vss@2019 gravatar image

updated 2019-06-11 16:37:50 -0500

metadaddy gravatar image

How do I send previous stage record value to next stage by using Javascript evaluator?

Input Structure looks like below

Colname
***********
$ABC+_$  ==> ROW1
%D*EF)   ==> ROW2

Output result has to be

Colname_out
****************
_ABC__$ ==> ROW1
_D_EF)  ==> ROW2
edit retag flag offensive close merge delete

Comments

1

Can you please provide more details or elaborate on your question? Maybe provide sample input and desired output?

iamontheinet gravatar imageiamontheinet ( 2019-06-04 14:08:52 -0500 )edit

Is there anyway which we can be achieved by using Javascript. Input Structure looks like below ===================== Colname *********** $ABC+_$ ==> ROW1 %D*EF) ==> ROW2 Output result has to be ================== Colname_out **************** _ABC__$ ==> ROW1 _D_EF) ==> ROW2

Vss@2019 gravatar imageVss@2019 ( 2019-06-05 12:38:50 -0500 )edit

@Vss@2019 It's better to edit your question than add more comments. I've done it for you :-)

metadaddy gravatar imagemetadaddy ( 2019-06-11 16:37:09 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-06-11 16:52:05 -0500

metadaddy gravatar image

Assuming your desired transformation is something like "replace any occurrences of $, +, % or * with _, but leave the last character intact", your JavaScript would look like:

for (var i = 0; i < records.length; i++) {
  try {
    var str = records[i].value['colname'];
    # Need to escape all the special characters with \
    records[i].value['colname_out'] = str.slice(0, -1).replace(/\$|\+|%|\*/g, '_') 
      + str.slice(-1);

    output.write(records[i]);
  } catch (e) {
    error.write(records[i], e);
  }
}

image description

edit flag offensive delete link more

Comments

If i have thousand number of characters wcich might be having italic/chinese characters how does it do

Vss@2019 gravatar imageVss@2019 ( 2019-06-12 13:35:52 -0500 )edit

@metadaddy : Will this work in Jython Evaluator. I have a header record like $abc_,def,*ghi$,jk)lmn I want output header record like _abc_,def,_ghi$,jk_lmn

Vss@2019 gravatar imageVss@2019 ( 2019-06-27 12:55:02 -0500 )edit

Yes, you can use the same technique in the Jython evaluator

metadaddy gravatar imagemetadaddy ( 2019-07-02 22:54:57 -0500 )edit

Thanks metadaddy

Vss@2019 gravatar imageVss@2019 ( 2019-07-05 01:32:53 -0500 )edit

How we replace only last delimiter character in each line using jython based on the parameter

Vss@2019 gravatar imageVss@2019 ( 2019-07-23 07:14:17 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-06-04 12:40:47 -0500

Seen: 80 times

Last updated: Jun 11