encoded query not working

El Cuchi
Tera Guru

Hi All,

 

i trust this email finds you well.

i do have a script include with a function that runs an encoded query.

it does not work as is, but if i replace "baname" (line 3) with the name of the business application in the query, rather than using the variable it works.

 

why?

 

		var baname= 'cape';
		var gr = new GlideRecord('cmdb_rel_ci');  //ref_cmdb_ci_hardware
		gr.addEncodedQuery('parent.name=cape^child.operational_status=12^child.ref_cmdb_ci_hardware.u_ci_eol_status=expired');
		gr.query();
		while(gr.next()) {
			gs.print('found another' + gr.child.name);
		}

1 ACCEPTED SOLUTION

Nick Parsons
Mega Sage

In the code you've shared you're not using baname on line 3. Please share the code that isn't working.
You'll need to ensure you concatenate your variable:

gr.addEncodedQuery('parent.name=' + baname + '^child.operational_status=12^child.ref_cmdb_ci_hardware.u_ci_eol_status=expired');

View solution in original post

2 REPLIES 2

Nick Parsons
Mega Sage

In the code you've shared you're not using baname on line 3. Please share the code that isn't working.
You'll need to ensure you concatenate your variable:

gr.addEncodedQuery('parent.name=' + baname + '^child.operational_status=12^child.ref_cmdb_ci_hardware.u_ci_eol_status=expired');

SAI VENKATESH
Tera Sage
Tera Sage

Hi @El Cuchi 

you're defining the bname  variable but you are not  actually using it in the addEncodedQuery() method.  

 

If you want to use it you need to insert dynamically into the query like below:

gr.addEncodedQuery('parent.name='+ baname +'^child.operational_status=12^child.ref_cmdb_ci_hardware.u_ci_eol_status=expired');

 

Thanks and regards

Sai venkatesh