Can scoped script includes be extended to other scoped apps?

davidarbour
Mega Contributor

Can a script include in scoped app B extend a script include in scoped app A?

10 REPLIES 10

davidarbour
Mega Contributor

Already did that as well. The error is being throw when the script include in app B is called. In other words, if I place logging code in the script include from app A, the logging is never reached. But putting a try/catch around the code in the script include in app B throws the error I mentioned above. This is why I'm asking if this is even possible. It seems there's a barrier between scoped apps that's blocking this functionality.


Can you post you script where you are calling the script include A along with the debug statements you have added?



Please mark this response as correct or helpful if it assisted you with your question.

You don't have to call toString to invoke it.   It is invoked whenever an Object is converted to a string, for printing, comparison, assignment, etc.   For example a GlideElement is an object.   The expression current.getValue('field') will likely call toString somewhere in its guts.   MDN says this:



The toString() method will throw a TypeError exception ("Function.prototype.toString called on incompatible object"), if its this value object is not a Function object. It will also throw for Proxy objects, for example.



This is a new error to me.   My guess is, you are passing a ServiceNow Glide or other object to a method that expects some other typeof ServiceNow object.   I get burned by this every once in awhile when I get confused about whether I'm holding a GlideElement or a GlideRecord in my right hand.



I'm a big fan of the script debugger these days.   Set breakpoints in your scripts by clicking to the left of a line number (a blue tag appears to indicate the breakpoint.)   Do something in your interactive context to execute the code with the breakpoint (doesn't work from scheduled jobs and workflow.)   You will be thrown into the debugger.   From there, step using F8.   If you get in the habit of breaking up expressions into a series of assignments to variables, you can view the intermediate results as you go.


davidarbour
Mega Contributor

I am using 'this' in script include B, with the assumption that script include A is being properly extended to B. So if there is a barrier between scopes, it would make sense that 'this' would not be a valid function in B because B would have no idea what A is.



I can call script include A from other apps, but I can't extend it to other apps, so I'm guessing there's something going on within the Object.extendsObject function that prevents scoped apps from extending other scoped apps.



I was hoping someone had already crossed this bridge and had a quick yes/no answer, but it seems that may not be the case. Unfortunately I can't post any of this code publicly because it's proprietary/sensitive, and I know that limits the help that you guys can provide. Sorry about that.


Ah.   I didn't think about inheritance.   I use composition and Crockford-style closures (LISP lambda expressions).   I don't reference this and the only thing I extend is AbstractAjaxProcessor.   I'm lucky, I guess.



For these kinds of problems, I create tiny "proofs" in my personal developer instance to explore what's going on.   Often those answer my question.   And if they don't, I have an unencumbered example to post...