Greg is back with another intro to Deluge tutorial! In this video, we focus on editing data in Deluge. Make sure to check out the previous video on Reading Data!
Key Takeaways
Pulling in a Lead Record
Let’s start out by pulling our lead record in by using the steps learned in the last video. Here’s a quick run-through of that process in case you missed it.
- Create a variable called new lead followed by zoho.crm.getRecordById and the Leads module with the lead Id
- Drop a lead Id number into the leadId variable to get the data
- Use a JSON viewer to view the data more easily
- Back in the function add the variable name of the information you are trying to retrieve, followed by get with the API Name
Using “If Statements” to Run Some Checks
Now we need to run some checks using “If Statements”. The “If Statement” will need a condition so that it knows what information to pull depending on if that condition is met. You can meet multiple conditions in a single “If Statement” by adding a second condition separated from the first by either using && or ||. Sometimes the Deluge editor won’t know exactly what data type you are trying to input, it will give you a drop-down list of all the options. Make sure you select the correct data type for the variable you are trying to input. In this example, we are using a string variable.
In the tutorial, Greg’s goal is to edit the data so that when the full name is in the Last Name field, it will separate into the First and Last Name fields, respectively. The “If Statement” used identifies that when the First Name field is blank and the Last Name field contains a space, then the data will be edited. These specific conditions set in the code must be met in order for the data to be edited. Using the newFirstName and newLastName variables, Deluge will know what data to edit into each field. To get the proper case of the name, we add newFirstNameProper and newLastNameProper.
Getting Related Records for Open Tasks
If you would like to know specific information on the lead, you can add a getRealatedRecords function. Instead of getting a record by an Id, the getRelatedRecords function will ask for a relation name, the parent module, and an Id. You can also add additional parameters if needed. To get the relation name, you will go to your API Settings and filter by Related Lists instead of Fields. The parent module name is the name of the module you are pulling from. The Id number here is the Id of the parent record. Once you have all the variables filled out, you can hit the Save & Execute button, then drop the results back into that JSON viewer we used in the first part of the tutorial.
You’ll need some additional steps to get more specific information from the related record. In our example video, Greg has used the getRelatedRecords function to find out that there are 3 tasks within the record. However, after viewing the data in JSON, now the question is, how many of these tasks are open? To find out you’ll use a for each loop to iterate through the list of information, executing a certain piece of code over and over on each piece of the iteration. To get the status of each task, use task.get(“Status). Now we want the count of open tasks, count =. Another “If Statement” will be added to add the condition of any status that is not closed, giving us all of the open tasks. The counter should be a running total to get the accurate count of open tasks. The count running total function will be counter = counter + 1.
Additional Resources
We’ve read the data and edited it, but now what about sending that data out? No worries, watch our final segment in this series on writing data! Want to learn more about Deluge? Check out our other resources which include videos, articles, and guides by clicking here to visit the Deluge resource page.