Genesys CTI User Forum
Genesys CTI User Forum => Genesys CTI Technical Discussion => Topic started by: kamalnba on February 25, 2020, 09:53:41 PM
-
Hi,
Need help to build ECMA script for searching the string and picking up the value against Key.
Example - abc:123, xyz:345,acd:4578,acq:785.
Looking for a script which can search the above string and store the output of the key "xyz" into a variable. Any help would be appreciated.
Thanks
-
Hi,
You can convert your string into KVP list format and using built-in irdGetStringKey function. This is based on assumption that format of your string is [i]<key>:<value>,<key>:<value>[/i]
[code]
var inputStr = "abc:123, xyz:345,acd:4578,acq:785";
var kvpList = inputStr.replace(/,/g,"|");
var valueOfXyz = irdGetStringKey("xyz",kvpList);
[/code]
R.
-
[quote author=René link=topic=11548.msg52563#msg52563 date=1582709483]
Hi,
You can convert your string into KVP list format and using built-in irdGetStringKey function. This is based on assumption that format of your string is [i]<key>:<value>,<key>:<value>[/i]
[code]
var inputStr = "abc:123, xyz:345,acd:4578,acq:785";
var kvpList = inputStr.replace(/,/g,"|");
var valueOfXyz = irdGetStringKey("xyz",kvpList);
[/code]
R.
[/quote]
Thank you. I have tried amended the script to below.
var bn_key = AppState.bn_key_script
var kvpList = bn_key.replace(/,/g,"|");
AppState.Test_Name = irdGetStringKey("b.agentNme",kvpList);
In logs, I see below error.
2020-02-26 09:42:05.425 DBUG 008301E5-1000AD1B 5480 0C000000 SemanticError.cxx:22 SemanticError() Created error.semantic from element: [Script] at line number: [975] with message: [TypeError: bn_key.replace is not a function. Line 1]
2020-02-26 09:42:05.425 DBUG 008301E5-1000AD1B 5480 0C000000 ScriptError.cxx:9 Created error.semantic from element [Script] at line number [975] from script [var bn_key = AppState.bn_key_script
var kvpList = bn_key.replace(/,/g,"|");
AppState.Broker_Name = irdGetStringKey("b.agentNme",kvpList);]
P.S. [b]bn_key_script:b.statusFlg:HS,b.statusMsg:Host Successful,b.searchKey:Test,b.searchValue:1234,b.agentNme:Test1[/b]
Any Suggestions?
-
Issue is caused by the fact that bn_key is NOT a string.
Please check type of variable using [i]typeof bn_key[/i]
You can try converting the variable to string using one of suggested options below but I cannot guarantee these will work as I don't know object type.
[code]
// Option #1
var kvpList = (''+bn_key).replace(/,/g,"|");
// Option #2
var kvpList = String(bn_key).replace(/,/g,"|");
[/code]
R.