· 5 years ago · Jan 26, 2021, 11:58 AM
1
2import os
3from datetime import date, datetime
4from zcrmsdk.src.com.zoho.crm.api.record import *
5from zcrmsdk.src.com.zoho.crm.api.attachments import Attachment
6from zcrmsdk.src.com.zoho.crm.api.tags import Tag
7from zcrmsdk.src.com.zoho.crm.api.layouts import Layout
8from zcrmsdk.src.com.zoho.crm.api.users import User
9from zcrmsdk.src.com.zoho.crm.api import HeaderMap, ParameterMap
10from zcrmsdk.src.com.zoho.crm.api.util import Choice, StreamWrapper
11from zcrmsdk.src.com.zoho.crm.api.record import Record as ZCRMRecord
12class Record(object):
13 @staticmethod
14 def update_record(module_api_name, record_id):
15
16 """
17 This method is used to update a single record of a module with ID and print the response.
18 :param module_api_name: The API Name of the record's module.
19 :param record_id: The ID of the record to be updated
20 """
21
22 """
23 example
24 module_api_name = 'Leads'
25 record_id = 3477061000006603276
26 """
27
28 # Get instance of RecordOperations Class
29 record_operations = RecordOperations()
30
31 # Get instance of BodyWrapper Class that will contain the request body
32 request = BodyWrapper()
33
34 # List to hold Record instances
35 records_list = []
36
37 # Get instance of Record Class
38 record = ZCRMRecord()
39
40 # Value to Record's fields can be provided in any of the following ways
41
42 """
43 Call add_field_value method that takes two arguments
44 Import the zcrmsdk.src.com.zoho.crm.api.record.field file
45 1 -> Call Field "." and choose the module from the displayed list and press "." and choose the field name from the displayed list.
46 2 -> Value
47 """
48
49 record.add_field_value(Field.Leads.last_name(), 'Python SDK')
50
51 record.add_field_value(Field.Leads.first_name(), 'New')
52
53 record.add_field_value(Field.Leads.company(), 'Zoho')
54
55 record.add_field_value(Field.Leads.city(), 'City')
56
57 """
58 Call add_key_value method that takes two arguments
59 1 -> A string that is the Field's API Name
60 2 -> Value
61 """
62
63 record.add_key_value('Custom_field', 'Value')
64
65 record.add_key_value('Custom_field_2', 12)
66
67 record.add_key_value('Date', date(2020, 4, 9))
68
69 record.add_key_value('Discounted', 23.34)
70
71 file_details = []
72
73 file_detail = FileDetails()
74
75 file_detail.set_file_id('479f0f5eebf0fb982f99e3832b35d23e29f67c2868ee4c789f22579895383c8')
76
77 file_details.append(file_detail)
78
79 record.add_key_value('File_Upload_1', file_details)
80
81 # Used when GDPR is enabled
82 data_consent = Consent()
83
84 data_consent.set_consent_remarks("Approved.")
85
86 data_consent.set_consent_through('Email')
87
88 data_consent.set_contact_through_email(True)
89
90 data_consent.set_contact_through_social(False)
91
92 record.add_field_value('Data_Processing_Basis_Details', data_consent)
93
94 # Add Record instance to the list
95 records_list.append(record)
96
97 # Set the list to data in BodyWrapper instance
98 request.set_data(records_list)
99
100 trigger = ["approval", "workflow", "blueprint"]
101
102 # Set the list containing the trigger operations to be run
103 request.set_trigger(trigger)
104
105 # Call updateRecord method that takes BodyWrapper instance, module_api_name and record_id as parameter.
106 response = record_operations.update_record(record_id, module_api_name, request)
107
108 if response is not None:
109 # Get the status code from response
110 print('Status Code: ' + str(response.get_status_code()))
111
112 # Get object from response
113 response_object = response.get_object()
114
115 if response_object is not None:
116
117 # Check if expected ActionWrapper instance is received.
118 if isinstance(response_object, ActionWrapper):
119
120 # Get the list of obtained ActionResponse instances
121 action_response_list = response_object.get_data()
122
123 for action_response in action_response_list:
124
125 # Check if the request is successful
126 if isinstance(action_response, SuccessResponse):
127 # Get the Status
128 print("Status: " + action_response.get_status().get_value())
129
130 # Get the Code
131 print("Code: " + action_response.get_code().get_value())
132
133 print("Details")
134
135 # Get the details dict
136 details = action_response.get_details()
137
138 for key, value in details.items():
139 print(key + ' : ' + str(value))
140
141 # Get the Message
142 print("Message: " + action_response.get_message().get_value())
143
144 # Check if the request returned an exception
145 elif isinstance(action_response, APIException):
146 # Get the Status
147 print("Status: " + action_response.get_status().get_value())
148
149 # Get the Code
150 print("Code: " + action_response.get_code().get_value())
151
152 print("Details")
153
154 # Get the details dict
155 details = action_response.get_details()
156
157 for key, value in details.items():
158 print(key + ' : ' + str(value))
159
160 # Get the Message
161 print("Message: " + action_response.get_message().get_value())
162
163 # Check if the request returned an exception
164 elif isinstance(response_object, APIException):
165 # Get the Status
166 print("Status: " + response_object.get_status().get_value())
167
168 # Get the Code
169 print("Code: " + response_object.get_code().get_value())
170
171 print("Details")
172
173 # Get the details dict
174 details = response_object.get_details()
175
176 for key, value in details.items():
177 print(key + ' : ' + str(value))
178
179 # Get the Message
180 print("Message: " + response_object.get_message().get_value())
181