Unexpected error (1 attempt) - when executing javascript task

104 views
Skip to first unread message

Julien

unread,
Sep 1, 2015, 10:44:37 AM9/1/15
to Fujitsu RunMyProcess Developer Community
Hi,

I have a script task in my process which executes the following javascript task, that is linked as a seperate file:

var current_step = RMPApplication.getVariable('V_CurrentStep');
var work = RMPApplication.getVariable('V_ApprovalsRequired');
current_step = current_step + 1;
if (work < current_step) {
var approverArray = RMPApplication.getVariable('approvers_list');
//convert them to JSON
var jsonListApprover = JSON.parse(approverArray);
var approverName = jsonListApprover.approverName[current_step];
var approverEmail = jsonListApprover.approver[current_step];

RMPApplication.setVariable('V_ApproverName', approverName);
RMPApplication.setVariable('V_ApproverEmail', approverEmail);

RMPApplication.setVariable('V_CurrentStep', current_step);
} else {
//Approved
RMPApplication.setVariable('V_FinalApproval', 'true');
}


When the process is at task, an error is thrown: 2015-08-31T15:09:02+0000 - Task "Set next approver" (id: 5[0] - status: ACTIVE): Error while processing <@script env="javascript">
.....
setVariable('V_FinalApproval', 'true');
};</@script>
Unexpected error (1 attempt)

I don't know what I am doing wrong here and how to fix this.

I read something on this page: http://docs.runmyprocess.com/User_Guide/Development_Environment/Toolbox/Processes/Step/Task/Process_Task_Script_Tab

Your javascript file can only use process' variables defined or redefined (a=${a}) as input variable of your script task

But I don't know what this mean since there is no sample found anywhere. So I have no idea, if this is the case or not. I tried to rewrite this by using input variables, but I got the same error.

This was my new javascript code I used after I added three input variables:
current_step = ${V_CurrentStep}
work = ${V_ApprovalsRequired}
approverArray = ${approvers_list}


current_step = current_step + 1;
if (work < current_step) {
var jsonListApprover = JSON.parse(approverArray);
var approverName = jsonListApprover.approverName[current_step];
var approverEmail = jsonListApprover.approver[current_step];

setVariable('V_ApproverName', approverName);
setVariable('V_ApproverEmail', approverEmail);
setVariable('V_CurrentStep', current_step);
} else {
//Approved
setVariable('V_FinalApproval', 'true');
setVariable('V_FinalApproval', 'true');
}

Still same error, so what do I do wrong?

p.s. Someone suggested to remove the else statement, but then it would not make any sense anymore, since I am still needing the if statement.

Pankaj Kumar

unread,
Sep 2, 2015, 5:58:19 AM9/2/15
to Fujitsu RunMyProcess Developer Community, Julien
Hi Julien,

Please try to run the below code and let us know if its working or not.

Input Variable:-
current_step = ${V_CurrentStep}
work = ${V_ApprovalsRequired}
approverArray = ${approvers_list}

js code:-

current_step = current_step + 1;
if (work < current_step) {
    var jsonListApprover = JSON.parse(approverArray);
    var approverName = jsonListApprover.approverName[current_step];
    var approverEmail = jsonListApprover.approver[current_step];

    setVariable('V_ApproverName', approverName);
    setVariable('V_ApproverEmail', approverEmail);
    setVariable('V_CurrentStep', current_step);
}


alternatively You can also use the freemarker script to implement the same functionality in "Input/output" variable tab which is a better choice rather than use of script or javascript in <@script env="javascript">....</@script> tag in freemarker. Please refer to attached screen print of using the freemarker to update/create the process variables.



Thank you,
Pankaj Kumar
Fujitsu RunMyProcess Support


--
Fujitsu - RunMyProcess
---
You received this message because you are subscribed to the Google Groups "Fujitsu RunMyProcess Developer Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supportforum...@runmyprocess.com.
To post to this group, send email to suppor...@runmyprocess.com.
Visit this group at http://groups.google.com/a/runmyprocess.com/group/supportforum/.
To view this discussion on the web visit https://groups.google.com/a/runmyprocess.com/d/msgid/supportforum/cf496396-5fb8-4ba9-b06d-59392f0a01c2%40runmyprocess.com.
For more options, visit https://groups.google.com/a/runmyprocess.com/d/optout.

1959.png

wens...@gmail.com

unread,
Sep 3, 2015, 4:17:17 AM9/3/15
to Fujitsu RunMyProcess Developer Community, wens...@gmail.com
Hi,

In your code sample I am missing the

"setVariable('V_FinalApproval', 'true');"

I am needing this variable to end this process, otherwise I run into an endless loop. Setting this variable is my stopping criteria.

How can I fix this? It now seems incorrect (I did not test this btw, just following the script logic).

wens...@gmail.com

unread,
Sep 3, 2015, 4:45:16 AM9/3/15
to Fujitsu RunMyProcess Developer Community, wens...@gmail.com
I just tried your suggestion and changed the script as you suggest.

I still receive the same error:

