1

I have the following code within a JavaScript dynamic action in Oracle APEX v4.2 to work with JSON, i.e.:

var graph_data = $v('P780_GRAPH_DATA');
var rule_data = $v('P780_RULE_DATA');

var unique = function(origArr) {
  var newArr = [],
      origLen = origArr.length,
      found, x, y;

  for (x = 0; x < origLen; x++) {
    found = undefined;
    for (y = 0; y < newArr.length; y++) {
      if (origArr[x] === newArr[y]) {
        found = true;
        break;
      }
    }
    if (!found) {
      newArr.push(origArr[x]);
    }
  }
  return newArr;
}

    var accessLines = graph_data.filter(function (line) {
      return !isTrunkLine(line);
    });
    var trunkLines = graph_data.filter(isTrunkLine);

    accessLines.forEach(drawLine);
    trunkLines.forEach(drawLine);


    function isTrunkLine(intf_type) {
      var purpose = intf_type.purpose;

      return purpose === 'TRUNK';
    }

When working with this outside of Oracle APEX but just in a separate HTML file that contains the javascript code, all works fine but now having to move this into Oracle APEX, I am getting the following error:

Uncaught TypeError: graph_data.filter is not a function

Unsure what I am doing wrong but I basically have a valid JSON object within graph_data as I have run it through JSONLint but not sure what the issue is here.

13
  • 1
    What does $v('P780_GRAPH_DATA') return? It should be an array. Commented Jun 1, 2016 at 8:51
  • @Tom I actually construct my own JSON via a select statement where I enclose this inside the square "[" and "]" brackets so looks like it's a string. Basically a function call that returns a VARCHAR2. How can I convert to an array pls? Commented Jun 1, 2016 at 8:58
  • How do you get this string? Through an ajax call? Commented Jun 1, 2016 at 9:01
  • Using a function call that returns a string in this format: select '{' || ' "id" : "'|| id || '"' || ',"node" : "' || node || '"' || ',"node_name" : "' || node_name || '"' etc Commented Jun 1, 2016 at 9:08
  • Sorry, I probably wasn't clear enough. You're constructing this string in sql, but somehow are passing it along to Javascript. For example, so you have an Ajax call prior to this code which communicates with an on-demand process which returns this through htp.p? Or are you using some other means of passing this data along. It might help in determining the most efficient solution. If it's in code prior, could you add it? Commented Jun 1, 2016 at 9:11

1 Answer 1

2

In the end with Tom's assistance, I simply forgot to parse my JSON object and also hit a limitation within Oracle APEX v4.2 of 4000 characters for a DA.

Please see: http://www.explorer-development.uk.com/avoiding-dynamic-action-plsql-length-limit/

I had to rearrange my JavaScript code, which was a nuisance. It's all fine now.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.