Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Unable to set the value for Reference field in Target table - Transform script

Mrman
Tera Guru

Hi All,

I am working on a Transform script to populate a reference field called model_id in the Target table(cmdb_ci).I am trying to Concatenate the "Manufacturer" and "Model" from my Custom Table and querying against the "short_description" in pc_vendor_cat_item   with the Concatenated result.

As per logs I am able to see that I am getting the value , however it is not assigning to model_id in target field . It still shows as Unknown. Please see below what I found in logs and please guide.

find_real_file.png

Code:

====

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

  var mnfc = source.u_manufacturer.trim();

  var mnfcr = mnfc.replace(/,/g, "");

  var mdl = source.u_model.trim();

  //var res = mnfcr.concat(mdl);

  var res = mnfcr + " " + mdl;

  gs.log("Concatenated string : "+res);

  var type = source.u_ci_server_type;

  if(type!='Virtual'){

  var pm = new GlideRecord('pc_vendor_cat_item');

  pm.addQuery('short_description',res);

  pm.query();

  gs.log("QueryResult :"+pm.getEncodedQuery());

  if(pm.next()){

  gs.log("into secondif"); ---- I am getting in here and able to see this logs.

  var mdel = pm.getValue('short_description');

  gs.log("ModelValue: "+mdel); ---- I am able to see this logs and coming correctly as ModelValue: HP ProLiant DL380 G7

  target.model_id = mdel;

  gs.log("Target :"+target.model_id); --- I am able to see the value correctly here also in logs as Target :HP ProLiant DL380 G7

      }

1 ACCEPTED SOLUTION

Gurpreet07
Mega Sage
7 REPLIES 7

Hi Michael,



This did not work, I tried this.


Check if this helps. What Michael told should work, otherwise try with this one also and again check what is the display value set for you model_id's table.



target.setDisplayValue('model_id', mdel);


Gurpreet07
Mega Sage

Hi Ravi,



Is it working now?