2015-09-03T08:43:41+0000 - Task "Set next approver" (id: 5[0] - status: ACTIVE): Error while processing <@script env="javascript">current_step = current_step + 1;


if (work < current_step) {
var jsonListApprover = JSON.parse(approverArray);
var approverName = jsonListApprover.approverName[current_step];
var approverEmail = jsonListApprover.approver[current_step];

setVariable('V_ApproverName', approverName);
setVariable('V_ApproverEmail', approverEmail);
setVariable('V_CurrentStep', current_step);
}

;</@script>
Unexpected error (1 attempt)

So I have no idea what is wrong here.

Pankaj Kumar

unread,
Sep 6, 2015, 3:50:32 PM9/6/15
to Fujitsu RunMyProcess Developer Community, Julien Moorrees
Hi,

If you have removed the "else" statement from the js code, one possibility might be related to accessing the value of "approverName" and "approverEmail", please check whether "current_step" is of String or Number type? By default variables are of String type in RMP.

modify the code to:-

current_step = Number(current_step) + 1;

Thank you,
Pankaj Kumar
Fujitsu RunMyProcess Support

--
Fujitsu - RunMyProcess
---
You received this message because you are subscribed to the Google Groups "Fujitsu RunMyProcess Developer Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supportforum...@runmyprocess.com.
To post to this group, send email to suppor...@runmyprocess.com.
Visit this group at http://groups.google.com/a/runmyprocess.com/group/supportforum/.

menos...@googlemail.com

unread,
Sep 7, 2015, 5:29:16 AM9/7/15
to Fujitsu RunMyProcess Developer Community, wens...@gmail.com
Hi Pankaj

I tried the code that you suggested but its still throwing the following error:

2015-09-07T09:22:37+0000 - Task "Set next approver" (id: 5[0] - status: ACTIVE): Error while processing <@script env="javascript">current_step = Number(current_step) + 1;


if (work < current_step) {
var jsonListApprover = JSON.parse(approverArray);
var approverName = jsonListApprover.approverName[current_step];
var approverEmail = jsonListApprover.approver[current_step];

setVariable('V_ApproverName', approverName);
setVariable('V_ApproverEmail', approverEmail);
setVariable('V_CurrentStep', current_step);
}
;</@script>
Unexpected error (1 attempt)


Any suggestions where i might be going wrong?

Thanks

Menosshan

Pankaj Kumar

unread,
Sep 13, 2015, 4:01:32 PM9/13/15
to Fujitsu RunMyProcess Developer Community, Julien Moorrees
Hi Menosshan,


Are you able to resolve this error?
Please find the js script as follows, the error might be coming from the "work" variable as its was not converted to int/Number.

current_step = Number(current_step) + 1;
work = Number(work);
if (work < current_step) {
    var jsonListApprover = JSON.parse(approverArray);
    var approverName = jsonListApprover.approverName[current_step];
    var approverEmail = jsonListApprover.approver[current_step];

    setVariable('V_ApproverName', approverName);
    setVariable('V_ApproverEmail', approverEmail);
    setVariable('V_CurrentStep', current_step);
}

Thank you,
Pankaj Kumar
Fujitsu RunMyProcess Support

--
Fujitsu - RunMyProcess
---
You received this message because you are subscribed to the Google Groups "Fujitsu RunMyProcess Developer Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supportforum...@runmyprocess.com.
To post to this group, send email to suppor...@runmyprocess.com.
Visit this group at http://groups.google.com/a/runmyprocess.com/group/supportforum/.

menos...@googlemail.com

unread,
Sep 16, 2015, 5:29:06 AM9/16/15
to Fujitsu RunMyProcess Developer Community, wens...@gmail.com
i tried the code you suggested but still throwing an error which is the following:

2015-09-16T09:26:13+0000 - Task "Set next approver" (id: 5[0] - status: ACTIVE): Error while processing <@script env="javascript">current_step = Number(current_step) + 1;
work = Number(work);
if (work < current_step) {
var jsonListApprover = JSON.parse(approverArray);
var approverName = jsonListApprover.approverName[current_step];
var approverEmail = jsonListApprover.approver[current_step];


setVariable('V_ApproverName', approverName);
setVariable('V_ApproverEmail', approverEmail);
setVariable('V_CurrentStep', current_step);
}

Pankaj Kumar

unread,
Sep 16, 2015, 5:56:51 AM9/16/15
to Fujitsu RunMyProcess Developer Community, Julien Moorrees
Hi,

I tested this code in my environment and its running fine. My guess is any value is coming "Null" in the script. Please check what values you are passing in the current_step, work and approverArray array.

Thank you,
Pankaj Kumar
Fujitsu RunMyProcess Support

--
Fujitsu - RunMyProcess
---
You received this message because you are subscribed to the Google Groups "Fujitsu RunMyProcess Developer Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supportforum...@runmyprocess.com.
To post to this group, send email to suppor...@runmyprocess.com.
Visit this group at http://groups.google.com/a/runmyprocess.com/group/supportforum/.
Reply all
Reply to author
Forward
0 new messages