Setting the value for Location in cmdb_ci

Mrman
Tera Guru

Hi All,

Can someone please help with the below Transform script . I am trying to set the Location (location) field in cmdb_ci which is target table in Transform script.

The script is working fine when I checked in Logs , and also background script .When I checked the logs it returns the display value of name , please see below screenshot.

When I check it Location field in cmdb_ci after Transform, it is blank. not showing any value.

Transform Script:

==============

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

  var sloc = source.u_cilocation.toString();

  var loc = new GlideRecord('cmn_location');

  loc.addQuery('u_description',sloc);

  loc.query();

  gs.log("Location: "+loc.getEncodedQuery());

  if(loc.next()){

  gs.log("IF STATEMENT");

  //var dnm = loc.getDisplayValue('name');

  //target.location = loc.getDisplayValue('name');

  target.location = loc.name;

      gs.log("TagetLOC :"+target.location);

  }

})(source, map, log, target);

Log screenshot:

=============

find_real_file.png

1 ACCEPTED SOLUTION

Ramakrishna Kat
Kilo Expert

Hi Ravishankar,



Please find below code. this is help full for you.



var emp = source.u_cilocation;


  var gr = new GlideRecord("table name");


  gr.addQuery("location field name", emp);


  gr.query();


  if (gr.next()) {


  var reqRecord = current..getRefRecord();


  reqRecord.target.location = gr.sys_id;


  }


View solution in original post

16 REPLIES 16

can you please try with below code, also check if display field is set on target table,



target.setValue('location', loc.getUniqueValue());


Hi Srivastava,



This worked as expected and getting the 'name' value .



target.location = loc.sys_id;


yes, same thing. both will give the sys_id.



Please mark the answer/helpful correct if it helped to solve your purpose.


Ok Thanks, Srivastava . YOu mean target.setValue('location', loc.getUniqueValue()); will give same result as target.location = loc.sys_id; ?



Please confirm.


I was referring this: target.location = loc.getUniqueValue();



I tested earlier in background script with sample code and was able to get sys_id using above code.