The CreatorCon Call for Content is officially open! Get started here.

Cannot find function base64DecodeAsBytes in scope Application Error

String
Kilo Sage

Hi Team ,

Am using below code to check the bytes length for string field ,code is working fine in global scope .But throwing below error for scoped application .

Please guide me 

 

var str = "Testing length";
var utf8Bytes = GlideStringUtil.base64DecodeAsBytes(GlideStringUtil.base64Encode(str));
gs.print(str + utf8Bytes.length);

 

Error:

Evaluator: com.glide.script.RhinoEcmaError: Cannot find function base64DecodeAsBytes in object function GlideStringUtil() {
	[native code, arity=0]
}
.
   script : Line(2) column(0)
      1: var str = "Testing length";
==>   2: var utf8Bytes = GlideStringUtil.base64DecodeAsBytes(GlideStringUtil.base64Encode(str));
      3: gs.print(str + utf8Bytes.length);

 

 

1 ACCEPTED SOLUTION

@String 

then it's not supported in scoped app.

you can create script include in your global scope and make it accessible from all scopes and then use the script

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@String 

what's your business requirement?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

We're currently examining the string fields to ensure they don't surpass 255 characters. If they do, we need to limit the user or trigger an alert. To handle this, we've implemented client-side scripting:

  1. We're converting strings to bytes and assessing the byte length.
  2. While this code functions well globally, it's encountering an error when used within the application scope.

@String 

then it's not supported in scoped app.

you can create script include in your global scope and make it accessible from all scopes and then use the script

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@String 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader