Genesys CTI User Forum

Genesys CTI User Forum => Genesys CTI Technical Discussion => Topic started by: marmota on November 11, 2020, 08:12:39 PM

Title: Get JS function result at IRD
Post by: marmota on November 11, 2020, 08:12:39 PM
Hi all!

Could you advise how to get value returned by JS macros at IRD?

There is a simple JS macros:
[code]
var res;
if (textVar.length > 2) {
  res = 'MORE than 2';
} else {
  res = 'LESS than 2';
}
ReturnEx(GetLastError(), res);
[/code]

There is a topic that describes how to add JS at IRD: http://www.sggu.com/smf/index.php?topic=6910.0

And a bit of info from documentation: https://docs.genesys.com/Documentation/R/latest/Ref/FunctionsUpdate
(see Support for Javascript section)

It says I need to use combination of ReturnEx(error, data) and data=ReturnData[]functions.
But it's not really clear what to do next =) How can I call retuned value (res) from macros inside of the strategy?
Title: Re: Get JS function result at IRD
Post by: gen_rtfm on November 11, 2020, 08:19:14 PM
Isn't the ReturnData[] supposed to be in an assign or function block directly following the macro-block?

The ReturnEx() statement within the js macro sets the value that will be available by calling  ReturnData[] in the strategy.

Give it a shot, let me know.

Br

Skickat från min Mi MIX 3 5G via Tapatalk

Title: Re: Get JS function result at IRD
Post by: marmota on November 11, 2020, 08:50:40 PM
I tried it but no idea how it works =)

I put a block with anotherVar=ReturnData[] after macros but it terminates with Competion code: Session terminated.

Strange but ReturnData[] doesn't accept any parameter (I tried to put variable name from macros [res] there but verification fails then) - only empty parameter works. I have no idea how then strategy understands which of parameters to retusn (the last one?) - anyway it doesn't wort with empty either.

Additrionally I tried to do same though Script - so I created a testScript, verifies it succesfully but when trying to run it at a RP it says testScript.rbn is not accessible.
Title: Re: Get JS function result at IRD
Post by: gen_rtfm on November 11, 2020, 08:58:20 PM
I can check and give an example tomorrow if nobody beats me to it - nighttime where I live ;)

Skickat från min Mi MIX 3 5G via Tapatalk

Title: Re: Get JS function result at IRD
Post by: terry on November 12, 2020, 06:31:41 AM
Do you actually make URS run those macros/strategies by placing a call or you are using IRD debug functionality to run strategy?
Title: Re: Get JS function result at IRD
Post by: marmota on November 12, 2020, 09:47:31 AM
[quote author=terry link=topic=11892.msg53532#msg53532 date=1605162701]
Do you actually make URS run those macros/strategies by placing a call or you are using IRD debug functionality to run strategy?
[/quote]

Hi! Debug yet.
Title: Re: Get JS function result at IRD
Post by: gen_rtfm on November 12, 2020, 11:56:24 AM
Hi,

I checked and in the assign/function block after a macro-block I've used ReturnData without [] to fetch the value from the macro.

This is in production, so that method works ;)

Br

Skickat från min Mi MIX 3 5G via Tapatalk

Title: Re: Get JS function result at IRD
Post by: marmota on November 12, 2020, 03:04:33 PM
[quote author=gen_rtfm link=topic=11892.msg53535#msg53535 date=1605182184]
Hi,

I checked and in the assign/function block after a macro-block I've used ReturnData without [] to fetch the value from the macro.

This is in production, so that method works ;)

Br

Skickat från min Mi MIX 3 5G via Tapatalk


[/quote]

Mmmm. Can you go thru my steps? Do they look similar to what you did?

1. IRD -> Routing Desgin -> Macros -> New

2. Fill in:
[list]
[li]Name (testMacro)[/li]
[li]Parameters (textVar)[/li]
[li]Definition[/li]
[/list][code]
var res;
if (textVar.length > 2) {
  res = 'MORE than 2';
} else {
  res = 'LESS than 2';
}
ReturnEx(GetLastError(), res);[/code][list]
[li]checkbox Complex macro[/li]
[/list]
Verify -> OK

3. Routing Design -> Strategies -> New (testMacroStrategy)

4. Variables: testVar1 STRING LOCAL

5. Entry block -> Macro block -> Function block -> Exit block

Macro block:
choose test Macro from the list of available macros, Parameter textVar = 'dsdsd', Verify (ok)

Function block:
textVar1 = ReturnData[], Verify (OK)

6. Set testMacroStrategy to RP, Debug -> it Runs until Macro block gives error: Session terminated =(

Title: Re: Get JS function result at IRD
Post by: gen_rtfm on November 12, 2020, 03:32:59 PM
Hi,

Update:
Function block:
textVar1 = ReturnData[]

To Function block:
Textvar1 = ReturnData

And see if that helps - this is my point in the earlier post - omit the brackets when you "fetch" the returned data - use it as if it were another variable.

Skickat från min Mi MIX 3 5G via Tapatalk

Title: Re: Get JS function result at IRD
Post by: marmota on November 12, 2020, 04:59:30 PM
Unfortrunately same (

It breaks before ReturnData - doesn't go further macros block...
Title: Re: Get JS function result at IRD
Post by: marmota on November 12, 2020, 05:04:44 PM
It's working now. The problem was that I was debugging with stepInto tool not stepOver [facepalm] =)
Title: Re: Get JS function result at IRD
Post by: gen_rtfm on November 12, 2020, 05:41:58 PM
Haha, glad to hear it!

Love it when I get that kind of realization myself, relatable!

Skickat från min Mi MIX 3 5G via Tapatalk

Title: Re: Get JS function result at IRD
Post by: marmota on November 12, 2020, 06:33:23 PM
Curious if it is possible to pass several values from macros to strategy...

My task is to parse Unix timestamp (transferred by REST API) and get day, month and year as integer numbers. It seems that I need to make separate macros for each of them.
Title: Re: Get JS function result at IRD
Post by: gen_rtfm on November 12, 2020, 06:44:50 PM
Have the return type be something that can be parsed as string(list) maybe?

Skickat från min Mi MIX 3 5G via Tapatalk

Title: Re: Get JS function result at IRD
Post by: terry on November 12, 2020, 08:37:40 PM
Basically IRD debugging doesn't work with JS macros - it can debug only native IRD strategies.
If strategy using Macros with JS - it probably will work only if not making "step into" - use step over to not go inside macro.
I tried and it worked for me :
Invoked from strategy macro var temp_array = a.split('|'); ReturnEx(0, temp_array);
and following it with data=ReturnData[] - get in data serialized as string array.

Also might work: create in strategy some INTERACTION scope STRING variable like abc
In macro put some value as property of call object in following way: GetCallObject().data.abc='something'.
Property abc of data of call object will be shared with INTERACTION variable abc (assuming type of variable (STRING) is the same as type of value you put in property abc). After macro execution you can just access this variable and get from there value you put in inside macro.





Title: Re: Get JS function result at IRD
Post by: marmota on November 12, 2020, 09:08:28 PM
Yep, array works! Thanks all for engagement!