Dynamic filter using script include as reference

tiagomacul
Giga Sage

I'm trying to create a Dynamic filter using script include or also Business Rules, how ever, I've been trying and when i tried to recognize how to do:

  1. Script include / Application: Global / Accessible from: All application scopes
  2. Dynamic Filter / script: javascript: new <includename>.<function name>(); / Reference Script: Script Include: <includename>

Script Include

find_real_file.png

var appLogin = Class.create();

appLogin.prototype = Object.extendsObject(AbstractAjaxProcessor, {

filterMe: function(){

var vuserid = gs.getUserID();

vReturn = "";

      vIsTrue = this.isTrue();

if (vIsTrue== false)

{

vReturn = vuserid;}

else

{

vReturn = this.GetMyBoss();

}

return vReturn;

},

isTrue: function(){

var vuserid = gs.getUserID();

var ObjUser = new GlideRecord('sys_user');

ObjUser.get(vuserid);

var vistrue= ObjUser.u_istrue;

return vistrue;

},

GetMyBoss: function(){

var vuserid = gs.getUserID();

var ObjUser = new GlideRecord('sys_user');

ObjUser.get(vuserid);

var vmyboss= ObjUser.u_myboss;

return vmyboss;

},

type: 'appLogin'

});

Dynamic FIlter Options

find_real_file.png

  • new x_appLogin().filterMe()
    • org.mozilla.javascript.EcmaError: "x_appLogin" is not defined.     Caused by error in <refname> at line 1==>     1: javascript: new x_appLogin().filterMe();
  • new x_appLogin.filterMe();
    • org.mozilla.javascript.EcmaError: "x_appLogin" is not defined.     Caused by error in Phase 2 Jelly: file:/glide/nodes/xxxxxxxxxxxxxxxx004_16033/webapps/glide/itil/WEB-INF/ui.jtemplates/doctype/template_bar.xml.2 at line 1==>     1: new x_appLogin().filterMe();
  • new appLogin.filterMe();
    • org.mozilla.javascript.EcmaError: undefined is not a function. Caused by error in <refname> at line 1 ==> 1: javascript: new appLogin.filterMe();
  • gs.include('appLogin'); filterMe();           OR         javascript:gs.include('appLogin'); filterMe();
    • org.mozilla.javascript.EcmaError: "filterMe" is not defined.     Caused by error in Phase 2 Jelly: file:/glide/nodes//4_16033/webapps/glide/itil/WEB-INF/ui.jtemplates/doctype/template_bar.xml.2 at line 1==>     1: gs.include('appLogin'); filterMe();
  • applogin.filterMe();
    • org.mozilla.javascript.EcmaError: "applogin" is not defined.     Caused by error in <refname> at line 1==>     1: applogin.filterMe();
  • javascript:applogin.filterMe();
    • org.mozilla.javascript.EcmaError: "applogin" is not defined.     Caused by error in Phase 2 Jelly: file:/glide/nodes16033/webapps/glide/itil/WEB-INF/ui.jtemplates/doctype/template_bar.xml.2 at line 1==>     1: javascript:applogin.filterMe();

BUT

Anything happens on my filter,

What am i making for isn't work?

1 ACCEPTED SOLUTION

Can you just try without javascript in your dynamic filter's script field (in your screen shot you are using javascript keyword), like,



new appLogin().filterMe();



OR



gs.include('appLogin');new appLogin().filterMe();


View solution in original post

16 REPLIES 16

Hey Tiago,



Can you add logs in the first line of filterme function to see if the control is reaching there or not?


-Anurag

Hi anurag ,



I did it, i clean my code to publish.


Isn't reaching there.



  • new x_appLogin().filterMe()
    • org.mozilla.javascript.EcmaError: "x_appLogin" is not defined.     Caused by error in <refname> at line 1==>     1: javascript: new x_appLogin().filterMe();
  • new appLogin.filterMe();
    • org.mozilla.javascript.EcmaError: undefined is not a function. Caused by error in <refname> at line 1 ==> 1: javascript: new appLogin.filterMe();
  • gs.include('appLogin'); filterMe();           OR         javascript:gs.include('appLogin'); filterMe();
    • org.mozilla.javascript.EcmaError: "filterMe" is not defined.     Caused by error in Phase 2 Jelly: file:/glide/nodes/XXXXXXXXXXXXXX004_16033/webapps/glide/itil/WEB-INF/ui.jtemplates/doctype/template_bar.xml.2 at line 1==>     1: gs.include('appLogin'); filterMe();
  • applogin.filterMe();
    • org.mozilla.javascript.EcmaError: "applogin" is not defined.     Caused by error in <refname> at line 1==>     1: applogin.filterMe();
  • javascript:applogin.filterMe();
    • org.mozilla.javascript.EcmaError: "applogin" is not defined.     Caused by error in Phase 2 Jelly: file:/glide/nodes/XXXXXXXXXXXXXXXXXXX004_16033/webapps/glide/itil/WEB-INF/ui.jtemplates/doctype/template_bar.xml.2 at line 1==>     1: javascript:applogin.filterMe();




Thank You


Can you please add var for below variables in your code and see if that helps.



var vReturn = "";  


var vIsTrue = this.isTrue(vuserid);


Can you just try without javascript in your dynamic filter's script field (in your screen shot you are using javascript keyword), like,



new appLogin().filterMe();



OR



gs.include('appLogin');new appLogin().filterMe();


Hi Tiago,


Please ensure client callable check box is True.



On 22-Jan-2018 5:41 AM, "explorenow" <community-no-reply@servicenow.com>