{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":42618,"path":"platform-user-interface/service-portal/unsupported_client_scripts.md","title":"Service Portal and client scripts","bundle":null,"doc_type":null,"release":"australia","body":"\n# Service Portal and client scripts\n\nYou can use client scripts and catalog client scripts in the Service Portal if the UI Type is set to **Mobile / Service Portal** or **All**. Client scripts and catalog client scripts are used with the Form widget and SC Catalog Item widget, as opposed to a widget client controller.\n\nBefore flagging a script as **Mobile/Service Portal** or **All**, make sure that you are only using the mobile APIs. Setting a client script to **Mobile** does not ensure that it will work, it simply flags that the script should be attempted by the mobile app or the Service Portal. Many of your existing client scripts can be set to **All** as long as the API calls are supported by the mobile client scripting environment.\n\nThe topics in this section require advanced coding knowledge and an understanding of Service Portal APIs.\n\n## Checking desktop vs mobile runtime\n\nYou might want to mark a client script compatible with both desktop and mobile, but include behavior that depends on the runtime. You can use this script:\n\n```\n  if (window === null)\n    // Write your mobile compatible code here\n  else\n    // Write your desktop compatible code here\n```\n\n## Unsupported client scripting globals\n\nThe following globals and APIs are unavailable in client scripts and catalog client scripts used in the Service Portal:\n\n-   $\n-   $$\n-   $j\n-   angular\n-   control\n-   document\n-   jQuery\n-   window\n\n**Note:** Widget client controllers are full Angular controllers and are not subject to the unsupported client script globals listed here. Use jQuery and Angular as needed.\n\n## Embedded widgets &amp; g\\_form\n\nWhen using the Service Catalog variable type **Macro** and **Macro with Label**, you can pick a widget to embed in a catalog item form. Within the client controller for the embedded widget you can access the field object and catalog item g\\_form instance using:\n\n-   `$scope.page.field`\n-   `$scope.page.g_form()`\n\n## Client scripts used with Service Portal\n\nThe 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.\n\n```\nfunction onLoad() {\n  var myListCollector = g_list.get(\"my_list_collector\");\n  myListCollector.reset();\n  myListCollector.setQuery(\"active=true^category=8c7b22230b402200b0b02c6317673a62\");\n  myListCollector.addItem('3a700d39af5f4fc0aab978df90f4c692', 'Power Supply');\n  myListCollector.addItem('1cb93419a3a248318da8f814140b42f6', 'Backpack');\n}\n```\n\ng\\_service\\_catalog is only available in Service Portal service catalog item scripts. Use this API to know if your catalog item script is run as part of an order guide or on its own.\n\n```\nfunction onLoad() {\n  if (window) // if CMS, don't run this\n   return;\n\n   // g_service_catalog api for Service Portal and Mobile\n   var isOrderGuide = g_service_catalog.isOrderGuide();\n   g_form.setValue(\"is_order_guide\", isOrderGuide ? \"Yes!\" : \"Nope :(\");\n}\n```\n\n-   **[Supported client script types and APIs](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/platform-user-interface/service-portal/client-script-reference.md)**  \nSome client scripts are not supported in Service Portal. Others must have a UI type set to **All** or **Mobile / Service Portal**. If using a client script in the Service Portal, only client-side APIs supported in a mobile environment can be used.\n\n**Parent Topic:**[Supported features in Service Portal](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/platform-user-interface/service-portal/unsupported-features-sp.md)\n\n"}}