json Parsing in Script Includes

Community Alums
Not applicable

Hi Team ,

I am storing a list of comma separated values in system property in the form of Json Format as shown below :

{"ticket":{"ListCI":"a,b,c,d,e,f"}}

I need to read this values in script includes . I have used the below code for the same :

var TypeCall = Class.create();

var iLookUpArray1 = [];

TypeCall.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

  AutoTicketsCallType: function(){

  var configItem = gs.getProperty("System Property Name");

      var parser = new JSONParser();

      var parsed = parser.parse(configItem);

  var result = parsed.ticket.ListCI;

  var gr1 = new GlideRecord('incident');

  var encQy1 = 'cmdb_ci.nameIN'+result;

  gr1.addQuery(encQy1);

  gr1.query();

  while(gr1.next()){

  iLookUpArray1.push(gr1.getValue('sys_id'));

  }

  return iLookUpArray1;

  },

      type: 'TypeCall'

});

I see that comma separated values aren't read properly and I am not fetching any results . Could anyone let me know what has been missed in the above code ?

Thanks in advance .

Regards,

Ankitha

1 ACCEPTED SOLUTION

Hi Ankitha,



Yes, properties do not get called from report condition builders.



You will have to take the ci name dynamically and then give it to the query.



There are some limitation to condition builder query such as gs.log don't work, gs.addInfoMessage won't work as well as gs.properties won't work.



So you have to give them or extract them in you script.





Thank you,


Ashutosh


View solution in original post

9 REPLIES 9

So you mean that you are calling this script include in condition filter of reports?



Please show me how are you calling this.



Thank you,
Ashutosh


Community Alums
Not applicable

Hi Ashutosh ,



PFB the below query which I am running in the report



SysId   isOneOf javascript:new TypeCall().AutoTicketsCallType();



When I directly hardcode the query in the script(without usingJson Parsing ) , it is fetching the results in the report .



Query builder too doesn't seem to be a problem .



Regards,


Ashutosh


Community Alums
Not applicable

Hi Ashutosh ,




System property is not getting called and I feel this is the root cause for this . Is there any other I can call the system property apart from gs.getProperty()?



Regards,


Ankitha


HI Ankitha,



Let me try this.



Thank you,




Ashutosh


Hi Ankitha,



Yes, properties do not get called from report condition builders.



You will have to take the ci name dynamically and then give it to the query.



There are some limitation to condition builder query such as gs.log don't work, gs.addInfoMessage won't work as well as gs.properties won't work.



So you have to give them or extract them in you script.





Thank you,


Ashutosh