UserCriteria - Scoped

UserCriteria API enables you to create, modify, or 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) should be enabled to access the UserCriteria API.

Scoped 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 1. 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 2. 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 = UserCriteria.create();
gs.info(UserCriteriaId);

Output

41bea3d53790200044e0bfc8bcbe5dec

Scoped UserCriteria - deleteRecord()

Deletes the current user criteria.

Table 3. Parameters
Name Type Description
None
Table 4. 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

Scoped UserCriteria - read(String[] columns)

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

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

Example

var uc = new sn_uc.UserCriteria();
uc.read({"name", "applies_to"});

Output

name: My Catalog Item;
        applies_to: catalog_item;

Scoped UserCriteria - setActive(Boolean active)

Specifies if the user criteria is active.

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

If false, the user criteria is inactive.

Table 8. Returns
Type Description
void

Example

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

Scoped UserCriteria - setAdvanced(boolean advanced)

Specifies if the user criteria has an advanced script.

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

Example

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

Scoped UserCriteria - setCompanies(String companies)

Sets the company property for the user criteria.

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

Example

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

Scoped UserCriteria - setDepartments(String departments)

Sets the department property for the user criteria.

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

Example

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

Scoped UserCriteria - setGroups(String groups)

Sets the group property for the user criteria.

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

Example

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

Scoped UserCriteria - setLocations(String locations)

Sets the location property for the user criteria.

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

Example

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

Scoped UserCriteria - setMatchAll(Boolean match_all)

Sets the match_all property for the user criteria.

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

Example

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

Scoped UserCriteria - setName(String name)

Sets the name property for the user criteria.

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

Example

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

Scoped UserCriteria - setRoles(String roles)

Sets the role property for the user criteria.

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

Example

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

Scoped UserCriteria - setScript(String script)

Sets the script for the user criteria.

Table 25. Parameters
Name Type Description
script String Script to be set for the advanced user criteria.
Table 26. 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;
}"); 

Scoped UserCriteria - setUsers(String users)

Sets the user property for the user criteria.

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

Example

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

Scoped UserCriteria - update(Object columnValues, String reason)

Updates the current catalog item with the specified values.

Table 29. Parameters
Name Type Description
columnValues Object Mapping for the column name and the value pairs.
reason String Reason for updating the catalog item.
Table 30. 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

Scoped UserCriteria - UserCriteria()

Creates an instance of the UserCriteria class.

var uc = new sn_uc.UserCriteria();

Scoped UserCriteria - UserCriteria(String sys_id)

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

Table 31. Parameters
Name Type Description
sys_id String sys_id of the user criteria.
var uc = new sn_uc.UserCriteria("31bea3d53790200044e0bfc8bcbe5dec");