|
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.
-
var statusId=$CS.getValue("STATUS");
-
var subject= $CS.getValue("SUBJECT");
-
var created_date=$CS.getValue("CREATEDTIME"); //This will return a JavaScript Date Object
————————————————————————————————————————————————————————————————————————————————————————
-
$CS.setValue("STATUS","1");
-
$CS.setValue("SUBJECT","test request");
-
$CS.setValue("UDF_DATE1",new Date("20 May 2015, 15:23:00"));
-
$CS.setValue("UDF_DATE1",""); [For setting empty value to the date field]
————————————————————————————————————————————————————————————————————————————————————————
-
var status=$CS.getText("STATUS");
————————————————————————————————————————————————————————————————————————————————————————
-
$CS.setText("STATUS","Open");
————————————————————————————————————————————————————————————————————————————————————————
-
$CS.addOptions("STATUS",["Open","Closed"]);
————————————————————————————————————————————————————————————————————————————————————————
-
$CS.removeOptions("STATUS",["Open","Closed"]);
————————————————————————————————————————————————————————————————————————————————————————
-
$CS.removeAllOptions(["STATUS"]); // If all options of status field is removed, new request creation will not work. Since every request should have a status.
-
$CS.removeAllOptions(["STATUS","PRIORITY"]);
————————————————————————————————————————————————————————————————————————————————————————
-
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.
-
$CS.enableField(["LEVEL"]);
- $CS.enableField(["STATUS","PRIORITY"]);
————————————————————————————————————————————————————————————————————————————————————————
-
$CS.disableField(["LEVEL"]);
- $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.
-
$CS.hideField(["LEVEL"]);
- $CS.hideField(["STATUS","PRIORITY"]);
——————————————————————————————————————————————————————————————————————————————————————
-
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.
-
$CS.showField(["LEVEL"]);
- $CS.showField(["STATUS","PRIORITY"]);
————————————————————————————————————————————————————————————————————————————————————————
-
$CS.mandateField(["LEVEL"]);
- $CS.mandateField(["STATUS","PRIORITY"]);
————————————————————————————————————————————————————————————————————————————————————————
-
$CS.nonMandateField(["LEVEL"]);
- $CS.nonMandateField(["STATUS","PRIORITY"]);
————————————————————————————————————————————————————————————————————————————————————————
-
var status=$CS.getText("STATUS");
-
if(status==="Closed")
-
{
-
$CS.stopFormSubmission();
-
}
————————————————————————————————————————————————————————————————————————————————————————
-
$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.
-
$CS.hasRole("ModifyRequests");
————————————————————————————————————————————————————————————————————————————————————————
-
var userId=$CS.getLoggedInUserId();
————————————————————————————————————————————————————————————————————————————————————————
-
var userName= $CS.getLoggedInUserName();
————————————————————————————————————————————————————————————————————————————————————————
-
$CS.setFieldDependency(dependencyObject);
2-LEVEL Dependency JSON Object:
-
{
-
"FIELDS" :["Country","City"],
-
"VALUES":{
-
"India":["Mumbai","Chennai],
-
"America":["California","Chicago"]
-
}
-
}
3-LEVEL Dependency JSON Object:
-
{
-
"FIELDS":["Country","City","Support Rep"],
-
"VALUES":{
-
"India":{
-
"Mumbai":["Ali Hassan","Neha Agarwal"],
-
"Chennai":["Guru Prasath","Ramesh Kumar"]
-
},
-
"America":{
-
"California":["Donald Miller","Lisa Turner"],
-
"Chicago":["Margaret Taylor","Ronald Lewis"]
-
}
-
}
-
}
————————————————————————————————————————————————————————————————————————————————————————
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 = .
|