How to get value for "Used For" field in CMDB_CI_Server--- cmdb_ci_win_server ?

Rajababu
Giga Guru

Hi ,

below simple code I created but value 

var gr = new GlideRecord ('cmdb_ci_server');

gr.addQuery('sys_id' , 's132432432423nh23h3223');

gr.Query()

if(gr.next());

//var msg = gr.getValue('used_for'); 

var msg = gr.used_for;

gs.print(" Value of choice field used_for is "+msg);

 

output :

Value of choice field used_for is null

 

anyone can help me understand why it's not getting value for purticular field when I am opening the record (cmdb_ci_server) in different table then form open record is showing - cmdb_ci_win_server ..(I am not expert in ITOM cmdb ci tables , so might be it's any relationship)

 

 

 

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi,

This is because your script has incorrect syntax. Please use the modified code below:

var gr = new GlideRecord ('cmdb_ci_server');

gr.addQuery('sys_id' , 'b0ccabf1c0a80009001f14fd151d8df0');

gr.query();

if(gr.next()){



var msg = gr.getDisplayValue('used_for');

gs.print(" Value of choice field used_for is "+msg);
}

Result:

find_real_file.png

Issue which was there sharing it as well for learning purpose to improve in future why it was not working for you:

1) gr.Query() --> Q should be in small and there should be a semicolon

2) if(gr.next()); --> There should not be a semicolon here and there should be brackets {}, within this bracket you need to write your logic to get the value.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

4 REPLIES 4

Bharath69
Tera Expert

Try below:

var gr = new GlideRecord('cmdb_ci_server');
gr.addQuery('sys_id', 's132432432423nh23h3223');
gr.query();
if(gr.next()){
var msg = gr.getDisplayValue('used_for');
}
gs.info(' value - ' +msg);

shloke04
Kilo Patron

Hi,

This is because your script has incorrect syntax. Please use the modified code below:

var gr = new GlideRecord ('cmdb_ci_server');

gr.addQuery('sys_id' , 'b0ccabf1c0a80009001f14fd151d8df0');

gr.query();

if(gr.next()){



var msg = gr.getDisplayValue('used_for');

gs.print(" Value of choice field used_for is "+msg);
}

Result:

find_real_file.png

Issue which was there sharing it as well for learning purpose to improve in future why it was not working for you:

1) gr.Query() --> Q should be in small and there should be a semicolon

2) if(gr.next()); --> There should not be a semicolon here and there should be brackets {}, within this bracket you need to write your logic to get the value.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Community Alums
Not applicable

var gr = new GlideRecord ('cmdb_ci_server');

if(gr.get('s132432432423nh23h3223'))

{

 

var msg = gr.getValue('used_for'); // you can user getDisplayValue too.

gs.print(" Value of choice field used_for is "+msg);

}

Zaib Ali
Tera Contributor
Your syntax is not valid please use below code.
 
var gr =new GlideRecord('cmdb_ci_server')
 
//replace sys_id below in line
 
gr.get('5f7dfd9cc0a8010e00ab58006f14bdc5')
 
gs.print(gr.used_for.getDisplayValue())
 
please mark this helpful if it's answer your question