SupportCenter Plus

Field And Form Rules - Supported JavaScript Functions

By default, script should be written in JavaScript format only. Moreover, jQuery and $CS have been added in global scope, thus allowing the user to write code using jQuery (v 1.7.2) and $CS library. (Note: $ is not supported for accessing elements using jQuery).

JavaScript functions Available in $CS Library 

  • $CS.getValue(fieldId) 

    • You can get the value of a field by using this function.

    • For input text type fields, this function sets the input text.

    • For select (Pick List) type fields, this function sets the value of the selected option.

  1. var statusId=$CS.getValue("STATUS");

  2. var subject= $CS.getValue("SUBJECT");

  3. var created_date=$CS.getValue("CREATEDTIME");  //This will return a JavaScript Date Object

  • $CS.setValue(fieldId,value) 

    • You can set the value of a field by using this function.

    • For input text type fields, this function sets the input text.

    • For select (Pick List) type fields, this function sets the value of the selected option.

  1. $CS.setValue("STATUS","1"); 

  2. $CS.setValue("SUBJECT","test request"); 

  3. $CS.setValue("UDF_DATE1",new Date("20 May 2015, 15:23:00"));

  4. $CS.setValue("UDF_DATE1","");  [For setting empty value to the date field] 

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.getText(fieldId) 

    • You can get the selected option text of a field by using this function.

    • This function should be used only for select (Pick List) type fields.

  1. var status=$CS.getText("STATUS");

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.setText(fieldId,text) 

    • You can set selected option text of a field by using this function.
    • This function should only be used for select (Pick List) type fields.
  1. $CS.setText("STATUS","Open");

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.addOptions(fieldId,options)

    • You can add options to a field by using this function.

    • Here, the options should be an  array  of options.

    • This function should be used only for select (Pick List) type fields. 

  1. $CS.addOptions("STATUS",["Open","Closed"]);

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.removeOptions(fieldId,options)

    • You can remove the existing options of a field by using this function.

    • Here, the options should be an array of options.

    • This function should be used only for select (Pick List) type fields. 

  1. $CS.removeOptions("STATUS",["Open","Closed"]);

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.removeAllOptions(fieldIds)

    • You can remove all the existing options of one or more select (Pick List) type fields by using this function.

    • Here, the fields should be an array of fields whose options need to be removed.

  1. $CS.removeAllOptions(["STATUS"]);   // If all options of status field is removed, new request creation will not work. Since every request should have a status.

  2. $CS.removeAllOptions(["STATUS","PRIORITY"]); 

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.enableField(fieldIds)

    • You can enable one or more fields by using this function.

    • Here, the fields should be an array of fields that you wish to enable.

  1. $CS.enableField(["LEVEL"]); 

  2. $CS.enableField(["STATUS","PRIORITY"]);

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.disableField(fieldIds)

    • You can disable one or more fields by using this function. This allows the user only to view the fields, but not to edit them.

    • Here, the fields should be an array of fields that you wiish to disable.

  1. $CS.disableField(["LEVEL"]); 

  2. $CS.disableField(["STATUS","PRIORITY"]);

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.hideField(fieldIds)

    • You can hide one or more fields by using this function. This restricts the user from viewing those fields.

    • Here, the fields should be an array of fields that you wish to hide.

  1. $CS.hideField(["LEVEL"]); 

  2. $CS.hideField(["STATUS","PRIORITY"]);

——————————————————————————————————————————————————————————————————————————————————————

  • $CS.showField(fieldIds)

  • You can show one or more hidden fields  using this function. Thus user will be able to see these fields.

  • Here, the fields should be an array of fields that you wish to show.

  1. $CS.showField(["LEVEL"]); 

  2. $CS.showField(["STATUS","PRIORITY"]);

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.mandateField(fieldIds)

    • You can mandate one or more fields by using this function. This restricts the user from submitting the form without filling values for those fields.

    • Here, the fields should be an array of fields that you wish to mandate.

  1. $CS.mandateField(["LEVEL"]); 

  2. $CS.mandateField(["STATUS","PRIORITY"]);

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.nonMandateField(fieldIds)

    • You can remove mandate from one or more fields by using this function. This allows the user to submit the form without filling values for those fields.       

  1. $CS.nonMandateField(["LEVEL"]); 

  2. $CS.nonMandateField(["STATUS","PRIORITY"]);

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.stopFormSubmission()

    • You can use this function to stop form submission. 

    • This function will work only when applied to "On Form Submit" event.

  1. var status=$CS.getText("STATUS");

  2. if(status==="Closed")

  3. {

  4. $CS.stopFormSubmission();

  5. }

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.isRequester()

    • You can use this function to find if a logged-in user is a Requester or not.

    • This function returns the value True, if the logged-in user is a Requester, else returns the value False. 

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.isTechnician()

    • You can use this function to find if a logged-in user is a Technician or not.

    • This function returns the value True, if the logged-in user is a Technician, else returns the value False.

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.hasRole(roleName)

    • You can use this function to find if a logged-in user has the assigned roleName.

    • This function returns the value True, if the logged-in user possesses the role with the assigned roleName, else returns the value False.

  1. $CS.hasRole("ModifyRequests");

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.getLoggedInUserId()

    • You can use this function to get the User ID of a logged-in user. 

  1. var userId=$CS.getLoggedInUserId();

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.getLoggedInUserName()

    • You can use this function to get the User Name of a logged-in user.

  1. var userName= $CS.getLoggedInUserName();

————————————————————————————————————————————————————————————————————————————————————————

  • $CS.setFieldDependency(dependencyObject)

    • You can use this function to set dependency among the fields based on dependency JSON Object. 

    • Here, the same function works for both two-field and three-field dependencies.

  1. $CS.setFieldDependency(dependencyObject);


2-LEVEL Dependency JSON Object:

  1. {

  2. "FIELDS" :["Country","City"],

  3. "VALUES":{

  4. "India":["Mumbai","Chennai],

  5. "America":["California","Chicago"]

  6. }

  7. }


3-LEVEL Dependency JSON Object:

  1. {

  2. "FIELDS":["Country","City","Support Rep"],

  3. "VALUES":{

  4. "India":{

  5. "Mumbai":["Ali Hassan","Neha Agarwal"],

  6. "Chennai":["Guru Prasath","Ramesh Kumar"]

  7. },

  8. "America":{

  9. "California":["Donald Miller","Lisa Turner"],

  10. "Chicago":["Margaret Taylor","Ronald Lewis"]

  11. }

  12. }

  13. }

————————————————————————————————————————————————————————————————————————————————————————

Note: 

Errors encountered during script execution will be visible at console in the following format:Caught following exception in executing field & form rules script execution of rule:[ Rule name ] at line number: [ line number ] and column:[ column number ] --> Error Message


Example:

Caught following exception in executing field & form rules script execution of rule:[ check for open request ] at line number: [ 2 ] and column: [ 8 ] --> Uncaught SyntaxError: Unexpected token = .

 

Copyright © 2017, ZOHO Corp. All Rights Reserved.