Skip to Content
0

Java Script to add special character in members conversion

Jan 23 at 03:49 PM

68

avatar image

Hi all,

Users want to add special characters to their members. For example convert 120000050130 to 1_20000.501.30 The logic is after every first digit or character, insert "_", then after the next 5 digits, insert ".", after the next 3 digits/characters, insert another "."

Regards

Jordan

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Vadim Kalinin Jan 23 at 09:32 PM
0

First you need to convert %eternal% to string:

js: %external%.toString

Then

js:

%external%.toString().slice(0,1)+"_"+%external%.toString().slice(1,6)+"."+%external%.toString().slice(7,10)+"."+%external%".toString().slice(10)

You can test it here:

http://js.do/

<script>
alert("120000050130".toString().slice(0,1)+"_"+"120000050130".toString().slice(1,6)+"."+"120000050130".toString().slice(7,10)+"."+"120000050130".toString().slice(10))
</script>
Show 5 Share
10 |10000 characters needed characters left characters exceeded

Hi Vadim,

I appreciate your help. The script is working when i test it online but on the conversion it is not writing any records. The transformation and conversion files are as below:

Whilst giving the following error;

Java scription JS: %EXTERNAL%.toString().slice(0,1)+"_"+%EXTERNAL evaluation error

Regards

Jordan

projtrans.png (9.3 kB)
projconv.png (5.4 kB)
0

May be not all members are in the format like:

120000050130

???

0

P.S. Post the log file!

0

I am restricting to only a few master records I know are in that format. The log file as below:

/CPMB/MODIFY completed in 0 seconds /CPMB/BW_IOBJ_MASTER_SOURCE completed in 0 seconds /CPMB/BW_IOBJ_TEXT_SOURCE completed in 1 seconds /CPMB/MERGE_IOBJ_MD_DATA completed in 0 seconds /CPMB/IOBJ_SOURCE_MD_CONVERT completed in 0 seconds /CPMB/SPLIT_IOBJ_MD_TXT_DATA completed in 0 seconds /CPMB/BPC_MASTER_DATA_TARGET completed in 0 seconds /CPMB/BPC_TXT_DATA_TARGET completed in 0 seconds /CPMB/CLEAR completed in 0 seconds [Selection] -------------------------------------------------------------- INFOOBJECT = 0WBS_ELEMT SELECTION = <?xml version="1.0" encoding="utf-16"?><Selections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Selection Type="Attribute"><Attribute><ID>0WBS_ELEMT</ID><Operator>1</Operator><LowValue>A304506BAHA61</LowValue><HighValue /></Attribute><Attribute><ID>0WBS_ELEMT</ID><Operator>1</Operator><LowValue>A304506BZAA03</LowValue><HighValue /></Attribute><Attribute><ID>0WBS_ELEMT</ID><Operator>1</Operator><LowValue>A304506BZAA11</LowValue><HighValue /></Attribute></Selection><Selection Type="Hierarchy" ImportText="1" /><Selection Type="Language" TextType="2"><Language>E</Language></Selection><Selection Type="AttributeList"><Attribute>0WBS_ELEMT</Attribute><Attribute>0APPR_YEAR</Attribute><Attribute>0BUS_AREA</Attribute><Attribute>0CH_ON</Attribute><Attribute>0COMP_CODE</Attribute><Attribute>0COSTCENTER</Attribute><Attribute>0CO_AREA</Attribute><Attribute>0CPR_GUID</Attribute><Attribute>0CPR_PSGUID</Attribute><Attribute>0CREATEDON</Attribute><Attribute>0CRM_MKTELM</Attribute><Attribute>0FIELDKEY</Attribute><Attribute>0IM_CORPOR</Attribute><Attribute>0IM_SIZE</Attribute><Attribute>0INV_REASON</Attribute><Attribute>0LOGSYS</Attribute><Attribute>0OBJ_CURR</Attribute><Attribute>0PLANT</Attribute><Attribute>0PRIORITY</Attribute><Attribute>0PROFIT_CTR</Attribute><Attribute>0PROG_DEF_S</Attribute><Attribute>0PROG_POS</Attribute><Attribute>0PROJECT</Attribute><Attribute>0PS_APPLNO</Attribute><Attribute>0PS_LEVEL</Attribute><Attribute>0PS_PRJTYPE</Attribute><Attribute>0PS_RESPNO</Attribute><Attribute>0PS_USR1</Attribute><Attribute>0PS_USR10</Attribute><Attribute>0PS_USR11</Attribute><Attribute>0PS_USR12</Attribute><Attribute>0PS_USR2</Attribute><Attribute>0PS_USR3</Attribute><Attribute>0PS_USR4</Attribute><Attribute>0PS_USR5</Attribute><Attribute>0PS_USR5UNT</Attribute><Attribute>0PS_USR6</Attribute><Attribute>0PS_USR6UNT</Attribute><Attribute>0PS_USR7</Attribute><Attribute>0PS_USR7CUR</Attribute><Attribute>0PS_USR8</Attribute><Attribute>0PS_USR8CUR</Attribute><Attribute>0PS_USR9</Attribute><Attribute>0PS_XSTAT</Attribute><Attribute>0REQU_CCTR</Attribute><Attribute>0RESP_CCTR</Attribute><Attribute>0SCOPE</Attribute><Attribute>0SOURSYSTEM</Attribute><Attribute>0STATUSSYS0</Attribute><Attribute>0WBS_ELM_EX</Attribute><Attribute>ZBASSQ</Attribute><Attribute>ZGENMAN</Attribute><Attribute>ZGOVPLAN</Attribute><Attribute>ZLINEMAN</Attribute><Attribute>ZMEASOBJ</Attribute><Attribute>ZNEWEXPR</Attribute><Attribute>ZPIDPREF</Attribute><Attribute>ZPROCMAN</Attribute><Attribute>ZPROJCHAM</Attribute><Attribute>ZPROVPLAN</Attribute><Attribute>ZSCOAGUID</Attribute><Attribute>ZSECTPLAN</Attribute></Selection><KeyDate>20180124</KeyDate><Relation><Value Right="Hierarchy" Left="Attribute">1</Value></Relation></Selections> WRITEMODE = 2 FORMAT = Yes TRANSFORMATION = \ROOT\WEBFOLDERS\MSUNDUZI\BUDGET\DATAMANAGER\TRANSFORMATIONFILES\PROJECT_ATTR.xls DIMNAME = PROJECT CLEAR_ALL = No [Message] -------------------------------------------------------------- Task name MASTER DATA SOURCE: Record count: 3 Task name TEXT SOURCE: Record count: 3 Task name CONVERT: No 1 Round: Java scription JS: %EXTERNAL%.toString().slice(0,1)+"_"+%EXTERNAL evaluation error Java scription JS: %EXTERNAL%.toString().slice(0,1)+"_"+%EXTERNAL evaluation error Java scription JS: %EXTERNAL%.toString().slice(0,1)+"_"+%EXTERNAL evaluation error Reject count: 3 Record count: 3 Skip count: 0 Accept count: 0 Task name MASTER DATA TARGET: Submit count: 0 Task name TXT DATA TARGET: Submit count: 0 model: BUDGET. Package status: WARNING

0

Hi Vadim,

I found the problem is to do with masking of WBS elements. Your javascript works.

Many thanks

Jordy

0
Vadim Kalinin Jan 23 at 04:15 PM
1

Sorry, but you didn't accepted my answer in previous question!

https://answers.sap.com/questions/404916/invalid-special-characters-in-transformation-and-c.html

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi Vadim,

Apologies I forgot to accept your correct answer, I have done that now. For this one, I need the script to insert characters rather than removing/replacing

Regards

Jordan

0

Any online JavaScript tutorial will help!

Or do you want me to do your job for free?

1

Uhm...I think he wants the second option, Vadim. You have been FAR more patient than I would be. haha

1
Vadim Kalinin Jan 23 at 05:24 PM
1

If you open ANY JavaScript tutorial you will find function:

substring(start [, end])

or

substr(start [, length])

or

slice(start [, end])

And you can test your code on any JavaScript test page!



Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi,

Im still a beginner to this javascript so it will take a while to understand how it works. I have tried the following but cant work:

Regards

Jordan

slice.png (4.2 kB)
0

JavaScript is a programming language (very easy, by the way). It's possible to test JavaScript code just in your browser!

0
Leila Lappin
Jan 23 at 05:09 PM
0

Hello,

Please review KBA 1448836 for permitted characters. This KBA covers valid characters for all areas of BPC, anything outside it or stated as invalid will not be supported.

Best Regards,

Leila Lappin

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Leila,

Unfortunately your answer is not related to the question!

0

Thank you Leila,

I will review the permitted characters but I need java script for inserting the permitted characters.

Regards

Jordan

0