Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to call a function declared in a Scoped Script Include?

peterraeves
Mega Guru

I have created a script include named 'iban.js'. It's API Name is 'sn_hr_sp.iban.js'. The content can be found here https://github.com/arhs/iban.js/blob/master/iban.js

Now how do I call it in another script include in the same scope?

When I add the code to the same script include, all I need to do is call IBAN.isValid(value) and it works, but what should I do when the code is in another script include? How do I call the code? 😕

4 REPLIES 4

Anurag Tripathi
Mega Patron

Hi Peter,



Script include has a field called 'Access From', you can select 'accessible form all scopes' on this and then i think ypu would be able to call it


-Anurag

I tried changing that, but that did not work. Though that should not be the issue as both script includes are in the same scope.



Edit: It did not work, because the value would not change. I cannot put the script include into 'all scopes'. Not sure why, but as I said, it should not be a problem as both are in same scope.


peterraeves
Mega Guru

Edit: The following script works when I put it in the global scope. So I guess I'm missing scope identifiers somewhere 😕



gs.include('iban.js');


gs.print(IBAN.isValid(''));



This returns 'false'.


you'll have to prefix the call with the scope name (<myscope>.IBAN.isValid()).


See also: http://wiki.servicenow.com/index.php?title=Scripting_in_Scoped_Applications#gsc.tab=0