---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# UserCriteria - Scoped

# UserCriteria - Scoped {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 4 minutes to read

The UserCriteria API provides methods to create, modify, and delete user criteria records using scripts.

To use this class in a scoped application, use the `sn_uc` namespace identifier. The User Criteria Scoped API plugin (ID: com.glideapp.user_criteria.scoped.api) must be enabled to access this API.

## UserCriteria - UserCriteria() {#ariaid-title2}

Creates an instance of the UserCriteria class.  

    var uc = new sn_uc.UserCriteria();

## UserCriteria - UserCriteria(String sys_id) {#ariaid-title3}

Creates an instance of the UserCriteria class with the specified sys_id.
{#r_UCS-UserCriteria_S__table_dxz_fz2_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| sys_id | String | sys_id of the user criteria. |
[Table 1. Parameters]

{#r_UCS-UserCriteria_S__table_dxz_fz2_vz}  

    var uc = new sn_uc.UserCriteria("31bea3d53790200044e0bfc8bcbe5dec");

## UserCriteria - create(Object columnValues, Boolean standardUpdate) {#ariaid-title4}

Creates a user criteria with specified values in the user_criteria table. Values
specified in columnValues override the values provided via setters.
{#r_UCS-create_O_B__table_ncp_prf_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| columnValues | Object | Key and value pairs for a column and its value. |
| standardUpdate | Boolean | Set to true to enable the running of engines and workflow. |
[Table 2. Parameters]

{#r_UCS-create_O_B__table_ncp_prf_vz} {#r_UCS-create_O_B__table_ocp_prf_vz__entry__2}

| Type | Description |
|-|-|
| String | sys_id of the created user criteria. |
[Table 3. Returns]

{#r_UCS-create_O_B__table_ocp_prf_vz}  

    var uc = new sn_uc.UserCriteria(); 
    uc.setCompanies("31bea3d53790200044e0bfc8bcbe5dec,0c441abbc6112275000025157c651c89");
    uc.setActive(true); 
    uc.setUsers("31bea3d53790200044e0bfc8bcbe5dec,0c441abbc6112275000025157c651c89");
    var UserCriteriaId = uc.create();
    gs.info(UserCriteriaId);

Output:

    41bea3d53790200044e0bfc8bcbe5dec

## UserCriteria - deleteRecord() {#ariaid-title5}

Deletes the current user criteria.
{#r_UCS-deleteRecord__table_erq_jlf_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 4. Parameters]

{#r_UCS-deleteRecord__table_erq_jlf_vz} {#r_UCS-deleteRecord__table_frq_jlf_vz__entry__2}

| Type | Description |
|-|-|
| Boolean | If true, the user criteria is deleted. If false, no user criteria is found to delete. |
[Table 5. Returns]

{#r_UCS-deleteRecord__table_frq_jlf_vz}  

    var uc = new sn_uc.UserCriteria("31bea3d53790200044e0bfc8bcbe5dec");
    uc.deleteRecord();

Output:

    true

## UserCriteria - read(String columns) {#ariaid-title6}

Displays the mapping for the attribute and value pairs of the catalog item.
{#r_UCS-read_S__table_rnk_bpf_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| columns | String | Array of catalog item attributes. |
[Table 6. Parameters]

{#r_UCS-read_S__table_rnk_bpf_vz} {#r_UCS-read_S__table_snk_bpf_vz__entry__2}

| Type | Description |
|-|-|
| Object | Mapping for the attribute and value pairs of the catalog item. |
[Table 7. Returns]

{#r_UCS-read_S__table_snk_bpf_vz}  

    var uc = new sn_uc.UserCriteria("7b8a6927ef732100438236caa5c0fb89");
    var obj = uc.read(["company","name"]);
    gs.info(JSON.stringify(obj));

Output:

    Script: {"name":"All ACME Corporation employees","company":"e7c1f3d53790200044e0bfc8bcbe5deb,227cdfb03710200044e0bfc8bcbe5d6b,86c1f3193790200044e0bfc8bcbe5d95,98c37b193790200044e0bfc8bcbe5dbe,81f95197ac1d55eb35432fd1e068385e,df7d53303710200044e0bfc8bcbe5dac,81fdf9ebac1d55eb4cb89f136a082555,4b7d13f03710200044e0bfc8bcbe5db6,81f87336ac1d55eb06002def816d139f,81fbfe03ac1d55eb286d832de58ae1fd,81fca4cbac1d55eb355b4b6db0e3c80f,187d13f03710200044e0bfc8bcbe5df2,81fd65ecac1d55eb42a426568fc87a63,31bea3d53790200044e0bfc8bcbe5dec,81f75fcaac1d55eb2b0781d6f2c3c260"}

## UserCriteria - setActive(Boolean active) {#ariaid-title7}

Specifies if the user criteria is active.
{#r_UCS-setActive_B__table_lc1_x3f_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| active | Boolean | If true, the user criteria is active. If false, the user criteria is inactive. |
[Table 8. Parameters]

{#r_UCS-setActive_B__table_lc1_x3f_vz} {#r_UCS-setActive_B__table_mc1_x3f_vz__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 9. Returns]

{#r_UCS-setActive_B__table_mc1_x3f_vz}  

    var uc = new sn_uc.UserCriteria();
    uc.setActive(true); 

## UserCriteria - setAdvanced(boolean advanced) {#ariaid-title8}

Specifies if the user criteria has an advanced script.
{#r_UCS-setAdvanced_B__table_eps_xff_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| advanced | Boolean | If true, the user criteria has an advanced script. If false, the user criteria does not have an advanced script. |
[Table 10. Parameters]

{#r_UCS-setAdvanced_B__table_eps_xff_vz} {#r_UCS-setAdvanced_B__table_fps_xff_vz__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 11. Returns]

{#r_UCS-setAdvanced_B__table_fps_xff_vz}  

    var uc = new sn_uc.UserCriteria();
    uc.setAdvanced(true); 

## UserCriteria - setCompanies(String companies) {#ariaid-title9}

Sets the company property for the user criteria.
{#r_UCS-setCompanies_S__table_qrr_gff_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| companies | String | Comma-separated list of the company sys_ids to be set for the user criteria. |
[Table 12. Parameters]

{#r_UCS-setCompanies_S__table_qrr_gff_vz} {#r_UCS-setCompanies_S__table_rrr_gff_vz__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 13. Returns]

{#r_UCS-setCompanies_S__table_rrr_gff_vz}  

    var uc = new sn_uc.UserCriteria();
    uc.setCompanies("31bea3d53790200044e0bfc8bcbe5dec,0c441abbc6112275000025157c651c89"); 

## UserCriteria - setDepartments(String departments) {#ariaid-title10}

Sets the department property for the user criteria.
{#r_UCS-setDepartments_S__table_k24_ddf_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| departments | String | Comma-separated list of the department sys_ids to be set for the user criteria. |
[Table 14. Parameters]

{#r_UCS-setDepartments_S__table_k24_ddf_vz} {#r_UCS-setDepartments_S__table_l24_ddf_vz__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 15. Returns]

{#r_UCS-setDepartments_S__table_l24_ddf_vz}  

    var uc = new sn_uc.UserCriteria();
    uc.setDepartments("31bea3d53790200044e0bfc8bcbe5dec,0c441abbc6112275000025157c651c89"); 

## UserCriteria - setGroups(String groups) {#ariaid-title11}

Sets the group property for the user criteria.
{#r_UCS-setGroups_S__table_zzq_j3f_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| groups | String | Comma-separated list of the group sys_ids to be set for the user criteria. |
[Table 16. Parameters]

{#r_UCS-setGroups_S__table_zzq_j3f_vz} {#r_UCS-setGroups_S__table_a1r_j3f_vz__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 17. Returns]

{#r_UCS-setGroups_S__table_a1r_j3f_vz}  

    var uc = new sn_uc.UserCriteria();
    uc.setGroups("31bea3d53790200044e0bfc8bcbe5dec,0c441abbc6112275000025157c651c89"); 

## UserCriteria - setLocations(String locations) {#ariaid-title12}

Sets the location property for the user criteria.
{#r_UCS-setLocations_S__table_hrs_42f_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| locations | String | Comma-separated list of the location sys_ids to be set for the user criteria. |
[Table 18. Parameters]

{#r_UCS-setLocations_S__table_hrs_42f_vz} {#r_UCS-setLocations_S__table_irs_42f_vz__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 19. Returns]

{#r_UCS-setLocations_S__table_irs_42f_vz}  

    var uc = new sn_uc.UserCriteria();
    uc.setLocations("31bea3d53790200044e0bfc8bcbe5dec,0c441abbc6112275000025157c651c89"); 

## UserCriteria - setMatchAll(Boolean match_all) {#ariaid-title13}

Sets the match_all property for the user criteria.
{#r_UCS-setMatchAll_B__table_wvg_gkf_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| None | match_all | If true, all conditions set as properties for the user criteria should be fulfilled. If false, at least one condition set as a property for the user criteria should be fulfilled. |
[Table 20. Parameters]

{#r_UCS-setMatchAll_B__table_wvg_gkf_vz} {#r_UCS-setMatchAll_B__table_xvg_gkf_vz__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 21. Returns]

{#r_UCS-setMatchAll_B__table_xvg_gkf_vz}  

    var uc = new sn_uc.UserCriteria();
    uc.setMatchAll(true); 

## UserCriteria - setName(String name) {#ariaid-title14}

Sets the name property for the user criteria.
{#r_UCS-setName_S__table_qzy_vhf_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Name of the user criteria. |
[Table 22. Parameters]

{#r_UCS-setName_S__table_qzy_vhf_vz} {#r_UCS-setName_S__table_rzy_vhf_vz__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 23. Returns]

{#r_UCS-setName_S__table_rzy_vhf_vz}  

    var uc = new sn_uc.UserCriteria();
    uc.setName("Property1"); 

## UserCriteria - setRoles(String roles) {#ariaid-title15}

Sets the role property for the user criteria.
{#r_UCS-setRoles_S__table_wxt_h1f_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| roles | String | Comma-separated list of the role sys_ids to be set for the user criteria. |
[Table 24. Parameters]

{#r_UCS-setRoles_S__table_wxt_h1f_vz} {#r_UCS-setRoles_S__table_xxt_h1f_vz__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 25. Returns]

{#r_UCS-setRoles_S__table_xxt_h1f_vz}  

    var uc = new sn_uc.UserCriteria();
    uc.setRoles("31bea3d53790200044e0bfc8bcbe5dec,0c441abbc6112275000025157c651c89"); 

## UserCriteria - setScript(String script) {#ariaid-title16}

Sets the script for the user criteria.
{#r_UCS-setScript_S__table_elp_zgf_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| script | String | Script to be set for the advanced user criteria. |
[Table 26. Parameters]

{#r_UCS-setScript_S__table_elp_zgf_vz} {#r_UCS-setScript_S__table_flp_zgf_vz__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 27. Returns]

{#r_UCS-setScript_S__table_flp_zgf_vz}  

    var uc = new sn_uc.UserCriteria();
    uc.setScript("function scriptTest() {
      var retVal;
      if (gs.getUser().getRecord().getDisplayValue('department') == 'Product Management') {
          retVal = true;
      } else {
          retVal = false;
      }
      return retVal;
    }"); 

## UserCriteria - setUsers(String users) {#ariaid-title17}

Sets the user property for the user criteria.
{#r_UCS-setUsers_S__table_npm_qbf_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| users | String | Comma-separated list of the user sys_ids to be set for the user criteria. |
[Table 28. Parameters]

{#r_UCS-setUsers_S__table_npm_qbf_vz} {#r_UCS-setUsers_S__table_opm_qbf_vz__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 29. Returns]

{#r_UCS-setUsers_S__table_opm_qbf_vz}  

    var uc = new sn_uc.UserCriteria();
    uc.setUsers("31bea3d53790200044e0bfc8bcbe5dec,0c441abbc6112275000025157c651c89"); 

## UserCriteria - update(Object columnValues, String reason) {#ariaid-title18}

Updates the current catalog item with the specified values.
{#r_UCS-update_O_S__table_nrg_fmf_vz__entry__3}

| Name | Type | Description |
|-|-|-|
| columnValues | Object | Mapping for the column name and the value pairs. |
| reason | String | Reason for updating the catalog item. |
[Table 30. Parameters]

{#r_UCS-update_O_S__table_nrg_fmf_vz} {#r_UCS-update_O_S__table_org_fmf_vz__entry__2}

| Type | Description |
|-|-|
| String | Returns the sys_id of the created user criteria. |
[Table 31. Returns]

{#r_UCS-update_O_S__table_org_fmf_vz}  

    var uc = new sn_uc.UserCriteria();
    uc.update("name": "Updated name", "The existing name is not relevant. Setting a relevant name"); 

Output:

    31bea3d53790200044e0bfc8bcbe5dec


