How To Create Purchase Order Using Zoho CRM In ASP.NET MVC


In this article, we will learn how to create a purchase order using Zoho CRM in ASP.NET MVC Web application.

Let’s begin

Please read this article first of all here.

If you have not seen How to Create Product using Zoho CRM then I recommend you to see that first. in that article, I described how to Create a Product using Zoho CRM.

C# Code Example

Open the HomeController.cs file and add the below code in it.

public void CreatePurchaseOrder()
     ZCRMModule moduleIns1 = ZCRMModule.GetInstance("products"); //module api name
     BulkAPIResponse<ZCRMRecord> response1 = moduleIns1.GetRecords();
     List<ZCRMRecord> relatedLists = response1.BulkData;
     ZCRMModule moduleInsAccounr = ZCRMModule.GetInstance("accounts"); //module api name
     BulkAPIResponse<ZCRMRecord> responseAccount = moduleInsAccounr.GetRecords();
     List<ZCRMRecord> relatedListsAccount = responseAccount.BulkData;
     List<ZCRMRecord> listRecord = new List<ZCRMRecord>();
     ZCRMRecord record;

     record = ZCRMRecord.GetInstance("Purchase_Orders", null); //To get ZCRMRecord instance
     record.SetFieldValue("Subject", "Invoice4"); //This method use to set FieldApiName and value similar to all other FieldApis and Custom field 
     record.SetFieldValue(relatedListsAccount[0].CreatedBy.FullName, relatedListsAccount[0].CreatedBy.Id);
     record.SetFieldValue("Company", "Your Company name");
     record.SetFieldValue("Last_Name", "Your last name");
     record.SetFieldValue("Customfield", "CustomFieldValue");
     record.SetFieldValue("Price_Book_Name", "Price_Book_Name");

    /** Following methods are being used only by Inventory modules */
     ZCRMPriceBookPricing pricing;

     pricing = new ZCRMPriceBookPricing
         ToRange = 5,
         FromRange = 1,
         Discount = 0

     pricing = new ZCRMPriceBookPricing
         ToRange = 11,
         FromRange = 6,
         Discount = 1

     pricing = new ZCRMPriceBookPricing
         ToRange = 17,
         FromRange = 12,
         Discount = 2

     pricing = new ZCRMPriceBookPricing
         ToRange = 23,
         FromRange = 18,
         Discount = 3

     record.SetFieldValue("Pricing_Model", "Flat");
     ZCRMTax linetax;
     linetax = ZCRMTax.GetInstance("Sales Tax");
     linetax.Percentage = 12.5;

     ZCRMRecord product = ZCRMRecord.GetInstance("Products", relatedLists[0].EntityId); // product instance
     ZCRMInventoryLineItem lineItem = new ZCRMInventoryLineItem(product); //To get ZCRMInventoryLineItem instance
     lineItem.Description = "Product_description"; //To set line item description
     lineItem.Discount = 5; //To set line item discount
     lineItem.ListPrice = 100; //To set line item list price

     ZCRMTax taxInstance1 = ZCRMTax.GetInstance("Sales Tax"); //To get ZCRMTax instance
     taxInstance1.Percentage = 2; //To set tax percentage
     taxInstance1.Value = 50; //To set tax value
     lineItem.AddLineTax(taxInstance1); //To set line tax to line item

     taxInstance1 = ZCRMTax.GetInstance("Vat");
     taxInstance1.Percentage = 12;
     taxInstance1.Value = 50;

     lineItem.Quantity = 100; //To set product quantity to this line item

     record.AddLineItem(lineItem); //The line item set to the record object
                                   /** End Inventory **/

     ZCRMModule moduleIns = ZCRMModule.GetInstance("Purchase_Orders");
     BulkAPIResponse<ZCRMRecord> responseIns = moduleIns.CreateRecords(listRecord); //To call the create record method

     Console.WriteLine("HTTP Status Code:" + responseIns.HttpStatusCode); //To get create record http response code


Get All Purchase Order Data

public void GetAllPurchaseOrderData()
     ZCRMModule moduleIns = ZCRMModule.GetInstance("Purchase_Orders"); //module api name
     BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords();
     List<ZCRMRecord> relatedLists = response.BulkData;


if you have any questions or issues about this article, please let me know and more details here


Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories