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

Jeff316
Kilo Guru

I tried this catalog client script to just pull one record and set the u_size fromthe table, but not working. I don't get any errors but setValue is not executing even for the hard coded values.

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var recomDrive = new GlideRecord('u_fnf_azure_request_form_recommend_drive');
recomDrive.addQuery('u_drive_letter_id', 25);
recomDrive.query();
while(recomDrive.next()){

var driveSize = recomDrive.u_size;
var OSdrive = [
{
drive_letter_os: "CC",
drive_size_os: driveSize,
unit_os: "GBs",
disk_tier_os: "Premium_LRS",
sizeingbs_os: "333"
}
];

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

Cody Smith _ Cl
Tera Guru

You will need to make new On Change scripts that look for the "Recommended Drivers" field to change. From that script you will populate the appropriate fields with that data. 

So it will look something like this..

function onChange(control, oldValue, newValue, isLoading) {
    var reference = g_form.getReference('your_reference_field', doAlert);
    // doAlert is our callback function
}


function doAlert(reference) { 
   //reference is passed into callback as first arguments
   g_form.setValue('letter',reference.letter);
   g_form.setValue('size',reference.size);
   g_form.setValue('whatever_you_want',reference.whatever);
}

Thanks but the onchange is on the OS variable field of the catalog request form.

If I pick OS = Windows in the OS field, then I need to lookup the records from "recommended drives"table to get each row for that OS. Each row will have drive_letter,drive_size,unit,disk_tier, sizeingbs.

Below is my catalog client script that correctly inserts hard-coded values into the mrvs perfectly, but I need this to be dynamic and lookup these 5 values from the "recommended drives" table instead of using "hard coded" values below. 

Shouldn't i be able to add the lookup to this existing catalog client script?

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));
}

 

nothing I do will set the variable UNIT from the query results. If I say var UNIT = "TESTING" then it works and the setValue enters "TESTING" as the unit_os for the mrvs.

function onChange(control, oldValue, newValue, isLoading) {

var REC = new GlideRecord('u_fnf_azure_request_form_recommend_drive');
REC.addQuery('u_description','x');
REC.query();
//if (REC.next() ) {
var UNIT = REC.u_size_unit;
var OSdrive = [
{
drive_letter_os: "CC",
drive_size_os: "test",
unit_os: UNIT,
disk_tier_os: "Premium_LRS",
sizeingbs_os: "333"
}

];

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