cancel
Showing results for 
Search instead for 
Did you mean: 

Java Script to add special character in members conversion

former_member246680
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member186338
Active Contributor
0 Kudos

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>
former_member246680
Participant
0 Kudos

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

former_member186338
Active Contributor
0 Kudos

May be not all members are in the format like:

120000050130

???

former_member186338
Active Contributor
0 Kudos

P.S. Post the log file!

former_member246680
Participant
0 Kudos

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

former_member246680
Participant
0 Kudos

Hi Vadim,

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

Many thanks

Jordy

Answers (3)

Answers (3)

former_member186338
Active Contributor

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!



former_member246680
Participant
0 Kudos

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

former_member186338
Active Contributor
0 Kudos

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

former_member186338
Active Contributor

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

former_member246680
Participant
0 Kudos

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

former_member186338
Active Contributor

Any online JavaScript tutorial will help!

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

ChrisSolomon
Active Contributor

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

damovand
Product and Topic Expert
Product and Topic Expert
0 Kudos

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

former_member186338
Active Contributor
0 Kudos

Hi Leila,

Unfortunately your answer is not related to the question!

former_member246680
Participant
0 Kudos

Thank you Leila,

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

Regards

Jordan