MRVS , script include & glide ajax

omar10148
Tera Contributor

Hello everyone,
I am working on a catalog item, I have 3 variables in this catalog item which are as follows
1 - Target Workstation, it is a variable which points to the 'cmdb_software_instance' table
2- an MRVS named 'selected_software', this MRVS has 2 columns, the first named 'Software' and the second column named 'status'.

the need is as follows:
I must check the list of installed software in my variable 'target_workstation', retrieve all the selected software, then compare them with the first column of MRVS 'software', if the software exists in the installed software, the status must be displayed 'installed ' otherwise I have to display 'to_instal' .

Attached screenshots for your understanding.

here is my include script that I set up and my client script, but I have no results.

thank you for helping me dear community 

 

script include : 

 

updateStatusBasedOnInstalledSoftware: function() {
 
var posteCibleSysID = this.getParameter('sysparm_poste_cible_sys_id');
var gr = new GlideRecord('cmdb_software_instance');
gr.addQuery('installed_on', posteCibleSysID);
gr.query();
 

 
var installedSoftwareList = [];
var arr = [];
while (gr.next()) {
installedSoftwareList.push(gr.software.name);
}

 
var mrvsData = this.getParameter('sysparm_selected_software');

 
if (mrvsData) {
 
var mrvsObject = JSON.parse(mrvsData);

 
if (mrvsObject && mrvsObject.length > 0) {
 
var obj = {};
for (var i = 0; i < mrvsObject.length; i++) {
 
var softwareValue = mrvsObject[i].software;

 
if (installedSoftwareList.includes(softwareValue)) {
 
mrvsObject[i].status = 'installed';
 

} else {
 
mrvsObject[i].status = 'to_install';
 
}
}
 
return JSON.stringify(mrvsObject);
}
}

return '';
},
 
client script : 
 
function onSubmit() {
//Type appropriate comment here, and begin script below

var posteCibleSysID = g_form.getValue('poste_cible');

// Appeler la fonction du Script Include pour mettre à jour le statut
var ga = new GlideAjax('ClientSideScriptInclude');
ga.addParam('sysparm_name', 'updateStatusBasedOnInstalledSoftware');
ga.addParam('sysparm_poste_cible_sys_id', posteCibleSysID);
ga.addParam('sysparm_selected_software', g_form.getValue('selected_software'));
ga.getXMLAnswer(onSuccess);
}

function onSuccess(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
 
g_form.setValue('u_test_recup', answer);
}
1 REPLY 1

AsharRahul
Tera Contributor

try using <internal_name_of_mrvs>.variable_name for this line

ga.addParam('sysparm_selected_software', g_form.getValue('<internal_name_of_mrvs>.selected_software'));