Solved

javascript error with substring in workflow/BPM

  • 25 October 2023
  • 4 replies
  • 99 views

Userlevel 1
Badge +4
  • Do Gooder (Customer)
  • 9 replies

Hello

i am trying to extract a part of a string in a JavaScript step in a BPM, but when i do not have any issue with IndexOf method i get the error “Unable to evaluate script while executing activity 'Activity_1uhrh20' in the process definition with id 'e8f99a83-733f-11ee-b992-76d175c7f0d6':TypeError: Selection.substring is not a function in at line number 4” like if substring was not a javascript method (actuall y i test with substr and get the same bad result)

hereunder is my code

var Selection = execution.getVariable("Selection");
var pos_start = Selection.indexOf("RAM_NO=")+7;
var pos_end = Selection.indexOf("^");
var CCN_RmaNo = Selection.substring(pos_start, pos_end);
execution.setVariable("CCN_RmaNo ", CCN_RmaNo );

everything works ok except the line

var CCN_RmaNo = Selection.substring(pos_start, pos_end);

Anyone any idea?

icon

Best answer by vito 25 October 2023, 17:44

View original

4 replies

Userlevel 1
Badge +4

ok i will answer myseelf :)

actually you can use javascript string method ...if you are using a string :)

i was trying string method on a table after figuring that out here is my new script that works

 

var SelectionTab = execution.getVariable("Selection");
var pos_start = SelectionTab[0].indexOf("RMA_NO=") + 7;
var pos_end = SelectionTab[0].indexOf("^");
var CCN_RmaNo = SelectionTab[0].substring(pos_start, pos_end);
execution.setVariable("CCN_RmaNo", CCN_RmaNo );

 

however please nopte that all javascript fucntion are case sensitive so Substring method will not works when substring yes

 

sorry for a stupid post 

Userlevel 7
Badge +21

@vito Not a stupid post at all, it learned me something.

What I don't understand is your last words '...when substring yes’. What do you mean with that?

Userlevel 1
Badge +4

hello,

what i mean is that as the javascript function name are case sensitive if you write

var CCN_RmaNo = SelectionTab[0].substring(pos_start, pos_end);

with a lowercase s at begining of substring fucntion name it will works when if you write

var CCN_RmaNo = SelectionTab[0].Substring(pos_start, pos_end);

with a Uppercase S t begining of substring fucntion name it will not works :)

best regards

Userlevel 7
Badge +21

@vito Thanks for the detailed explanation. Typically something that takes a long time to see when something is not working. 

Reply