It's all about the answers!

Ask a question

org.mozilla.javascript.EcmaError: TypeError: Cannot find function lastIndexOf

Tadeusz Janasiewicz (120149) | asked May 12 '16, 9:33 a.m.
edited May 13 '16, 3:46 p.m.
Hi, when I am opening Work Item I am getting an error:

2016-05-12 15:08:23,179 [Default Executor-thread-22758 @@ 15:08 jazzadmin < Items@c9744e2c-b848-4fc8-887f-60117b541f74> /ccm/service/] ERROR                        - Error invoking value provider 'Expected Provider' associated with the attribute 'Expected Amount Year0' in the project area with id '_Gf11gBggEea1KYcnS7uVGg'. You can link to the project area definition using a URL similar to https://thehostname:9443/jazz/process/project-areas/_Gf11gBggEea1KYcnS7uVGg, where the host name, port and jazz context are configured for your installation. Contact your project area administrator for assistance. Unexpected exception type
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$
Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot find function lastIndexOf in object 0. (expected-provider.js#106)
    at org.mozilla.javascript.ScriptRuntime.constructError(
    at org.mozilla.javascript.ScriptRuntime.constructError(

I have a Calculated Value script defined, the one mentioned in this error message (expected-provider.js#106), and attribute to which it was define should be update only if Dependent attributes were changed, what did not happened in this case.

What is even more interesting if those Dependent attributes are changed this "lastIndexOf" is working fine, see the attached screen shot:
Fuction is reached

There is also one more question about the line mentioned in the error message, 106 is empty what can we checked in the attached above screen shot.

3 answers

permanent link
Donald Nong (14.5k414) | answered May 13 '16, 1:36 a.m.
It's looks like the variable "identifier" is treated as an "object" rather than a "string" when the error is thrown. The error says "object 0". The "object" type does not have a lastIndexOf() function, hence the error. You can add a line console.log(typeof identifier) to confirm this.

If at the time when the error is thrown, the value of "identifier" is correct, you can force it into a string by padding space or a dot (.) at the beginning of the value. Without debugging, it's hard to say what the value actually is and how it causes the error.

I'm not too worried about the line number though as long as you can see which line throws the error.

permanent link
Tadeusz Janasiewicz (120149) | answered May 13 '16, 5:51 p.m.
edited May 13 '16, 7:30 p.m.
Hi Donald,

Thank you for your suggestion. You have right, this function was not recognized because the value which should be assigned were not during the Work Item opening. After I added a condition to check if those values were set correctly this issue was solved, see example below:

var deliveryDateValue    = workItem.getValue('avppipeline.workitemtype.deliveryDate');
var deliveryEndDateValue = workItem.getValue('avppipeline.workitemtype.deliveryEndDate');
var amountValue          = workItem.getValue('avppipeline.workitemtype.amount');

if( (typeof deliveryDateValue    === 'string' || deliveryDateValue    instanceof String) &&
    (typeof deliveryEndDateValue === 'string' || deliveryEndDateValue instanceof String) &&
    (typeof amountValue          === 'string' || amountValue          instanceof String)) {   

    var deliveryDate    = new Date(deliveryDateValue);
    var deliveryEndDate = new Date(deliveryEndDateValue);
    var amount          = getLastIntSegment(amountValue);

    var result = calulateAmountPerYear(n, deliveryDate, deliveryEndDate, amount);

    return result;
But when I am saving Work Item with all those value recalculated (all correctly calculated and shown) all of them are set to zero. It looks like there is something else related.

What is still wondering me is the fact why this script is executed on Work Item opening , considering the documentation Work Items attribute customization it should not:

Script-based calculated values

Note: You can find general information about script-based attribute customization in the Using scripts for attribute customization section.

If you configure a Script-based calculated value, the script will be executed in three cases:

  • When a work item is created, the script is executed
  • When a work item is saved, the script is executed to recalculate the value.
  • When an attribute which the current attribute depends on is changed, the value of the current attribute is recalculated. Depending on the presentations of the two attributes this may not work in all cases.

and also what is going on when when Work Item is saved?

I should add that brake points set in this script are not reached when Work Item is saved, or when it is reloaded, so in cases when there are some problems. In case when a Dependent attributes are changed debugging in Chrome works fine.

Donald Nong commented May 15 '16, 7:53 p.m.

When you save the work item, the script will be executed on the server, so the break points will not have any effects as they are tied to the browser. You will need to use the console.log() technique for debugging. I cannot explain how the script is executed but based on my observation, it will be executed at least twice in the browser - when the editor is loaded, and when the depending attribute is changed.

permanent link
Tadeusz Janasiewicz (120149) | answered May 25 '17, 6:13 a.m.

Hi Donald, you are right. In fact I noticed that you can debug those scripts using the RTC Eclipse Client to simulate how they are working on the server side.

To summarize:
1) those scripts are working differently in browser and on the server side: (Server-side debugging with console.log)

2) and also those scripts are run three times (even when attributes are not field in):

Case solved. Thank you.

Your answer

Register or to post your answer.