- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2017 08:06 PM
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.
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
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2017 08:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2017 08:23 PM
Here you need to use
target.model_id.setDisplayValue(mdel);
Refer below link
http://wiki.servicenow.com/index.php?title=Inserting/Updating_GlideRecord_with_References#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2017 08:35 PM
Hi Gurpreet,
This did not work.Please guide.
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(mdl!=''){
if(type!='Virtual'){
//gs.log("into if");
var pm = new GlideRecord('pc_vendor_cat_item');
//pm.addQuery('model.display_name',res);
pm.addQuery('short_description',res);
pm.query();
gs.log("QueryResult :"+pm.getEncodedQuery());
if(pm.next()){
gs.log("into secondif");
var mdel = pm.getValue('short_description');
gs.log("ModelValue: "+mdel);
target.model_id.setDisplayValue(mdel);
//gs.log("Target :"+target.model_id);
//}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2017 08:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2017 08:33 PM
Hi Ravi,
I believe you want to set "target.model_id" to the sys_id of the pc_vendor_cat_item record, like below:
target.model_id = pm.sys_id;
Hope this helps!