Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can't send array from CEP panel to JSX

Community Beginner ,
Apr 05, 2023 Apr 05, 2023

I am not abel to send a array between JS and JSX in my CEP panel using JSON.stringify. The JSX function doeasnt get called at all. The alert below doesn't come through.

 

If i don't use JSON.stringify the array gets send not as an array but just comma seperated vaules. The array structure is lost.

 

My JS function

 

function generateList() {
  var ruleData = [["filename","doesntcontain","kkk"], ["clipname","doesntcontain","kkk"]]
  var andor = "and";
  if (document.getElementById("andor-select2").checked) {
    andor = "or"
  }
  
  if (ruleData === "Error") {
    return;
  }
  var ruleDataStr = JSON.stringify(ruleData)
  console.log(ruleDataStr)
  var csInterface = new CSInterface();
  csInterface.evalScript('searchTimeline("' + ruleDataStr + '", "' + andor + '")')
}

 My JSX function

function searchTimeline (ruleData, andor) {
    alert("here")}

 

 

Any suggestions?

TOPICS
Error or problem , SDK
507
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Adobe Employee , Apr 05, 2023 Apr 05, 2023

At first glance, I suspect the double-then-single quotes before and after 'ruleDataStr', and 'andor'.

It's not JSON-related, but have a look at this JavaScript function in PProPanel; it builds up a complicated evalScript() command. 

Translate
Community Beginner , Apr 05, 2023 Apr 05, 2023

Youre right, the double quotes were the issue! I escaped the quotes in the string and now its working.

 

  var ruleDataStr = JSON.stringify(ruleData)
  var ruleDataEscaped = ruleDataStr.replace(/"/g, '\\"'); // Escape double quotes
Translate
Adobe Employee ,
Apr 05, 2023 Apr 05, 2023

At first glance, I suspect the double-then-single quotes before and after 'ruleDataStr', and 'andor'.

It's not JSON-related, but have a look at this JavaScript function in PProPanel; it builds up a complicated evalScript() command. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 05, 2023 Apr 05, 2023
LATEST

Youre right, the double quotes were the issue! I escaped the quotes in the string and now its working.

 

  var ruleDataStr = JSON.stringify(ruleData)
  var ruleDataEscaped = ruleDataStr.replace(/"/g, '\\"'); // Escape double quotes
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines