Requirement | Script | Examples | Remarks |
Alert (Requests & Changes) | await CS.alert(“message”); | await CS.alert("Alert message"); | |
Confirm (Requests & Changes) | var confirm = await CS.confirm(“message”); if(confirm){ } else{ } | var confirm = await CS.confirm(“Do you want to proceed"); if(confirm){ } else{ } | |
Page Redirect (Requests & Changes) | await CS.alert(options); | Page redirection for internal links await CS.alert({ title: "Redirection Alert", message: "You are being redirected to Request list view", button_options: { label: "Proceed", redirectTo: "/ui/requests" } }); Page redirection for external links await CS.alert({ title: "Redirection Alert", message: "You are being redirected to an external website in a new tab", button_options: { label: "Proceed", redirectTo: "https://www.zoho.com", target: "_blank" } }); | Properties 1. title, message - defines custom text content to display in the alert’s title and message part. 2. button_options - defines redirection details. label - defines the alert button’s label content. redirectTo - defines URL for navigation. When redirecting to external links, ensure that the redirectTo property value contains the full URL, including the protocol. For example, using “www.zoho.com” is invalid and hence use “https://www.zoho.com”. target [optional] - If left undefined, the redirection will take place in the current tab. Setting the value to “_blank” will open the specified URL in a new tab. |
Get API (Requests & Changes) | await CS.API.get(“url”,”input_data”); | await CS.API.get('/api/v3/requests/technician/',{list_info:{search_criteria:{field:'roles.name',condition:'is',value:'SDAdmin'}}}); | To make internal API calls |
Hide Fields (Requests & Changes) | CS.hideField(fields) | CS.hideField(["level","priority","urgency"]); | |
Show Fields (Requests & Changes) | CS.showField(fields) | CS.showField(["level","priority","urgency"]) | |
Disable Fields (Requests & Changes) | CS.disableField(fields) | CS.disableField(["level","priority","urgency"]); | |
Enable Fields (Requests & Changes) | CS.enableField(fields) | CS.enableField(["level","priority","urgency"]); | |
Mandate Fields (Requests & Changes) | CS.mandateField(fields) | CS.mandateField(["level","priority","urgency"]); | |
Non-Mandate Fields (Requests & Changes) | CS.nonMandateField(fields) | CS.nonMandateField(["level","priority","urgency"]); | |
Add Options (Requests & Changes) | CS.addOptions(field,options) | CS.addOptions("urgency",["100000000000007061","100000000000007067"]); | Ensure that they are Pick Type fields and an array. |
Remove Options (Requests & Changes) | CS.removeOptions(field,options) | CS.removeOptions("status",["100000000000007061","100000000000007067"]); | Same as above. |
Reset Options (Requests & Changes) | CS.resetOptions(fields); | CS.resetOptions(["priority","impact"]); | Same as above. |
Clear Options (Requests & Changes) | CS.clearOptions(fields) | CS.clearOptions(["urgency"]); CS.clearOptions(["urgency","priority"]); | Same as above. |
Set a Field Value (Requests & Changes) | CS.setValue(field,value) | CS.setValue("subject","This is a test subject"); CS.setValue("urgency",{"name":"High","deleted":false,"id":"100000000000007061"}); CS.setValue("due_by_date", Date.now()); | |
Get Field Values (Requests & Changes) | CS.getValue(field) | var status=CS.getValue("status"); var created_date=CS.getValue("created_date"); | To retain the existing field values and store them in a variable. |
Clear Field Values (Requests & Changes) | CS.clearValue(fieldnames) | CS.clearValue(["priority","impact"]); | |
Set Criteria (Requests & Changes) | CS.setCriteria(<field_name>,<criteria>); | ||
Set Tasks (Requests) | CS.setTasks(tasksArray) | CS.setTasks([{"id":"100000000000033123","value":"Task 1"},{"id":"100000000000033125","value":"Task 2"}]); | Applicable only for request templates configured with tasks. |
Unset Tasks (Requests) | CS.unsetTasks(tasks) | CS.unsetTasks([{"id":"100000000000033123","value":"Task 1"},{"id":"100000000000033125","value":"Task 2"}]); | Same as above. |
Show Tasks (Requests) | CS.showTasks(tasks) | CS.showTasks([{"id":"100000000000033123","value":"Task 1"},{"id":"100000000000033125","value":"Task 2"}]); | Same as above. |
Hide Tasks (Requests) | CS.hideTasks(tasks) | CS.hideTasks([{"id":"100000000000033123","value":"Task 1"},{"id":"100000000000033125","value":"Task 2"}]); | Same as above. |
Show Resources (Requests) | CS.showResources(resources) | CS.showResources(["resources.res_100000000000030756"]); | Applicable only for request templates configured with resource questions. |
Hide Resources (Requests) | CS.hideResources(resources) | CS.hideResources(["resources.res_100000000000030756"]); | Same as above. |
Set Date Constraint (Requests & Changes) | CS.setDateConstraint(<field_names>,<constraint>); | const current_time = new Date().getTime(); var thirty_days = 30*24*60*60*1000; CS.setDateConstraint("scheduled_start_time",{minDate:current_time,maxDate:current_time+thirty_days}); | Set constraints for date fields |
Show Field Errors (Requests & Changes) | CS.showErrors({ field_name: <field_name>, message: <message>, error_key: <unique_error_identifier> }); | errors.push({ "field_name": "scheduled_end_time", "message": "Duration of the Change scheduled must not exceed 30 days", "error_key": "scheduled_end_time_ERR1" }); CS.showErrors(errors); | Display field specific error messages beneath the fields. Note: Using CS.abort() to abort form submission after CS.showErrors() is unnecessary, as the form is automatically aborted after CS.showErrors(). |
Clear Field Errors (Requests & Changes) | CS.clearErrors({ field_name: <field_name>, error_key: <unique_error_identifier> }); | Clear field specific error messages created with Show Field Error. | |
Get Local Data (Requests & Changes) | CS.dataStore.get(name) | CS.dataStore.get(“Technician"); | Uses the form's local data storage which the other custom scripts, configured for the same form, can access and return the data mentioned in the parameter. If the parameter is not passed, all the data stored is returned |
Set Local Data (Requests & Changes) | CS.dataStore.set(name,value) | CS.dataStore.set(“Technician",”John”); | Uses the form’s local data storage which the other custom scripts, configured for the same form, can access, and assign the data to the key mentioned in the parameter. By default, the dataStore contains the logged-in user’s information such as email, id, first & last name, photo url, etc which can be accessed by CS.dataStore.get(“CS_context”). |
On Field Change (Requests & Changes) | await CS.onFieldChange(<field_name>,<cbk>); | Triggers actions on field change in forms | |
On Form Submit (Requests & Changes) | CS.onFormSubmit(<cbk>); | Triggers actions on submitting forms | |
Abort (Requests & Changes) | CS.abort(<value>); | Aborts form submission |