Record producer - how to get the configuration item from the alm_asset record that has been assigned to the user.

Alex319
Giga Guru

Hi All, 

I have created a record producer which currently returns assets assigned to the current user. (see below)

find_real_file.png

What I am trying to do is pull the associated configuration item off the record that exists for those assets. for example the P1000104 - Apple iMac 27" has an associated CI: Apple iMac 27" - CI

find_real_file.png

The purpose is so that the CI is automatically populated on the incident record which is created when the record producer is submitted. 

find_real_file.png

I have tried doing this from the scripting area on the record producer and had no joy. 
I have started trying to create a client script and script include but I haven't been able to get it working. please see the below code:

Catalog client script:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var citem = new GlideAjax('assetci'); //Name of the Script Include
citem.addParam('sysparm_name', 'getci'); //name of function in script include
citem.addParam('sysparm_conf', g_form.getValue('what_do_you_have_an_issue_with'));
//alert(g_form.getUniqueValue('what_do_you_have_an_issue_with'));
citem.getXML(confCallback);


function confCallback(response) {
var coni = response.responseXML.documentElement.getAttribute("answer");
alert(coni);
g_form.setValue('coni');
}}

Script include:

try {
var assetci = Class.create();
assetci.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getci: function() {
gs.error('getci has been called');
var conf = this.getParameter('sysparm_conf');
var confGR = new GlideRecord('alm_asset');
confGR.addQuery('ci', conf);
confGR.query();
gs.error(conf);
if (confGR.next()) {
gs.error(confGR.ci.getDisplayValue());
return confGR.ci.getDisplayValue();

}
},

type: 'assetci'
});
} catch (err) {
gs.error('[' + gs.getCurrentScopeName() + ']' + ': assetci: get config item - Caught error: ' + err);
}

The gs.error is returning undefined in the script include. 

Any help would be amazing

Thanks

Alex 

1 ACCEPTED SOLUTION

Muhammad Khan
Mega Sage
Mega Sage

Hi Alex,

 

Use the following script in the script field of record producer;

var gr = new GlideRecord('alm_asset');
if(gr.get(producer.what_do_you_have_an_issue_with)) //I am assuming that 'producer.what_do_you_have_an_issue_with' will return sys_id of record in alm_asset.
	current.cmdb_ci = gr.getValue('ci'); // Populating cmdb_ci field of the incident table with ci field of alm_asset table.

 

Hopefully this will work for you as it is working on my PDI.

View solution in original post

5 REPLIES 5

Sadik Palsania
Tera Contributor

Hello @Alex319 

Can you please share how did you pull CMDB's list in catalog form?