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()

Creates an instance of the UserCriteria class.

Example

var uc = new sn_uc.UserCriteria();

UserCriteria - UserCriteria(String sys_id)

Creates an instance of the UserCriteria class with the specified sys_id.

Table 1. Parameters
Name Type Description
sys_id String sys_id of the user criteria.

Example

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

UserCriteria - create(Object columnValues, Boolean standardUpdate)

Creates a user criteria with specified values in the user_criteria table. Values specified in columnValues override the values provided via setters.

Table 2. Parameters
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 3. Returns
Type Description
String sys_id of the created user criteria.

Example

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()

Deletes the current user criteria.

Table 4. Parameters
Name Type Description
None
Table 5. Returns
Type Description
Boolean If true, the user criteria is deleted.

If false, no user criteria is found to delete.

Example

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

Output:

true

UserCriteria - read(String columns)

Displays the mapping for the attribute and value pairs of the catalog item.

Table 6. Parameters
Name Type Description
columns String Array of catalog item attributes.
Table 7. Returns
Type Description
Object Mapping for the attribute and value pairs of the catalog item.

Example

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)

Specifies if the user criteria is active.

Table 8. Parameters
Name Type Description
active Boolean If true, the user criteria is active.

If false, the user criteria is inactive.

Table 9. Returns
Type Description
void

Example

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

UserCriteria - setAdvanced(boolean advanced)

Specifies if the user criteria has an advanced script.

Table 10. Parameters
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 11. Returns
Type Description
void

Example

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

UserCriteria - setCompanies(String companies)

Sets the company property for the user criteria.

Table 12. Parameters
Name Type Description
companies String Comma-separated list of the company sys_ids to be set for the user criteria.
Table 13. Returns
Type Description
void

Example

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

UserCriteria - setDepartments(String departments)

Sets the department property for the user criteria.

Table 14. Parameters
Name Type Description
departments String Comma-separated list of the department sys_ids to be set for the user criteria.
Table 15. Returns
Type Description
void

Example

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

UserCriteria - setGroups(String groups)

Sets the group property for the user criteria.

Table 16. Parameters
Name Type Description
groups String Comma-separated list of the group sys_ids to be set for the user criteria.
Table 17. Returns
Type Description
void

Example

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

UserCriteria - setLocations(String locations)

Sets the location property for the user criteria.

Table 18. Parameters
Name Type Description
locations String Comma-separated list of the location sys_ids to be set for the user criteria.
Table 19. Returns
Type Description
void

Example

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

UserCriteria - setMatchAll(Boolean match_all)

Sets the match_all property for the user criteria.

Table 20. Parameters
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 21. Returns
Type Description
void

Example

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

UserCriteria - setName(String name)

Sets the name property for the user criteria.

Table 22. Parameters
Name Type Description
name String Name of the user criteria.
Table 23. Returns
Type Description
void

Example

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

UserCriteria - setRoles(String roles)

Sets the role property for the user criteria.

Table 24. Parameters
Name Type Description
roles String Comma-separated list of the role sys_ids to be set for the user criteria.
Table 25. Returns
Type Description
void

Example

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

UserCriteria - setScript(String script)

Sets the script for the user criteria.

Table 26. Parameters
Name Type Description
script String Script to be set for the advanced user criteria.
Table 27. Returns
Type Description
void

Example

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)

Sets the user property for the user criteria.

Table 28. Parameters
Name Type Description
users String Comma-separated list of the user sys_ids to be set for the user criteria.
Table 29. Returns
Type Description
void

Example

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

UserCriteria - update(Object columnValues, String reason)

Updates the current catalog item with the specified values.

Table 30. Parameters
Name Type Description
columnValues Object Mapping for the column name and the value pairs.
reason String Reason for updating the catalog item.
Table 31. Returns
Type Description
String Returns the sys_id of the created user criteria.

Example

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

Output:

31bea3d53790200044e0bfc8bcbe5dec