In this article, we will learn how to update a purchase order in Quickbooks online from .NET MVC web application using SDK.
Before using any Quickbooks online API we need access token, if you don’t know how to get access token then you can find it here.
public ActionResult UpdatePurchaseOrder() { try { OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(Access_token); // Create a ServiceContext with Auth tokens and realmId ServiceContext serviceContext = new ServiceContext(RealmId, IntuitServicesType.QBO, oauthValidator); serviceContext.IppConfiguration.MinorVersion.Qbo = "23"; serviceContext.IppConfiguration.BaseUrl.Qbo = QboBaseUrl; string EXISTING_PURCHASEORDER_QUERYBYID = string.Format("select * from PurchaseOrder where id = '{0}'", "155"); var queryService = new QueryService<PurchaseOrder>(serviceContext); PurchaseOrder objPurchaseOrderFound = queryService.ExecuteIdsQuery(EXISTING_PURCHASEORDER_QUERYBYID).FirstOrDefault<PurchaseOrder>(); //If Purchase Order found on Quickbooks online if (objPurchaseOrderFound != null) { PurchaseOrder ObjPurchaseOrder = new PurchaseOrder(); ObjPurchaseOrder.Id = objPurchaseOrderFound.Id; ObjPurchaseOrder.SyncToken = objPurchaseOrderFound.SyncToken; ObjPurchaseOrder.APAccountRef = new ReferenceType(); ObjPurchaseOrder.APAccountRef = objPurchaseOrderFound.APAccountRef; ObjPurchaseOrder.VendorRef = new ReferenceType(); ObjPurchaseOrder.VendorRef = objPurchaseOrderFound.VendorRef; List<Line> LineList = new List<Line>(); for (int i = 0; i < objPurchaseOrderFound.Line.Count(); i++) { if (objPurchaseOrderFound.Line[i].DetailType == LineDetailTypeEnum.ItemBasedExpenseLineDetail) { if (!objPurchaseOrderFound.Line[i].AmountSpecified) { objPurchaseOrderFound.Line[i].AmountSpecified = true; } objPurchaseOrderFound.Line[i].Amount = 200; objPurchaseOrderFound.Line[i].Description = "This is test description"; ItemBasedExpenseLineDetail itemLineDetail = new ItemBasedExpenseLineDetail(); itemLineDetail = (ItemBasedExpenseLineDetail)objPurchaseOrderFound.Line[i].AnyIntuitObject; if (!itemLineDetail.QtySpecified) { itemLineDetail.QtySpecified = true; } itemLineDetail.Qty = 2; objPurchaseOrderFound.Line[i].AnyIntuitObject = itemLineDetail; LineList.Add(objPurchaseOrderFound.Line[i]); } } ObjPurchaseOrder.Line = LineList.ToArray(); DataService dataService = new DataService(serviceContext); PurchaseOrder UpdateEntity = dataService.Update<PurchaseOrder>(ObjPurchaseOrder); if (UpdateEntity != null && !string.IsNullOrEmpty(UpdateEntity.Id)) { //you can write Database code here ViewBag.IsSuccess = true; } } return View(); } catch (IdsException ex) { ViewBag.IsSuccess = false; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { ViewBag.Message = ex.InnerException.Message; } else if (!string.IsNullOrEmpty(ex.Message)) { ViewBag.Message = ex.Message; } else { ViewBag.Message = "Something went wrong,IdsException occurs"; } return View(); } catch (Exception ex) { ViewBag.IsSuccess = false; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { ViewBag.Message = ex.InnerException.Message; } else if (!string.IsNullOrEmpty(ex.Message)) { ViewBag.Message = ex.Message; } else { ViewBag.Message = "Something went wrong,Exception occurs"; } return View(); } }
@{ ViewBag.Title = "UpdatePurchaseOrder"; } <h2>Update Purchase Order</h2> @if (ViewBag.IsSuccess != null && ViewBag.IsSuccess == true) { <div class="row"> <label class="label label-success"> Purchase Order Updated Successfully </label> </div> } else if (ViewBag.IsSuccess != null && ViewBag.IsSuccess == false) { <div class="row"> <label class="label label-danger">@ViewBag.Message</label> </div> }
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular