cancel
Showing results for 
Search instead for 
Did you mean: 

Conversion File JS code

Former Member
0 Kudos


Hello,

I have a senario where in I have an ID defined as (ID=0CO_AREA+*STR(_)+ID)

Transformation file for ID

ID=0CO_AREA+*STR(_)+ID

In Conversion file

NODENAME=NODENAME (Since the hierarchy already contains the Controlling area)

Now using Java script I want to split the hierarchy code with "_" between the Controlling area and ID. The ID length is not fixed.

Regards

Accepted Solutions (1)

Accepted Solutions (1)

former_member186338
Active Contributor
0 Kudos

Hi Mahesh,

The requirement is not clear: first you combine, then you want to split... how do you want to use split result?

Vadim

Former Member
0 Kudos

Hello Vadim,

Transformation file for Text and Attribute load:
For (ID=0CO_AREA+*STR(_)+ID) --> created 1130_1000142 as a member in dimension.

Now in BW in the  hierarchial view,  Node Name appears like 1130000001000142

In the Transformation file for Hierarchy:

NODENAME=NODENAME (since in the BW the node name shows the controlling area in as 1130000001000142 )

In the conversion file using a JavaScript i want to split as follows

External                            Internal

1130000001000142        1130_1000142

Is my understanding right or there is some other way to deal with this.

Regards,

former_member186338
Active Contributor
0 Kudos

If your controlling area is 4 characters long it can be done by JS. But what is the logic for zeros?

1130000001000142

Vadim

Former Member
0 Kudos

Hello Vadim,

Based on the character length the leading positions get appended with Zero. But the issue is that the character length is 7 or 8..

When I tried to test by having the logic of Controlling area + ID without "_" and selecting external Format in the data Manager package i could load both the text and hierarchy with out any issues.

Regards,

former_member186338
Active Contributor
0 Kudos

Something like:

js:%external%.toString().substring(0,4)+"_"+parseInt(%external%.toString().substring(4)).toString()

Vadim

Former Member
0 Kudos

Many Thanks.

Regards,

Former Member
0 Kudos

Hello Vadim,

I am facing some issue for Parents which have text in because of the parselnt in the js script.

So I tried to write an if-else Statement around this to handle Not a number.

js:if(isNaN(%external%)) then %external%.toString().substring(0,4)+"_"+%external%.toString().substring(4);%external%.toString().substring(0,4)+"_"+parseInt(%external%.toString().substring(4)).toString()

It gives an Evaluation error .

Regards,

former_member186338
Active Contributor
0 Kudos

Hi Mahesh,

You are using not JS syntax. Try:

isNaN(%external%)  ? %external%.toString().substring(0,4)+"_"+%external%.toString().substring(4) : %external%.toString().substring(0,4)+"_"+parseInt(%external%.toString().substring(4)).toString()

Vadim

Former Member
0 Kudos

Hello Vadim,

I tried the following apart from yours: 

*if(isNaN(%external%)) then(js:%external%.toString().substring(0,4)
+"_"+ %external%.substring(4))
else(js:%external%.toString().substring(0,4) +"_"+
parseInt(%external%.substring(4)))

But does not work. The above goes for Memory dump.

Regards,

former_member186338
Active Contributor
0 Kudos

The syntax of ternary operator for JS is:

(LogicalCondition) ? ExpressionIfTrue : ExpressionIfFalse

And this syntax will work! Your syntax will not work.

Please explain on the example what strings do you want to process!

Vadim

former_member186338
Active Contributor
0 Kudos

P.S. Just tested the following code in the online Java Script editor/debugger:

var s="111100000123456A"

alert(isNaN(s) ? s.toString().substring(0,4)+"_"+s.toString().substring(4) : s.toString().substring(0,4)+"_"+parseInt(s.toString().substring(4)).toString())

Result: 1111_00000123456A

With:

var s="111100000123456"

Result: 1111_123456

Vadim

Former Member
0 Kudos

Hello Vadim,

For Eg:

ABCD1234          ABCD_1234  

711100062456    7111_62456

Regards,


Former Member
0 Kudos

Hello Vadim,

You are right. It was my mistake.

Thanks

Regards

Answers (0)