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

chrisperry
Giga Sage

Hi there,

No need to use catalog client script or script include here. You can simply use the record producer's script field - something like this should do it:

//set record producer created incident's configuration item field to your Asset drop-down variable
current.cmdb_ci = producer.asset_variable_name.ci.toString();

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

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.

Hi Muhammad, 

yes this worked perfectly. Thank you so much 🙂

Alex

There no need to make the GlideRecord call in your script, since the variable itself is a reference to the alm_asset record you can accomplish the same with one line of code and dot-walking -- see my first answer above:

//set record producer created incident's configuration item field to your Asset drop-down variable
current.cmdb_ci = producer.asset_variable_name.ci.toString();

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry