How to inject the value of a variable into a JS parameter?

335 views
Skip to first unread message

J.M.

unread,
Mar 6, 2015, 6:43:26 AM3/6/15
to suppor...@runmyprocess.com
Hi,

I'm trying to make a process that is able to add a new event to the calendar, asking if the new event is at the same hour that another.


For this purposse I've thought a proccess that:
1.- Login Calendar API.
2.- Get events from a calendar
3.- Execute a function that check if the new event (whose data have been introduced on the launch by the user), is at the same time that another.
3.a.- If there is no coincidence add event.
3.b.- if there is coincidence, show a form to the user, in order to correct de datetime info, and go to step 3.

My problem comes running the javascript function. I'm getting the following error:

2015-03-06T11:15:03+0000 - Task "Look for coincidence" (id: 4[0] - status: ABORTED): Error while processing <@script env="javascript">

function coincidence(items,start) {
var found = false;
var i=0;
var newDateTime = start.split("T");
var newDate = newDateTime[0];
var newTime = newDateTime[1];
while ((!found) && (items.length > 0) && (i < items.length)){
var currentDateTime = items[i].start.datetime.split("T");
var currentEventDate = currentDateTime[0];
var currentEventTime = currentDateTime[1];
var currentDateTimeEnd = items[i].end.datetime.split("T");
var currentEventDateEnd = currentDateTimeEnd[0];
var currentEventTimeEnd = currentDateTimeEnd[1];
if (currentEventDate == newDate ){
if ((newTime > currentEventTime) && (newTime < currentEventTimeEnd))
found = true;
}
i++;
}
return found;
}

var tmp = coincidence(items, start);
print(tmp);
setVariable("coincidence",tmp);


</@script>
Invalid javascript.: TypeError: Cannot call method "split" of undefined (<
function ...>#9)

I understand that the value of the variable called items isn't correct, but why?

I need some help, please.

Regards
input_lookForCoincidence.png
new event checking.png
output_lookForCoincidence.png
process.png

J.M.

unread,
Mar 9, 2015, 3:57:18 AM3/9/15
to suppor...@runmyprocess.com, javiermm...@gmail.com
Hi,

I forgot to ask, how to do the opposite operation too. That is, once I have achieved to introduce a variable from RMP to JS, I'll need to extract the value of a JS variable to a RMP variable.

Please, I need help with that problem.
Besides, I make an UP to the post.

Thanks and regards,

Pray Desai

unread,
Mar 12, 2015, 3:36:25 PM3/12/15
to suppor...@runmyprocess.com, javiermm...@gmail.com

Hello JM,

Regarding injecting a process variable into JS, you can directly pass the variable in the function call parameters. 

Regarding extracting the value of a JS variable to a RMP variable, it is done by 

setVariable("process_variable_name",js_function_result);



Regarding your application specific issue, i see you have correctly injected and extracted variables from JS so you need to debug yourself inside your function like just have 
print(input);
print(start);

inside your script to see whether these variables have correct values or not  and then write your actual function.

One thing I noticed from your input screenshot is that you have ${P_result.items} in Input variables which should have been an Output variable of a previous connector task that returned items.


Regards,
Pray Desai,
Fujitsu RunMyProcess.


javiermm...@gmail.com

unread,
Mar 13, 2015, 7:59:27 AM3/13/15
to suppor...@runmyprocess.com, javiermm...@gmail.com
Thanks Pray.

It works. I make a silly mistake.

Regards.
Reply all
Reply to author
Forward
0 new messages