Python SDK Samples - Module Operations

Meta Data
Get List of Module Fields

# Get list of module fields
# -------------------------
def get_fields(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Accounts')# Module API Name
        resp = module_ins.get_all_fields()
        print(resp.status_code)
        field_ins_arr = resp.data
        for field_ins in field_ins_arr:
            print(field_ins.api_name)
            print(field_ins.id)
            print(field_ins.is_custom_field)
            lookup_field = field_ins.lookup_field
            if lookup_field is not None:
                print(lookup_field.id)
                print(lookup_field.api_name)
                print(lookup_field.display_label)
                print(lookup_field.module)
            print(field_ins.convert_mapping)
            print(field_ins.is_visible)
            print(field_ins.field_label)
            print(field_ins.length)
            print(field_ins.created_source)
            print(field_ins.default_value)
            print(field_ins.is_mandatory)
            print(field_ins.sequence_number)
            print(field_ins.is_read_only)
            print(field_ins.is_unique_field)
            print(field_ins.is_case_sensitive)
            print(field_ins.data_type)
            print(field_ins.is_formula_field)
            print(field_ins.is_currency_field)
            picklist_values = field_ins.picklist_values
            if picklist_values is not None:
                for picklist_value in picklist_values:
                    print(picklist_value.display_value)
                    print(picklist_value.sequence_number)
                    print(picklist_value.actual_value)
                    print(picklist_value.maps)
            print(field_ins.is_auto_number)
            print(field_ins.is_business_card_supported)
            print(field_ins.field_layout_permissions)
            print(field_ins.decimal_place)
            print(field_ins.precision)
            print(field_ins.rounding_option)
            print(field_ins.formula_return_type)
            print(field_ins.formula_expression)
            print(field_ins.prefix)
            print(field_ins.suffix)
            print(field_ins.start_number)
            print(field_ins.json_type)
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Get Field Data

# Get single field data
# ---------------------
def get_field(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Accounts')# Module API Name
        api_resp = module_ins.get_field(3477061000000)# field id
        print(api_resp.status_code)
        field_ins = api_resp.data
        print(field_ins.api_name)
        print(field_ins.id)
        print(field_ins.is_custom_field)
        lookup_field = field_ins.lookup_field
        if lookup_field is not None:
            print(lookup_field.id)
            print(lookup_field.api_name)
            print(lookup_field.display_label)
            print(lookup_field.module)
        print(field_ins.convert_mapping)
        print(field_ins.is_visible)
        print(field_ins.field_label)
        print(field_ins.length)
        print(field_ins.created_source)
        print(field_ins.default_value)
        print(field_ins.is_mandatory)
        print(field_ins.sequence_number)
        print(field_ins.is_read_only)
        print(field_ins.is_unique_field)
        print(field_ins.is_case_sensitive)
        print(field_ins.data_type)
        print(field_ins.is_formula_field)
        print(field_ins.is_currency_field)
        picklist_values = field_ins.picklist_values
        if picklist_values is not None:
            for picklist_value in picklist_values:
                print(picklist_value.display_value)
                print(picklist_value.sequence_number)
                print(picklist_value.actual_value)
                print(picklist_value.maps)
        print(field_ins.is_auto_number)
        print(field_ins.is_business_card_supported)
        print(field_ins.field_layout_permissions)
        print(field_ins.decimal_place)
        print(field_ins.precision)
        print(field_ins.rounding_option)
        print(field_ins.formula_return_type)
        print(field_ins.formula_expression)
        print(field_ins.prefix)
        print(field_ins.suffix)
        print(field_ins.start_number)
        print(field_ins.json_type)
        print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 

# Get list of module related lists
# --------------------------------
def get_all_relatedlists(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Accounts')# Module API Name
        resp = module_ins.get_all_relatedlists()
        print(resp.status_code)
        relatedlist_instances = resp.data
        for relatedlist_instance in relatedlist_instances:
            print("\n\n:::MODULE RELATEDLIST DETAILS:::")
            print(relatedlist_instance.api_name)
            print(relatedlist_instance.module)
            print(relatedlist_instance.display_label)
            print(relatedlist_instance.is_visible)
            print(relatedlist_instance.name)
            print(relatedlist_instance.id)
            print(relatedlist_instance.href)
            print(relatedlist_instance.type)
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 

# Get single related list details
# -------------------------------
def get_relatedlist(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Accounts')# Module API Name
        resp = module_ins.get_relatedlist(3477061000)# Related list id
        print(resp.status_code)
        relatedlist_instances = [resp.data]
        for relatedlist_instance in relatedlist_instances:
            print("\n\n:::MODULE RELATEDLIST DETAILS:::")
            print(relatedlist_instance.api_name)
            print(relatedlist_instance.module)
            print(relatedlist_instance.display_label)
            print(relatedlist_instance.is_visible)
            print(relatedlist_instance.name)
            print(relatedlist_instance.id)
            print(relatedlist_instance.href)
            print(relatedlist_instance.type)
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Get List of Layouts of a Module

# Get list of module layouts
# --------------------------
def get_all_layouts(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Accounts')# Module API Name
        resp = module_ins.get_all_layouts()
        print(resp.status_code)
        layout_ins_arr = resp.data
        for layout_ins in layout_ins_arr:
            print("\n\n:::LAYOUT DETAILS:::")
            print(layout_ins.name)
            print(layout_ins.id)
            print(layout_ins.created_time)
            print(layout_ins.modified_time)
            print(layout_ins.convert_mapping)
            print(layout_ins.is_visible)
            modified_by = layout_ins.modified_by
            if modified_by is not None:
                print(modified_by.id)
                print(modified_by.name)
            profiles = layout_ins.accessible_profiles
            if profiles is not None:
                for profile in profiles:
                    print("\n\n")
                    print(profile.id)
                    print(profile.name)
                    print(profile.is_default)
            print(layout_ins.created_by)
            sections = layout_ins.sections
            if sections is not None:
                print("\n:::SECTION DETAILS:::")
                for secton in sections:
                    print(secton.name)
                    print(secton.display_name)
                    print(secton.column_count)
                    print(secton.sequence_number)
                    fields = secton.fields
                    if fields is not None:
                        print("\n:::FIELD DETAILS:::")
                        for field_ins in fields:
                            print(field_ins.api_name)
                            print(field_ins.id)
                            print(field_ins.is_custom_field)
                            lookup_field = field_ins.lookup_field
                            if lookup_field is not None:
                                print(lookup_field.id)
                                print(lookup_field.api_name)
                                print(lookup_field.display_label)
                                print(lookup_field.module)
                            print(field_ins.convert_mapping)
                            print(field_ins.is_visible)
                            print(field_ins.field_label)
                            print(field_ins.length)
                            print(field_ins.created_source)
                            print(field_ins.default_value)
                            print(field_ins.is_mandatory)
                            print(field_ins.sequence_number)
                            print(field_ins.is_read_only)
                            print(field_ins.is_unique_field)
                            print(field_ins.is_case_sensitive)
                            print(field_ins.data_type)
                            print(field_ins.is_formula_field)
                            print(field_ins.is_currency_field)
                            picklist_values = field_ins.picklist_values
                            if picklist_values is not None:
                                for picklist_value in picklist_values:
                                    print(picklist_value.display_value)
                                    print(picklist_value.sequence_number)
                                    print(picklist_value.actual_value)
                                    print(picklist_value.maps)
                            print(field_ins.is_auto_number)
                            print(field_ins.is_business_card_supported)
                            print(field_ins.field_layout_permissions)
                            print(field_ins.decimal_place)
                            print(field_ins.precision)
                            print(field_ins.rounding_option)
                            print(field_ins.formula_return_type)
                            print(field_ins.formula_expression)
                            print(field_ins.prefix)
                            print(field_ins.suffix)
                            print(field_ins.start_number)
                            print(field_ins.json_type)
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Get List of Custom Views of a Module

# Get list of module customviews
# ------------------------------
def get_all_customviews(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Accounts')# Module API Name
        resp = module_ins.get_all_customviews()
        print(resp.status_code)
        cv_ins_arr = resp.data
        for customview_ins in cv_ins_arr:
            print("\n\n:::CUSTOM VIEW DETAILS:::")
            print(customview_ins.id)
            print(customview_ins.module_api_name)
            print(customview_ins.display_value)
            print(customview_ins.is_default)
            print(customview_ins.name)
            print(customview_ins.system_name)
            print(customview_ins.sort_by)
            print(customview_ins.category)
            fields = customview_ins.fields
            if fields is not None:
                print("\n:::FIELDS:::")
                for field in fields:
                    print(field)
            print(customview_ins.favorite)
            print(customview_ins.sort_order)
            cv_criteria = customview_ins.criteria
            if cv_criteria is not None:
                print("\n\n :::CRITERIA::::")
                for criteria_ins in cv_criteria:
                    print(criteria_ins.field)
                    print(criteria_ins.comparator)
                    print(criteria_ins.value)
                print(customview_ins.criteria_pattern)
            categories = customview_ins.categories
            print("\n\n :::CATEGORIES::::")
            if categories is not None:
                for category in categories:
                    print(category.actual_value)
                    print(category.display_value)
            print(customview_ins.is_off_line)
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Get a Layout of a Module

# Get single module layout
# ------------------------
def get_layout(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Accounts')# Module API Name
        resp = module_ins.get_layout(3477061000)# Layout id
        print(resp.status_code)
        layout_ins_arr = [resp.data]
        for layout_ins in layout_ins_arr:
            print("\n\n:::LAYOUT DETAILS:::")
            print(layout_ins.name)
            print(layout_ins.id)
            print(layout_ins.created_time)
            print(layout_ins.modified_time)
            print(layout_ins.convert_mapping)
            print(layout_ins.is_visible)
            modified_by = layout_ins.modified_by
            if modified_by is not None:
                print(modified_by.id)
                print(modified_by.name)
            profiles = layout_ins.accessible_profiles
            if profiles is not None:
                for profile in profiles:
                    print("\n\n")
                    print(profile.id)
                    print(profile.name)
                    print(profile.is_default)
            print(layout_ins.created_by)
            sections = layout_ins.sections
            if sections is not None:
                print("\n:::SECTION DETAILS:::")
                for secton in sections:
                    print(secton.name)
                    print(secton.display_name)
                    print(secton.column_count)
                    print(secton.sequence_number)
                    fields = secton.fields
                    if fields is not None:
                        print("\n:::FIELD DETAILS:::")
                        for field_ins in fields:
                            print(field_ins.api_name)
                            print(field_ins.id)
                            print(field_ins.is_custom_field)
                            lookup_field = field_ins.lookup_field
                            if lookup_field is not None:
                                print(lookup_field.id)
                                print(lookup_field.api_name)
                                print(lookup_field.display_label)
                                print(lookup_field.module)
                            print(field_ins.convert_mapping)
                            print(field_ins.is_visible)
                            print(field_ins.field_label)
                            print(field_ins.length)
                            print(field_ins.created_source)
                            print(field_ins.default_value)
                            print(field_ins.is_mandatory)
                            print(field_ins.sequence_number)
                            print(field_ins.is_read_only)
                            print(field_ins.is_unique_field)
                            print(field_ins.is_case_sensitive)
                            print(field_ins.data_type)
                            print(field_ins.is_formula_field)
                            print(field_ins.is_currency_field)
                            picklist_values = field_ins.picklist_values
                            if picklist_values is not None:
                                for picklist_value_ins in picklist_values:
                                    print(picklist_value_ins.display_value)
                                    print(picklist_value_ins.actual_value)
                                    print(picklist_value_ins.sequence_number)
                                    print(picklist_value_ins.maps)
                            print(field_ins.is_auto_number)
                            print(field_ins.is_business_card_supported)
                            print(field_ins.field_layout_permissions)
                            print(field_ins.decimal_place)
                            print(field_ins.precision)
                            print(field_ins.rounding_option)
                            print(field_ins.formula_return_type)
                            print(field_ins.formula_expression)
                            print(field_ins.prefix)
                            print(field_ins.suffix)
                            print(field_ins.start_number)
                            print(field_ins.json_type)
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Get a Custom View of a Module

# Get single customview details
# -----------------------------
def get_customview(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Accounts')# Module API Name
        resp = module_ins.get_customview(347706100000)# customview id
        print(resp.status_code)
        cv_ins_arr = [resp.data]
        for customview_ins in cv_ins_arr:
            print("\n\n:::CUSTOM VIEW DETAILS:::")
            print(customview_ins.id)
            print(customview_ins.module_api_name)
            print(customview_ins.display_value)
            print(customview_ins.is_default)
            print(customview_ins.name)
            print(customview_ins.system_name)
            print(customview_ins.sort_by)
            print(customview_ins.category)
            fields = customview_ins.fields
            print("\n:::FIELDS:::")
            for field in fields:
                print(field)
            print(customview_ins.favorite)
            print(customview_ins.sort_order)
            cv_criteria = customview_ins.criteria
            if cv_criteria is not None:
                print("\n\n :::CRITERIA::::")
                for criteria_ins in cv_criteria:
                    print(criteria_ins.field)
                    print(criteria_ins.comparator)
                    print(criteria_ins.value)
                print(customview_ins.criteria_pattern)
            categories = customview_ins.categories
            print("\n\n :::CATEGORIES::::")
            if categories is not None:
                for category in categories:
                    print(category.actual_value)
                    print(category.display_value)
            print(customview_ins.is_off_line)
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Update Module settings

# Update module setting
# ---------------------
def update_module_settings(self):
    try:
        module_instance = zcrmsdk.ZCRMModule.get_instance('Accounts') # module api name
        module_instance.per_page = 30
        module_instance.business_card_fields = ['Employees', 'Phone']
        module_instance.default_custom_view = zcrmsdk.ZCRMCustomView.get_instance(347706100000,'Accounts') # custom view id and module api name
        module_instance.default_territory_id = 13865860000011  # territory id
        resp = module_instance.update_module_settings()
        print(resp.status_code)
        print(resp.message)
        print(resp.code)
        print(resp.status)
        print(resp.details)
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Records
Get List of Records

def get_records(self):
	try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Accounts')  # Module API Name
        # resp = module_ins.get_records()
        # resp = module_ins.get_records(347706100000008) # custom view id
        # resp = module_ins.get_records(None, 'Account_Name') # Sort_by field(Field API Name)
        # resp = module_ins.get_records(None, None, 'asc') # Sort_order(asc/desc)
        # resp = module_ins.get_records(None, None, None, 0, 3)  # start index and end index
        # resp= module_ins.get_records(347706100000008, 'Account_Name', 'asc', 0, 2) # custom view id, Sort_by field(Field API Name), Sort_order(asc/desc) and start index and end index
        request_headers = dict()
        request_headers['If-Modified-Since'] = '2019-10-10T10:10:10+05:30'
        resp = module_ins.get_records(custom_headers=request_headers) #Adding custom headers
        print(resp.status_code)
        record_ins_arr = resp.data  # list of ZCRMRecord instance
        for record_ins in record_ins_arr:
            print(record_ins.entity_id)
            print(record_ins.created_by.id)
            print(record_ins.modified_by.id)
            print(record_ins.owner.id)
            print(record_ins.created_by.name)
            print(record_ins.created_time)
            print(record_ins.modified_time)
            print(record_ins.get_field_value('Email'))  # To get particular field value
            if record_ins.line_items is not None:
                for line_item in record_ins.line_items:
                    print("::::::LINE ITEM DETAILS::::::")
                    print(line_item.id)
                    print(line_item.product.lookup_label)
                    print(line_item.product.get_field_value('Product_Code'))
                    print(line_item.product.entity_id)
                    print(line_item.list_price)
                    print(line_item.quantity)
                    print(line_item.description)
                    print(line_item.total)
                    print(line_item.discount)
                    print(line_item.discount_percentage)
                    print(line_item.total_after_discount)
                    print(line_item.tax_amount)
                    print(line_item.net_total)
                    print(line_item.delete_flag)
                    if line_item.line_tax is not None:
                        for tax in line_item.line_tax:
                            print(":::::: TAX DETAILS ::::::")
                            print(tax.name)
                            print(tax.value)
                            print(tax.percentage)
            product_data = record_ins.field_data
            for key in product_data:
                print(key + ":" + str(product_data[key]))
            print("\n\n")
	except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)
        print(ex.error_message)
        print(ex.error_code)
        print(ex.error_details)
        print(ex.error_content)
 
Insert Records

# Create Records
# --------------
def create_records(self):
    try:
        record_ins_list = list()
        for i in range(0, 2):
            record = zcrmsdk.ZCRMRecord.get_instance('Invoices')# Module API Name
            record.set_field_value('Subject', 'Invoice' + str(i)) #This method use to set FieldApiName and value similar to all other FieldApis and Custom field 
            record.set_field_value('Account_Name', 'account_name')
            record.set_field_value('Price_Book_Name','book_name')
            record.set_field_value('Pricing_Model', 'Flat')
            record.set_field_value('Event_Title','Title')
            record.set_field_value('Start_DateTime','2018-09-04T15:52:21+05:30')
            record.set_field_value('End_DateTime','2019-01-04T15:52:21+05:30')
            record.set_field_value('Product_Name','product_name1')
            user = zcrmsdk.ZCRMUser.get_instance(3477061000, 'Owner name') # user id and user name
            record.set_field_value('Owner', user)
            
            # Following methods are being used only by Inventory modules
            taxIns = zcrmsdk.ZCRMTax.get_instance("Vat")

            record.tax_list.append(taxIns)

            pricing = zcrmsdk.ZCRMPriceBookPricing(None)
            pricing.to_range = 5
            pricing.from_range = 1
            pricing.discount = 0
            record.price_details.append(pricing)

            pricing = zcrmsdk.ZCRMPriceBookPricing(None)
            pricing.to_range = 11
            pricing.from_range = 6
            pricing.discount = 1
            record.price_details.append(pricing)

            pricing = zcrmsdk.ZCRMPriceBookPricing(None)
            pricing.to_range = 17
            pricing.from_range = 12
            pricing.discount = 2
            record.price_details.append(pricing)

            # participants = zcrmsdk.ZCRMEventParticipant(3477061000000,'contact') # Contacts record id and participant type
            # record.participants.append(participants)

            # participants = zcrmsdk.ZCRMEventParticipant('usermail@domain.com', 'email')
            # participants.email = 'usermail@domain.com'
            # participants.name = 'username'
            # participants.is_invited = 'true'
            # record.participants.append(participants)

            line_item = zcrmsdk.ZCRMInventoryLineItem.get_instance(zcrmsdk.ZCRMRecord.get_instance('Products', 347706100)) # module api name and record id
            line_item.discount = 10
            line_item.list_price = 8
            line_item.description = 'Product Description'
            line_item.quantity = 100
            line_item.tax_amount = 2.5
            taxIns = zcrmsdk.ZCRMTax.get_instance("Vat")
            taxIns.percentage = 5
            line_item.line_tax.append(taxIns)
            record.add_line_item(line_item)

            line_tax = []
            line_tax_row1 = {}
            line_tax_row1['percentage'] = 12.5
            line_tax_row1['name'] = 'Sales Tax'
            line_tax.append(line_tax_row1)
            line_tax_row2 = {}
            line_tax_row2['percentage'] = 8.5
            line_tax_row2['name'] = 'Common Tax'
            line_tax.append(line_tax_row2)

            record.set_field_value('$line_tax', line_tax)
            record_ins_list.append(record)

        resp = zcrmsdk.ZCRMModule.get_instance('Invoices').create_records(record_ins_list)
        print(resp.status_code)
        entity_responses = resp.bulk_entity_response
        for entity_response in entity_responses:
            print(entity_response.details)
            print(entity_response.status)
            print(entity_response.message)
            print(entity_response.data.entity_id)
            print(entity_response.data.created_by.id)
            print(entity_response.data.created_time)
            print(entity_response.data.modified_by.id)
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Update Records

# update Records
# --------------
def update_records(self):
    try:
        record_ins_list = list()
        record = zcrmsdk.ZCRMRecord.get_instance('Invoices')  # Module API Name
        record.set_field_value('id', 3477061000002) # record id
        record.set_field_value('Subject', 'Invoice')  # This method use to set FieldApiName and value similar to all other FieldApis and Custom field
        record.set_field_value('Account_Name', 'account_name')
        record.set_field_value('Price_Book_Name', 'book_name')
        record.set_field_value('Pricing_Model', 'Flat')
        record.set_field_value('Event_Title', 'Title')
        record.set_field_value('Start_DateTime', '2018-09-04T15:52:21+05:30')
        record.set_field_value('End_DateTime', '2019-01-04T15:52:21+05:30')
        record.set_field_value('Product_Name', 'product_name1')
        user = zcrmsdk.ZCRMUser.get_instance(347706100001, 'Owner name')  # user id and user name
        record.set_field_value('Owner', user)

        # Following methods are being used only by Inventory modules
        taxIns = zcrmsdk.ZCRMTax.get_instance("Vat")

        record.tax_list.append(taxIns)

        pricing = zcrmsdk.ZCRMPriceBookPricing(None)
        pricing.to_range = 5
        pricing.from_range = 1
        pricing.discount = 0
        record.price_details.append(pricing)

        pricing = zcrmsdk.ZCRMPriceBookPricing(None)
        pricing.to_range = 11
        pricing.from_range = 6
        pricing.discount = 1
        record.price_details.append(pricing)

        pricing = zcrmsdk.ZCRMPriceBookPricing(None)
        pricing.to_range = 17
        pricing.from_range = 12
        pricing.discount = 2
        record.price_details.append(pricing)

        # participants = zcrmsdk.ZCRMEventParticipant(3477061000000,'contact')  # Contacts record id and participant type
        # record.participants.append(participants)

        # participants = zcrmsdk.ZCRMEventParticipant('usermail@domain.com', 'email')
        # participants.email = 'usermail@domain.com'
        # participants.name = 'username'
        # participants.is_invited = 'true'
        # record.participants.append(participants)

        line_item = zcrmsdk.ZCRMInventoryLineItem.get_instance(zcrmsdk.ZCRMRecord.get_instance('Products', 347706100001))  # module api name and record id
        line_item.discount = 10
        line_item.list_price = 8
        line_item.description = 'Product Description'
        line_item.quantity = 100
        line_item.tax_amount = 2.5
        taxIns = zcrmsdk.ZCRMTax.get_instance("Vat")
        taxIns.percentage = 5
        line_item.line_tax.append(taxIns)
        record.add_line_item(line_item)

        line_tax = []
        line_tax_row1 = {}
        line_tax_row1['percentage'] = 12.5
        line_tax_row1['name'] = 'Sales Tax'
        line_tax.append(line_tax_row1)
        line_tax_row2 = {}
        line_tax_row2['percentage'] = 8.5
        line_tax_row2['name'] = 'Common Tax'
        line_tax.append(line_tax_row2)

        record.set_field_value('$line_tax', line_tax)
        record_ins_list.append(record)

        resp = zcrmsdk.ZCRMModule.get_instance('Invoices').update_records(record_ins_list)
        print(resp.status_code)
        entity_responses = resp.bulk_entity_response
        for entity_response in entity_responses:
            print(entity_response.details)
            print(entity_response.status)
            print(entity_response.message)
            print(entity_response.data.entity_id)
            print(entity_response.data.created_by.id)
            print(entity_response.data.created_time)
            print(entity_response.data.modified_by.id)
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Upsert Records (Insert/Update)

def upsert_records(self):
    try:
        record_ins_list = list()
        for i in range(0, 2):
            record = zcrmsdk.ZCRMRecord.get_instance('Invoices')
            record.set_field_value('Subject', 'Invoice' + str(i))
            record.set_field_value('Account_Name', 'IIIT')
            user = zcrmsdk.ZCRMUser.get_instance(34770610000, 'username') # user id and name
            record.set_field_value('Owner', user)
            line_item = zcrmsdk.ZCRMInventoryLineItem.get_instance(zcrmsdk.ZCRMRecord.get_instance("Products", 3477061000000)) # module api name and rescord id
            line_item.discount = 10
            line_item.list_price = 8
            line_item.description = 'Product Description'
            line_item.quantity = 100
            line_item.tax_amount = 2.5
            taxIns = zcrmsdk.ZCRMTax.get_instance("Vat")
            taxIns.percentage = 5
            line_item.line_tax.append(taxIns)
            record.add_line_item(line_item)
            record_ins_list.append(record)
        record = zcrmsdk.ZCRMRecord.get_instance('Invoices', 347706100000) # module api name and rescord id
        record.set_field_value('Subject', 'Invoice1.1')
        line_item = zcrmsdk.ZCRMInventoryLineItem.get_instance(zcrmsdk.ZCRMRecord.get_instance("Products", 347706100000)) # module api name and rescord id
        line_item.discount = 10
        line_item.list_price = 8
        line_item.description = 'Product Description'
        line_item.quantity = 100
        line_item.tax_amount = 2.5
        taxIns = zcrmsdk.ZCRMTax.get_instance("Vat")
        taxIns.percentage = 5
        line_item.line_tax.append(taxIns)
        record.add_line_item(line_item)
        record_ins_list.append(record)
        duplicate_check_fields=list()
        duplicate_check_fields.append("{any_unique_field}")
        duplicate_check_fields.append("{any_unique_field2}") #for more than one field append again
        resp = zcrmsdk.ZCRMModule.get_instance('Invoices').upsert_records(record_ins_list,duplicate_check_fields)
        print(resp.status_code)
        entity_responses = resp.bulk_entity_response
        for entity_response in entity_responses:
            print(entity_response.details)
            print(entity_response.status)
            print(entity_response.message)
            print(entity_response.code)
            print(entity_response.data.entity_id)
            print(entity_response.data.created_by.id)
            print(entity_response.data.created_time)
            print(entity_response.data.modified_by.id)
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Delete Records

# Delete Records
# --------------
def delete_records(self):
    try:
        entityid_list = [347706100000031, 3477061000000311] # record id
        resp = zcrmsdk.ZCRMModule.get_instance('Invoices').delete_records(entityid_list) #To call the delete record method
        print(resp.status_code)
        entity_responses = resp.bulk_entity_response
        for entity_response in entity_responses:
            print(entity_response.details)
            print(entity_response.status)
            print(entity_response.message)
            print(entity_response.code)
            print(entity_response.data.entity_id)
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Mass Update Records

# Mass update records
# -------------------
def mass_update_records(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Invoices') # Module API Name
        entityid_list = [3477061000003, 3477061000002] # record Id
        bulk_resp = module_ins.mass_update_records(entityid_list, 'Status', 'Created') #To call the update record method
        print(bulk_resp.status_code)
        entity_responses = bulk_resp.bulk_entity_response
        for entity_response in entity_responses:
            print(entity_response.details)
            print(entity_response.status)
            print(entity_response.message)
            print(entity_response.code)
            print(entity_response.data.entity_id)
            print(entity_response.data.created_by.id)
            print(entity_response.data.created_time)
            print(entity_response.data.modified_by.id)
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Get List of Deleted Records

# Get list of deleted records
# ---------------------------
def get_deleted_records(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Invoices') # Module API Name
        resp = module_ins.get_all_deleted_records() # To call the delete record method
        print(resp.status_code)
        trash_record_ins_arr = resp.data
        resp_info = resp.info
        print(resp_info.count)
        print(resp_info.page)
        print(resp_info.per_page)
        print(resp_info.is_more_records)
        for record_ins in trash_record_ins_arr:
            print(record_ins.id)
            print(record_ins.type)
            print(record_ins.display_name)
            if record_ins.created_by is not None:
                print(record_ins.created_by.id)
            if record_ins.deleted_by is not None:
                print(record_ins.deleted_by.id)
            print(record_ins.deleted_time)
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Get List of Recycle Bin Records

# Get list of recycle bin records
# -------------------------------
def get_recyclebin_records(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Invoices')
        resp = module_ins.get_recyclebin_records()
        print(resp.status_code)
        trash_record_ins_arr = resp.data
        resp_info = resp.info
        print(resp_info.count)
        print(resp_info.page)
        print(resp_info.per_page)
        print(resp_info.is_more_records)
        for record_ins in trash_record_ins_arr:
            print(record_ins.id)
            print(record_ins.type)
            print(record_ins.display_name)
            if record_ins.created_by is not None:
                print(record_ins.created_by.id)
            if record_ins.deleted_by is not None:
                print(record_ins.deleted_by.id)
            print(record_ins.deleted_time)
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Get List of Permanently Deleted Records

# Get list of permanently deleted records
# ---------------------------------------
def get_permanently_deleted_records(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Invoices') # Module API Name
        resp = module_ins.get_permanently_deleted_records()
        print(resp.status_code)
        trash_record_ins_arr = resp.data
        resp_info = resp.info
        print(resp_info.count)
        print(resp_info.page)
        print(resp_info.per_page)
        print(resp_info.is_more_records)
        for record_ins in trash_record_ins_arr:
            print(record_ins.id)
            print(record_ins.type)
            print(record_ins.display_name)
            if record_ins.created_by is not None:
                print(record_ins.created_by.id)
            if record_ins.deleted_by is not None:
                print(record_ins.deleted_by.id)
            print(record_ins.deleted_time)
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Search Records
Search Records by Word(Text)

# Search by Word
# --------------
def search_records(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Invoices')
        resp = module_ins.search_records('(SearchWord)')
        print(resp.status_code)
        resp_info = resp.info
        print(resp_info.count)
        print(resp_info.page)
        print(resp_info.per_page)
        print(resp_info.is_more_records)
        record_ins_arr = resp.data
        for record_ins in record_ins_arr:
            print(record_ins.entity_id)
            print(record_ins.created_by.id)
            print(record_ins.modified_by.id)
            print(record_ins.owner.id)
            print(record_ins.created_by.name)
            print(record_ins.created_time)
            print(record_ins.modified_time)
            print(record_ins.get_field_value('Email'))  # To get particular field value
            # Following methods are being used only by Inventory modules
            if record_ins.line_items is not None:
                for line_item in record_ins.line_items:
                    print("::::::LINE ITEM DETAILS::::::")
                    print(line_item.id)
                    print(line_item.product.lookup_label)
                    print(line_item.product.get_field_value('Product_Code'))
                    print(line_item.product.entity_id)
                    print(line_item.list_price)
                    print(line_item.quantity)
                    print(line_item.description)
                    print(line_item.total)
                    print(line_item.discount)
                    print(line_item.discount_percentage)
                    print(line_item.total_after_discount)
                    print(line_item.tax_amount)
                    print(line_item.net_total)
                    print(line_item.delete_flag)
                    if line_item.line_tax is not None:
                        for tax in line_item.line_tax:
                            print(":::::: TAX DETAILS ::::::")
                            print(tax.name)
                            print(tax.value)
                            print(tax.percentage)
            # End Inventory
            field_data_dict = record_ins.field_data
            for key in field_data_dict:
                print(key + ":" + str(field_data_dict[key]))
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Search Records by Phone

# Search by Phone
# ---------------
def search_records_by_phone(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Leads')
        resp = module_ins.search_records_by_phone('555-555-5555')
        print(resp.status_code)
        resp_info = resp.info
        print(resp_info.count)
        print(resp_info.page)
        print(resp_info.per_page)
        print(resp_info.is_more_records)
        record_ins_arr = resp.data
        for record_ins in record_ins_arr:
            print(record_ins.entity_id)
            print(record_ins.created_by.id)
            print(record_ins.modified_by.id)
            print(record_ins.owner.id)
            print(record_ins.created_by.name)
            print(record_ins.created_time)
            print(record_ins.modified_time)
            print(record_ins.get_field_value('Email'))  # To get particular field value
            # Following methods are being used only by Inventory modules
            if record_ins.line_items is not None:
                for line_item in record_ins.line_items:
                    print("::::::LINE ITEM DETAILS::::::")
                    print(line_item.id)
                    print(line_item.product.lookup_label)
                    print(line_item.product.get_field_value('Product_Code'))
                    print(line_item.product.entity_id)
                    print(line_item.list_price)
                    print(line_item.quantity)
                    print(line_item.description)
                    print(line_item.total)
                    print(line_item.discount)
                    print(line_item.discount_percentage)
                    print(line_item.total_after_discount)
                    print(line_item.tax_amount)
                    print(line_item.net_total)
                    print(line_item.delete_flag)
                    if line_item.line_tax is not None:
                        for tax in line_item.line_tax:
                            print(":::::: TAX DETAILS ::::::")
                            print(tax.name)
                            print(tax.value)
                            print(tax.percentage)
            # End Inventory
            field_data_dict = record_ins.field_data
            for key in field_data_dict:
                print(key + ":" + str(field_data_dict[key]))
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Search Records by Email

# Search by Email
# ---------------
def search_records_by_email(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Leads')
        resp = module_ins.search_records_by_email('email@domain.com')
        print(resp.status_code)
        resp_info = resp.info
        print(resp_info.count)
        print(resp_info.page)
        print(resp_info.per_page)
        print(resp_info.is_more_records)
        record_ins_arr = resp.data
        for record_ins in record_ins_arr:
            print(record_ins.entity_id)
            print(record_ins.created_by.id)
            print(record_ins.modified_by.id)
            print(record_ins.owner.id)
            print(record_ins.created_by.name)
            print(record_ins.created_time)
            print(record_ins.modified_time)
            print(record_ins.get_field_value('Email'))  # To get particular field value
            # Following methods are being used only by Inventory modules
            if record_ins.line_items is not None:
                for line_item in record_ins.line_items:
                    print("::::::LINE ITEM DETAILS::::::")
                    print(line_item.id)
                    print(line_item.product.lookup_label)
                    print(line_item.product.get_field_value('Product_Code'))
                    print(line_item.product.entity_id)
                    print(line_item.list_price)
                    print(line_item.quantity)
                    print(line_item.description)
                    print(line_item.total)
                    print(line_item.discount)
                    print(line_item.discount_percentage)
                    print(line_item.total_after_discount)
                    print(line_item.tax_amount)
                    print(line_item.net_total)
                    print(line_item.delete_flag)
                    if line_item.line_tax is not None:
                        for tax in line_item.line_tax:
                            print(":::::: TAX DETAILS ::::::")
                            print(tax.name)
                            print(tax.value)
                            print(tax.percentage)
            # End Inventory
            field_data_dict = record_ins.field_data
            for key in field_data_dict:
                print(key + ":" + str(field_data_dict[key]))
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
 
Search Records by Criteria

# Search by Criteria
# ------------------
def search_records_by_criteria(self):
    try:
        module_ins = zcrmsdk.ZCRMModule.get_instance('Invoices')
        resp = module_ins.search_records_by_criteria('((Subject:starts_with:<Search Value>) and (Status:equals:<Status Value>))')
        print(resp.status_code)
        resp_info = resp.info
        print(resp_info.count)
        print(resp_info.page)
        print(resp_info.per_page)
        print(resp_info.is_more_records)
        record_ins_arr = resp.data
        for record_ins in record_ins_arr:
            print(record_ins.entity_id)
            print(record_ins.created_by.id)
            print(record_ins.modified_by.id)
            print(record_ins.owner.id)
            print(record_ins.created_by.name)
            print(record_ins.created_time)
            print(record_ins.modified_time)
            print(record_ins.get_field_value('Email'))  # To get particular field value
            # Following methods are being used only by Inventory modules
            if record_ins.line_items is not None:
                for line_item in record_ins.line_items:
                    print("::::::LINE ITEM DETAILS::::::")
                    print(line_item.id)
                    print(line_item.product.lookup_label)
                    print(line_item.product.get_field_value('Product_Code'))
                    print(line_item.product.entity_id)
                    print(line_item.list_price)
                    print(line_item.quantity)
                    print(line_item.description)
                    print(line_item.total)
                    print(line_item.discount)
                    print(line_item.discount_percentage)
                    print(line_item.total_after_discount)
                    print(line_item.tax_amount)
                    print(line_item.net_total)
                    print(line_item.delete_flag)
                    if line_item.line_tax is not None:
                        for tax in line_item.line_tax:
                            print(":::::: TAX DETAILS ::::::")
                            print(tax.name)
                            print(tax.value)
                            print(tax.percentage)
            # End Inventory
            field_data_dict = record_ins.field_data
            for key in field_data_dict:
                print(key + ":" + str(field_data_dict[key]))
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)  
        print(ex.error_message) 
        print(ex.error_code) 
        print(ex.error_details) 
        print(ex.error_content) 
Tags
Get Tags

def get_tags(self):
        try:
            resp=ZCRMModule.get_instance('Leads').get_tags()
            print (resp.status_code)
            tag_ins_array = resp.data
            for tag_ins in tag_ins_array:
                print (tag_ins.id)
                print (tag_ins.name)
                print (tag_ins.created_by.id)
                print(tag_ins.created_by.name)
                print (tag_ins.modified_by.id)
                print(tag_ins.created_by.id)
                print (tag_ins.created_time)
                print (tag_ins.modified_time)

        except ZCRMException as ex:
            print (ex.status_code)
            print (ex.error_message)
            print (ex.error_code)
            print (ex.error_details)
            print (ex.error_content)
Get Tag Count

def get_tag_count(self):
	try:
    	resp=ZCRMModule.get_instance('Leads').get_tag_count('3524033000002965001')
       	print (resp.status_code)
        tag_ins = resp.data
        print (tag_ins.count)

    except ZCRMException as ex:
            print (ex.status_code)
            print (ex.error_message)
            print (ex.error_code)
            print (ex.error_details)
            print (ex.error_content)
Create Tags

def create_tags(self):
        try:
            tag_ins_array = []
            tag1 = ZCRMTag.get_instance(None, 'asdasdsdasdsadsd')
            tag2 = ZCRMTag.get_instance(None, 'dsdasasdssddadsdasd')
            tag_ins_array.append(tag1)
            tag_ins_array.append(tag2)
            resp = ZCRMModule.get_instance('Leads').create_tags(tag_ins_array)
            print(resp.status_code)
            tag_created = resp.data
            entity_responses = resp.bulk_entity_response
            for entity_response in entity_responses:
                print (entity_response.details)
                print (entity_response.status)
                print (entity_response.message)
                print (entity_response.code)
            for tag_ins in tag_created:
                print(tag_ins.id)
                print(tag_ins.name)
                print(tag_ins.created_by.id)
                print(tag_ins.created_by.name)
                print(tag_ins.modified_by.id)
                print(tag_ins.created_by.id)
                print(tag_ins.created_time)
                print(tag_ins.modified_time)

        except ZCRMException as ex:
            print(ex.status_code)
            print(ex.error_message)
            print(ex.error_code)
            print(ex.error_details)
            print(ex.error_content)
Update Tags

def update_tags(self):
        try:
            tag_ins_array = []
            tag1 = ZCRMTag.get_instance('3524033000002967011', '21')
            tag2 = ZCRMTag.get_instance('3524033000002967012', '312')
            tag_ins_array.append(tag1)
            tag_ins_array.append(tag2)
            resp = ZCRMModule.get_instance('Leads').update_tags(tag_ins_array)
            print(resp.status_code)
            tag_created = resp.data
            for tag_ins in tag_created:
                print(tag_ins.id)
                print(tag_ins.name)
                print(tag_ins.created_by.id)
                print(tag_ins.created_by.name)
                print(tag_ins.modified_by.id)
                print(tag_ins.created_by.id)
                print(tag_ins.created_time)
                print(tag_ins.modified_time)
            entity_responses = resp.bulk_entity_response
            for entity_response in entity_responses:
                print(entity_response.details)
                print(entity_response.status)
                print(entity_response.message)
                print(entity_response.code)
        except ZCRMException as ex:
            print(ex.status_code)
            print(ex.error_message)
            print(ex.error_code)
            print(ex.error_details)
            print(ex.error_content)
Add Tags to Multiple Records

def add_tags_to_multiple_records(self):
	try:
		tag_names=['tag2', 'tag3']
		record_ids=['3524033000002935002', '3524033000002930006']
		resp = ZCRMModule.get_instance('Leads').add_tags_to_multiple_records(tag_names, record_ids)
		entity_responses = resp.bulk_entity_response
		for entity_response in entity_responses:
			print(entity_response.details)
		print(entity_response.status)
		print(entity_response.message)
		print(entity_response.code)
		print (entity_response.data.entity_id)
		for tag in entity_response.data.tag_list:
			print(tag.name)
	except ZCRMException as ex:
		print(ex.status_code)
		print(ex.error_message)
		print(ex.error_code)
		print(ex.error_details)
		print(ex.error_content)
Remove Tags from Multiple Records

def remove_tags_from_multiple_records(self):
   try:
        tag_names=['tag2', 'tag3']
        record_ids=['3524033000002935002', '3524033000002930006']
        resp = ZCRMModule.get_instance("Leads").remove_tags_from_multiple_records(tag_names, record_ids)
        entity_responses = resp.bulk_entity_response
        for entity_response in entity_responses:
            print(entity_response.details)
            print(entity_response.status)
            print(entity_response.message)
            print(entity_response.code)
            print (entity_response.data.entity_id)
            for tag in entity_response.data.tag_list:
                print (tag.name)
    except ZCRMException as ex:
		print(ex.status_code)
		print(ex.error_message)
		print(ex.error_code)
		print(ex.error_details)
		print(ex.error_content)