The CreatorCon Call for Content is officially open! Get started here.

Catalog client script to do a table lookup then insert the results in a multi-row variable set on the intake form.

Jeff316
Kilo Guru

Back to the well again. I'm liking the new multi-row variable sets. I have a catalog item to request new servers. Originally, the requester said, if the user picks Windows then automatically populate the "drives" mrvs with a C drive and some values. They can add others to the mrvs but we need this required drive to automatically be there and if they pick Linux as the OS then automatically add "/", the size, the tier into the mrvs. I have the script that assumes I will hardcode either C or /.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var OSdrive = [
{
drive_letter_os: "CC",
drive_size_os: "test",
unit_os: "GBs",
disk_tier_os: "Premium_LRS",
sizeingbs_os: "333"
}
];
g_form.setValue('INTERNAL_NAME_OF_MRVS', JSON.stringify(OSdrive));
}
But now they added a custom table called "recommended drives" where they will dynamically store the C drive and / drive attributes as well as others. So now when the user selects the OS of Windows or Linux on the catalog item I can't just use my cat script and populate the mrvs, I have to lookup which drive or drives to insert into the mrvs based on what is in the Recommended Drive table. So today when I select the OS of Windows there might be Drives C and F with drive_letter, drive_size, unit, dis_ticket, sizeinbgs, I then need to insert those 2 rows into the mrvs on the intake form.

21 REPLIES 21

Thanks.

I think I'll have to abort now and come up with a workaround. Almost out of time.

I'll give myself till high noon here to morph these baby scripts to populate a MRVS.

 

I'm very close. My scripts can pull back an entire row from the table in the script include and inserts them into the MRVS. YAY!!! But I need to loop through the table to get all rows and insert each into the MRVS.

SI:

var getRecDrive = Class.create();
getRecDrive.prototype = Object.extendsObject(AbstractAjaxProcessor, {
driveDetails: function(){
var retVal; // Return value
var Dreq = this.getParameter('sysparm_id');
var gr = new GlideRecord('u_fnf_azure_request_form_recommend_drive');
//gr.addQuery('u_description"',Dreq);
gr.query();
if(gr.next())
{
retVal = gr.u_size_unit+','+gr.u_key;
}
return retVal;
},
type: 'getRecDrive'
});

 

 CS:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var name = g_form.getValue('name');
var ga = new GlideAjax('getRecDrive');//name of script include
ga.addParam('sysparm_name', 'driveDetails');//name of function on script include
ga.addParam('sysparm_id', "x");//name of field on form triggering call
ga.getXML(getRecDriveLookup);

}

function getRecDriveLookup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var answers = answer.split(',');
alert(answers);

var OSdrive = [
{
drive_letter_os:answers[1],
drive_size_os: "test",
unit_os: answers[0],
disk_tier_os: "Premium_LRS",
sizeingbs_os: "333"
}
];

g_form.setValue('os_drive', JSON.stringify(OSdrive));

}

I quit. So close. Moving on. 

I think I need to change my script include to return the entire results of the query (for as many rows that match) into an array holding all rows and all fields, then pull that array into the client script who will parse all the fields from all the rows? 

That should work