Thank you for your feedback.
Form temporarily unavailable. Please try again or contact docfeedback@servicenow.com to submit your comments.
Versions
  • London
  • Kingston
  • Jakarta
  • Istanbul
  • Helsinki
  • Geneva
  • Store
Close

Client script usage examples

Client script usage examples

Use the following as examples for how to use client scripts in Service Portal.

g_list

The g_list global helps you set the filter of a glide list element or a list collector variable. Use this API in place of the g_filter API on desktop client scripts.
function onLoad() {
  var myListCollector = g_list.get("my_list_collector");
  myListCollector.reset();
  myListCollector.setQuery("active=true^category=8c7b22230b402200b0b02c6317673a62");
  myListCollector.addItem('3a700d39af5f4fc0aab978df90f4c692', 'Power Supply');
  myListCollector.addItem('1cb93419a3a248318da8f814140b42f6', 'Backpack');
}

g_service_catalog

The g_service_catalog global is only available in Service Portal service catalog item scripts. Use this API to know if your catalog item script is being run as part of an order guide or on its own.
 function onLoad() {
   if (window) // if CMS don't run this
    return;

    // g_service_catalog api for Service Portal and Mobile
    var isOrderGuide = g_service_catalog.isOrderGuide();
    g_form.setValue("is_order_guide", isOrderGuide ? "Yes!" : "Nope :(");
}