Gel function not working - is there a way to populate the righthand list collector from db values on a Service Portal catalog item

J Shone
Kilo Expert

I found some code on the community and guru to populate the righthand side of a list collector object in a catalog item.

All the code is working fine until the gel() function call.

Error (in chrome developer) states 

com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=fbe82ecbdb821810d6ce3313f396193f:1482 Uncaught TypeError: gel is not a function

Has gel() been deprecated and is there any alternative function I can use?

Requirement:

On a Companies Catalog Item, on an update request, I want to prepopulate the vendor manager and vendor type list collectors from the current core_company record, so that the righthand side contains existing values and requester can add new types/manager and/or remove existing values.

Code:

NOTE: arVendorType is the array of vendor type ids for the currently selected core_company record (ie the record the user wants to update).  This is populated correctly.

 

The error occurs on first gel() call the 3rd debug CONFIRM, dialog doesn't display:

 

 

function onCondition() {

var OrgLevel = g_form.getValue('sn_organisation_level');
var ReqType = g_form.getValue('sn_request_type');
var CompanyVal = g_form.getValue('sn_company_to_update');

//If this is a Company Update and Company has been selected
if ((OrgLevel == "company") && (ReqType == 'Update') && (CompanyVal != ''))
{
//get the current vendor_manager and vendor_type values for selected company record
var str = '';
var arVendorType = [];

//var grCompany = new GlideRecord('core_company');
var gref = g_form.getReference('sn_company_to_update');

str = gref.vendor_type.toString();
//add the current list values to each array
arVendorType = str.split(',');
}

//debugging
confirm("arVendorType: " + arVendorType);

//set the list collector selected values in the Update request form

//Set the VendorType righthand bucket values
var lcVendorType = 'sn_company_vendor_type_to_update';
confirm("lcVendorType: " + lcVendorType);

//problem here, dialog not shown
var VTleftBucket = gel(lcVendorType + '_select_0');
//var VTleftBucket = document.getElementById(lcVendorType + '_select_0');
//var VTleftBucket = document.getElementsByTagName(lcVendorType + '_select_0');
//var VTleftBucket = g_form.getControl(lcVendorType + '_select_0');
confirm("VTleftBucket: " + VTleftBucket);

var VTrightBucket = gel(lcVendorType + '_select_1');
//var VTrightBucket = g_form.getControl(lcVendorType + '_select_1');
confirm("VTrightBucket: " + VTrightBucket);

//Move all current Vendor Types from left ro right bucket and sort the results
moveSelectedOptions(arVendorType, VTleftBucket, VTrightBucket, '--None--');
//Sort the resultant options in the right bucket
sortSelect(VTrightBucket);


}

 

 

Sources:

https://community.servicenow.com/community?id=community_question&sys_id=9f3ac3a9db5cdbc01dcaf3231f9619b6

https://www.servicenowguru.com/scripting/client-scripts-scripting/move-list-collector-options/ 

2 REPLIES 2

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

Do you have isolate script field on client script set to false?


If not make it false and then try.


Thanks,
Ashutosh

Hi Ashotosh

I've set isolate script to False (hidden field)

Unfortunately that doesn't make any difference.  I've tried a few different methods now but none seem to work:

 

function onCondition() {

var OrgLevel = g_form.getValue('sn_organisation_level');
var ReqType = g_form.getValue('sn_request_type');
var CompanyVal = g_form.getValue('sn_company_to_update');

//If this is a Company Update and Company has been selected
if ((OrgLevel == "company") && (ReqType == 'Update') && (CompanyVal != ''))
{
//get the current vendor_manager and vendor_type values for selected company record
var str = '';
var arVendorType = [];

//var grCompany = new GlideRecord('core_company');
var gref = g_form.getReference('sn_company_to_update');

str = gref.vendor_type.toString();
//add the current list values to each array
arVendorType = str.split(',');
}

//debugging
confirm("arVendorType: " + arVendorType);

//set the list collector selected values in the Update request form

//Set the VendorType righthand bucket values
var lcVendorType = 'sn_company_vendor_type_to_update';
confirm("lcVendorType: " + lcVendorType);

//problem here, dialog not shown
var VTleftBucket = gel(lcVendorType + '_select_0');
//var VTleftBucket = document.getElementById(lcVendorType + '_select_0');
//var VTleftBucket = document.getElementsByTagName(lcVendorType + '_select_0');
//var VTleftBucket = g_form.getControl(lcVendorType + '_select_0');
confirm("VTleftBucket: " + VTleftBucket);

var VTrightBucket = gel(lcVendorType + '_select_1');
//var VTrightBucket = g_form.getControl(lcVendorType + '_select_1');
confirm("VTrightBucket: " + VTrightBucket);

//Move all current Vendor Types from left ro right bucket and sort the results
moveSelectedOptions(arVendorType, VTleftBucket, VTrightBucket, '--None--');
//Sort the resultant options in the right bucket
sortSelect(VTrightBucket);


}