Here, we are going to explain the creation of custom SAP UI5 application using BOPF consumed OData service.

Pre-requisite– Please visit our previous blog posts for overview of the functionality and for the back-end creation.

Develop Draft Capable Custom Apps Using BOPF Framework – Part2

In this application, we have implemented the basic functionality like user can read/create/edit/delete the sales order header data along with durable locking and drafting functionality.

Let’s start the development of SAP UI5 custom application:

1.First step is to create destination in SAP Cloud Connector.

  • Login to the SAP Cloud connector.
  • Click on “Cloud to On-Premise” in SAP Cloud Connector and make an entry for the SAP system.

2.Next is to create destination in SAP cloud platform.

  • Login to the SAP Cloud Platform (Neo Trial account) -> Destinations -> Click on “New Destination” -> Make a new entry and Check the connection.
  • Connection should be reachable.

3.Then, open SAP WEB IDE Full Stack

  •  And Click on “File” -> New -> Project from template -> “SAP UI5 Application” template -> Next

Note: Click on “Service tab” and enable SAP WEB IDE Full Stack service if not enabled.

  • Enter Project Name and Namespace -> Click on “Next” then select View Type as XML and enter view name (HomePage) ->Click on “Finish”.

After this you can see the newly created project in files section.

4.Then right click on the project and add your OData service as displayed in the below picture.

 

  •  Choose system in “Service Catalog” and search for the OData service (ZC_SALESORDERSHEAD_CDS)->next->finish.

Now, the next step is screen/view designing.

In our homepage/first view, we have added a smart table to display sales order header details and on the table header itself, we have added buttons for create and delete. And on the click of line item of the table, we have given the edit functionality. RadioButton is used to enable delete button which means on the click of radiobutton, delete button will enable.

                                                 HOME PAGE SCREEN

1. HomePage:  View1.view.xml

Note: Please see the comments in the code for better understanding of the view functionality.

<mvc:View xmlns:smartFilterBar="sap.ui.comp.smartfilterbar" xmlns:smartTable="sap.ui.comp.smarttable"
	controllerName="ZCustDraftLockDemo.ZCustDraftLockDemo.controller.View1" xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m"
	xmlns:core="sap.ui.core">
	<Shell id="shell">
		<App id="app">
			<pages>
				<Page id="page" title=" Process Sales Order">
					<content>
						<!--Add smart table with entity set ZC_SalesOrdersHead -->
						<smartTable:SmartTable id="smartid" smartFilterId="smartFilterBar" beforeRebindTable="onBeforeRebindTable" editable="false"
							entitySet="ZC_SalesOrdersHead" tableType="ResponsiveTable" useVariantManagement="false" useExportToExcel="true"
							useTablePersonalisation="true" header="Sales Order List" placeToolbarInTable="true"
							initiallyVisibleFields="salesorder,businesspartner,overallstatus,createdat,createdby,changedat,changedby,auart,kunnr,vkgrp,vkorg,matnr,werks,DraftUUID,DraftEntityCreationDateTime,DraftEntityLastChangeDateTime"
							showRowCount="true" showFullScreenButton="true" demandPopin="true" enableAutoBinding="true" class="sapUiSmallMarginTop">
							<smartTable:customToolbar id="stickyToolbar" class="stickyToolbar">
								<!--Add delete,refresh,create button -->
								<OverflowToolbar design="Transparent">
									<ToolbarSpacer/>
									<Button icon="sap-icon://add" tooltip="Create" press="onCreate"/>
									<Button type="Transparent" press="onRefreshMlstBtnPress" icon="sap-icon://refresh" tooltip="Refresh"/>
									<Button id="idPersoButton" icon="sap-icon://delete" tooltip="Delete" press="onDelete" visible="false"/>
								</OverflowToolbar>
							</smartTable:customToolbar>
							<!--Add  table for fixed column headers while scrolling -->
							<Table id="table" growing="true" class="sapUiSizeCompact" mode="SingleSelectLeft" sticky="ColumnHeaders,HeaderToolbar"
								selectionChange="onTableSelectionChange" updateFinished="onUpdateFinished" growingScrollToLoad="true">
								<columns >
									<Column>
										<customData>
											<core:CustomData key="p13nData"
												value='{"columnKey": "salesorder", "leadingProperty": "salesorder", "sortProperty": "salesorder", "filterProperty": "salesorder", "columnIndex": 0}'/>
										</customData>
										<Text text="Sales document"></Text>
									</Column>
								</columns>
								<items>
									<ColumnListItem type="Active" press="pressed">
										<cells>
											<VBox>
												<Text text="{salesorder}" class="bold"/>
												<!--Add Draft status for salesorder -->
												<Text text="{parts: [ 'DraftUUID','salesorder'], formatter: '.formatter.statusText'}" class="blueTxtHlight"/>
											</VBox>
										</cells>
									</ColumnListItem>
								</items>
							</Table>
						</smartTable:SmartTable>
					</content>
					<footer>
						<OverflowToolbar>
							<VBox></VBox>
							<OverflowToolbarToggleButton/>
						</OverflowToolbar>
					</footer>
				</Page>
			</pages>
		</App>
	</Shell>
</mvc:View>

For edit and create functionality, we are loading fragments here.

2.  Edit Screenedit.fragment.xml

Note: ShareModel contains changes being done in Edit fragment.

<core:FragmentDefinition xmlns="sap.m" xmlns:f="sap.ui.layout.form" xmlns:core="sap.ui.core"
	controllerName="ZCustDraftLockDemo.ZCustDraftLockDemo.controller.View1">
	<Dialog title="Edit Sales Order" type="Message" contentWidth="30%">
		<VBox>
			<f:SimpleForm id="edit1" editable="true" layout="ResponsiveGridLayout" title="" labelSpanXL="4" labelSpanL="4" labelSpanM="12"
				labelSpanS="12" adjustLabelSpan="false" emptySpanXL="0" emptySpanL="0" emptySpanM="0" emptySpanS="0" columnsXL="2" columnsL="2" columnsM="1"
				singleContainerFullSize="false">
				<f:content>
					<Label text="Sales Order" labelFor="name" required="false"/>
					<Input value="{ShareModel>/salesorder}" placeholder=" Enter Business Partner ID" enabled="false"/>
					<Label text="Created on" labelFor="name" required="false"/>
					<Input value="{ShareModel>/createdat}" id="edit5" enabled="false"/>
					<Label text="Created by" labelFor="name" required="false"/>
					<Input value="{ShareModel>/createdby}" id="edit6" enabled="false"/>
					<Label text="Changed on" labelFor="name" required="false"/>
					<Input value="{ShareModel>/changedat}" id="edit7" enabled="false"/>
					<Label text="Changed by" labelFor="name" required="false"/>
					<Input value="{ShareModel>/changedby}" id="edit8" enabled="false"/>
					<Label text="Business Partner ID" labelFor="name" required="false"/>
					<Input value="{ShareModel>/businesspartner}" id="businesspartner" placeholder=" Enter Business Partner ID" liveChange="onchangeedit"
						required="true" maxLength="10"/>
					<Label text="Overall Status" labelFor="name"/>
					<Input value="{ShareModel>/overallstatus}" id="overallstatus" placeholder=" Enter status" required="true" liveChange="onchangeedit"
						maxLength="1"/>
					<Label text="Sales Document Type" labelFor="name"/>
					<Input value="{ShareModel>/auart}" id="auart" placeholder=" Enter sales document type" liveChange="onchangeedit" required="true"
						maxLength="4"/>
					<Label text="Sales Organisation" labelFor="name"/>
					<Input value="{ShareModel>/vkorg}" id="vkorg" placeholder=" Enter sales org." liveChange="onchangeedit" required="false" maxLength="4"/>
					<Label text="Sales Group" labelFor="name"/>
					<Input value="{ShareModel>/vkgrp}" id="vkgrp" placeholder=" Enter sales group" liveChange="onchangeedit" required="false" maxLength="3"/>
					<Label text="Cost Center" labelFor="name"/>
					<Input value="{ShareModel>/kostl}" id="kostl" placeholder=" Enter cost center" liveChange="onchangeedit" required="false" maxLength="10"/>
					<Label text="Sold To Party" labelFor="name"/>
					<Input value="{ShareModel>/kunnr}" id="kunnr" placeholder=" Enter sold to party" liveChange="onchangeedit" required="false" maxLength="10"/>
					<Label text="Material" labelFor="name"/>
					<Input value="{ShareModel>/matnr}" id="matnr" placeholder=" Enter material" liveChange="onchangeedit" required="false" maxLength="40"/>
					<Label text="Plant" labelFor="name"/>
					<Input value="{ShareModel>/werks}" id="werks" placeholder=" Enter plant name" liveChange="onchangeedit" required="false" maxLength="4"/>
					<HBox >
						<Button text="Save" press="onSubmit" class="sapUiSmallMargin"/>
						<Button id="cancel" text="Cancel" press="onClose" class="sapUiSmallMargin"/>
						<Button id="cancel1" text="Close" press="onCloseedit" class="sapUiSmallMargin"/>
					</HBox>
				</f:content>
			</f:SimpleForm>
		</VBox>
	</Dialog>
</core:FragmentDefinition>

3. Create Screen: create.fragment.xml

Note: CreateModel contains changes being made in create fragment

<core:FragmentDefinition xmlns="sap.m" xmlns:f="sap.ui.layout.form" xmlns:core="sap.ui.core"
	controllerName="ZCustDraftLockDemo.ZCustDraftLockDemo.controller.View1">
	<Dialog title="Create Sales Order" type="Message" contentWidth="30%">
		<VBox>
			<f:SimpleForm id="userReg1" editable="true" layout="ResponsiveGridLayout" title="" labelSpanXL="4" labelSpanL="4" labelSpanM="12"
				labelSpanS="12" adjustLabelSpan="false" emptySpanXL="0" emptySpanL="0" emptySpanM="0" emptySpanS="0" columnsXL="2" columnsL="2" columnsM="1"
				singleContainerFullSize="false">
				<f:content>
					<Label text="Overall Status" labelFor="name"/>
					<Input value="{CreateModel>/overallstatus}" id="overallstatus1" liveChange="onchangecreate" valueStateText="Maximum one character."
						placeholder=" Enter Status " required="true" maxLength="1"/>
					<Label text="Business Partner ID" labelFor="name" required="false"/>
					<Input value="{CreateModel>/businesspartner}" id="businesspartner1" liveChange="onchangecreate" placeholder=" Enter Business Partner ID"
						required="true" maxLength="10" valueStateText="Maximum 10 character."/>
					<Label text="Sales Document Type" labelFor="name"/>
					<Input value="{CreateModel>/auart}" id="auart1" liveChange="onchangecreate" placeholder=" Enter sales document type" maxLength="4"
						valueStateText="Maximum 4 character." required="true"/>
					<Label text="Sales Organisation" labelFor="name"/>
					<Input value="{CreateModel>/vkorg}" id="vkorg1" liveChange="onchangecreate" placeholder=" Enter sales org." maxLength="4" required="false"
						valueStateText="Maximum 4 character."/>
					<Label text="Sales Group" labelFor="name1"/>
					<Input value="{CreateModel>/vkgrp}" id="vkgrp1" liveChange="onchangecreate" placeholder=" Enter sales group" maxLength="3" required="false"
						valueStateText="Maximum 3 character."/>
					<Label text="Cost Center" labelFor="name"/>
					<Input value="{CreateModel>/kostl}" id="kostl1" liveChange="onchangecreate" placeholder=" Enter cost center" maxLength="10" required="false"/>
					<Label text="Sold To Party" labelFor="name"/>
					<Input value="{CreateModel>/kunnr}" id="kunnr1" liveChange="onchangecreate" placeholder=" Enter sold to party" maxLength="10"
						required="false"/>
					<Label text="Material" labelFor="name"/>
					<Input value="{CreateModel>/matnr}" id="matnr1" liveChange="onchangecreate" placeholder=" Enter material" maxLength="40" required="false"/>
					<Label text="Plant" labelFor="name"/>
					<Input value="{CreateModel>/werks}" id="werks1" liveChange="onchangecreate" placeholder=" Enter plant name" maxLength="4" required="false"
						valueStateText="Maximum 4 character."/>
					<HBox >
						<Button text="Create" press="onRegister" class="sapUiSmallMargin"/>
						<Button text="Cancel" id="createcancel" press="onexit" class="sapUiSmallMargin"/>
						<Button text="Close" id="createcancel1" press="onCloseCreate" class="sapUiSmallMargin"/>
					</HBox>
				</f:content>
			</f:SimpleForm>
		</VBox>
	</Dialog>
</core:FragmentDefinition>

Next, we had added a formatter file to set different kind of draft status to sales order.

4. Formatter.js

Here, statusText is a function which is used for setting draft status for sales order.

Types of draft status:

  • Draft
  • This object contains unsaved changes for user
  • This object is locked by user
sap.ui.define([], function () {
	"use strict";
	return {
		statusText: function (DraftUUID,salesorder) 
		{
	 if (DraftUUID !== "00000000-0000-0000-0000-000000000000")
	{
		return "Draft";
	}
	
	if(salesorder !== "")
	{
		var oModel1 = new sap.ui.model.json.JSONModel();
		oModel1.loadData("/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='"+salesorder+"',DraftUUID=guid'00000000-0000-0000-0000-000000000000',IsActiveEntity=true)?$expand=DraftAdministrativeData",null,false);
		
		if(oModel1.getData().d.DraftAdministrativeData !== null)
		{
	var flaglastchange = oModel1.getData().d.DraftAdministrativeData.DraftIsLastChangedByMe;
	var flagprocess = oModel1.getData().d.DraftAdministrativeData.DraftIsProcessedByMe;
	if (flaglastchange === false && flagprocess === false){
		var lockuser;
		if(oModel1.getData().d.DraftAdministrativeData.InProcessByUser === ""){
			lockuser = oModel1.getData().d.DraftAdministrativeData.LastChangedByUser;
	return "This object contains unsaved changes for user : " + lockuser;
		}
     	}	
	if(oModel1.getData().d.DraftAdministrativeData.InProcessByUser !== "")
	{
		lockuser = oModel1.getData().d.DraftAdministrativeData.InProcessByUser;
	    return "This object is locked by user : " + lockuser;
	}
	
		}
	}
		}
	};
});

style.css

/* Enter your custom styles here */
.blueTxtHlight {
color: #053b70 !important;
}
.bold{
font-weight: bold !important;	
}/* Enter your custom styles here */
.stickyToolbar {
    position: sticky;
    position: -webkit-sticky;
    top: 0;
    z-index: 101;
}

Controller

Main view controller:  View1.controller.js

Function used:

onCreate function

  • onCreate function is called on click of create button through View1.view.xml.
  • onCreate opens Create fragment as dialog.
  • Validation given for Input Fields in create.fragment.xml

onRegister Function

  • onRegister function gets called on click of Create Button through Create fragment.
  • Overall Status , Business Partner Id , Sales Document Type are mandatory when changes                  being saved on backend.
  • POST ZC_SalesOrdersHeadPreparation is called to create draft data.
  • POST ZC_SalesOrdersHeadActivation is called to convert draft to active data.

pressed function

  • Function get called at the click of table’s line item.
  • Here, we are setting cancel and discard button based on the draft created or not.
  • Edit.fragment.xml is opened as dialog.
  • checks if salesorder is not locked then error.
  • checks if salesorder has unsaved changes then warning.
  • else open edit.fragment.xml is opened as dialog.

onSubmit function

  • onSubmit function is called on click of Save Button through Edit Fragment.
  • Validation of mandatory fields at saving function ie Bussiness Partner ID,Overall Status,Sales            Document Type.
  • Error “Please do some changes to be saved” is given when no change is performed on click of save button.
  • POST ZC_SalesOrdersHeadPreparation is called to create draft data.
  • POST ZC_SalesOrdersHeadActivation is called to convert draft to active data.

onchangecreate function

  • onchangecreate is triggered on every live change in particular input fields in Create.fragment.xml

Input Fields:

  • Overall status
  • Business partner id
  • Sales Document Type
  • Sales Organisation
  • Sales Group
  • Cost Center
  • Sold To Party
  • Material
  • Plant

Here, both post and merge operations performed.

  • POST ZC_SalesOrdersHead
  • MERGE                          ZC_SalesOrdersHead(salesorder=’salesorderno’,DraftUUID=guid’xyz’,IsActiveEntity=false

xyz is draftguid.

Here, if draft is not created ,create a new draft and merge livechanges to newly created draft.

and if draft already exists ,merge livechanges to already to existing draft.

onDelete function

  • Delete function will be called on click of delete button in View1.
  • REMOVE ZC_SalesOrdersHead(salesorder=’salesorderno’,DraftUUID=guid’xyz’,IsActiveEntity=false is called;

Here, xyz is draftguid.

onchangeedit function

  • onchangeedit is called on every live change in particular input fields in edit.fragment.xml.

POST ZC_SalesOrdersHeadEdit is called

MERGE ZC_SalesOrdersHead(salesorder=’salesorderno’,DraftUUID=guid’xyz’,IsActiveEntity=false is called;

  • Here, xyz is draftguid .
  • if draft is not created ,create a new draft and merge livechanges to newly created draft.
  • if draft already exists ,merge livechanges to already to existing draft.

onTableSelectionChange function

  • on Line selection through radio button enable delete button on screen.

onClose function

  • Works for edit.fragment.xml
  • If draft exist then delete the draft record and close the dialog.

REMOVE ZC_SalesOrdersHead(salesorder=’salesorderno’,DraftUUID=guid’xyz’,IsActiveEntity=false is called;

xyz is draftguid here.

onBeforeRebindTable function

  • Filter applied on smart table

onRefreshMlstBtnPress function

  • Refresh smart table

Note: Please read comments for better vision for the below code.

sap.ui.define([
	"sap/ui/core/mvc/Controller",
	"sap/ui/core/Fragment",
	"sap/m/MessageBox",
	"../model/formatter"
], function (Controller, Fragment, MessageBox, formatter) {
	"use strict";

	return Controller.extend("ZCustDraftLockDemo.ZCustDraftLockDemo.controller.View1", {
		formatter: formatter,
		onInit: function () {
		},
       /*onRegister function is called on click of Create Button on Create Fragment*/
		onRegister: function (oEvent) {

			sap.ui.getCore().byId("createcancel").setText("Cancel");
			var tab = sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData();
		/*tab contains the CreateModel data of Create Fragment changes*/
		
		/*Overall Status , Business Partner Id , Sales Document Type are mandatory when changes being saved on backend*/
			if (tab.overallstatus === "") {
				MessageBox.error("Enter Overall status");
				sap.ui.getCore().byId("overallstatus1").setValueState(sap.ui.core.ValueState.Error);
				return false;
			} else {
				sap.ui.getCore().byId("overallstatus1").setValueState(sap.ui.core.ValueState.None);
			}

			if (tab.businesspartner === "") {

				MessageBox.error("Enter Business Partner Id");
				sap.ui.getCore().byId("businesspartner1").setValueState(sap.ui.core.ValueState.Error);

				return false;
			} else {
				sap.ui.getCore().byId("businesspartner1").setValueState(sap.ui.core.ValueState.None);

			}
			if (tab.auart === undefined) {
				MessageBox.error("Enter Sales Document Type");
				sap.ui.getCore().byId("auart1").setValueState(sap.ui.core.ValueState.Error);
				// this.setValueState(sap.ui.core.ValueState.Error);
				return false;

			} else {
				sap.ui.getCore().byId("auart1").setValueState(sap.ui.core.ValueState.None);

			}
			
		/*POST ZC_SalesOrdersHeadPreparation is called */	
			var oUrlParams = {
				salesorder: "",
				DraftUUID: tab.DraftUUID,
				IsActiveEntity: "false"
			};
			this.getView().getModel().callFunction("/ZC_SalesOrdersHeadPreparation", {
				method: "POST",
				urlParameters: oUrlParams,
				groupId: "batchUpdateGroup2",
				success: function (odata, Response) {
				},
				error: function (oError) {
					try {
						if (oError.responseText) {
							var obj;
							var message, message1;
							obj = JSON.parse(oError.responseText);
							message = obj.error.message.value;
						} else if (oError.response.body) {
							var errorModel = new sap.ui.model.xml.XMLModel();
							errorModel.setXML(oError.response.body);
							//Read message node
							if (errorModel.getProperty("/0/message") !== "") {
								message = errorModel.getProperty("/0/message");
							} else {
								message = message1;
							}
						} else {
							message = message1;
						}
					} catch (error) {
						message = message1;
					}
					sap.m.MessageToast.show(message);
				}
			});
             /*POST ZC_SalesOrdersHeadActivation is called*/
			this.getView().getModel().callFunction("/ZC_SalesOrdersHeadActivation", {
				method: "POST",
				urlParameters: oUrlParams,
				groupId: "batchUpdateGroup2",
				success: function (odata, Response) {

					if (odata !== "" || odata !== undefined) {
						MessageBox.success("Sales Document  " + odata.salesorder + " has been created");
					} else {
						MessageBox.error("Not able to create");
					}

				},
				error: function (oError) {
					try {
						if (oError.responseText) {
							var obj;
							var message, message1;
							obj = JSON.parse(oError.responseText);
							message = obj.error.message.value;
						} else if (oError.response.body) {
							var errorModel = new sap.ui.model.xml.XMLModel();
							errorModel.setXML(oError.response.body);
							//Read message node
							if (errorModel.getProperty("/0/message") !== "") {
								message = errorModel.getProperty("/0/message");
							} else {
								message = message1;
							}
						} else {
							message = message1;
						}
					} catch (error) {
						message = message1;
					}
					sap.m.MessageToast.show(message);
				}
			});

			this._oDialog1.close();

		},
		
		/*onSubmit function is called on click of Save Button on Edit Fragment*/
		onSubmit: function (oEvent) {
			
			//validation of mandatory fields at saving function ie Bussiness Partner ID,Overall Status,Sales Document Type
			var validatebusinesspartner = sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().businesspartner;
			var validateoverallstatus = sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().overallstatus;
			var validateaurat = sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().aurat;
			if ((validatebusinesspartner === "") || (validateoverallstatus === "") || (validateaurat === "")) {
				sap.m.MessageBox.error("Enter Mandatory fields for updatig sales order");
			} else {
				sap.ui.getCore().byId("cancel").setText("Cancel");

				var tab = sap.ui.getCore().byId("edit1").getModel("ShareModel").getData();
			    /*Error is given when no change is performed on click of save button*/
				if (tab.DraftUUID === "00000000-0000-0000-0000-000000000000") {
					MessageBox.error("Please do some changes to be saved");
					this._oDialog3.open();
				}
				
				
				/*POST ZC_SalesOrdersHeadPreparation is called */
				var vDraftID = tab.DraftUUID;
				var oUrlParams = {
					salesorder: tab.salesorder,
					DraftUUID: vDraftID,
					IsActiveEntity: "false"
				};

				this.getView().getModel().callFunction("/ZC_SalesOrdersHeadPreparation", {
					method: "POST",
					urlParameters: oUrlParams,
					groupId: "batchUpdateGroup2",
					success: function (odata, Response) {
					},
					error: function (oError) {
						try {
							if (oError.responseText) {
								var obj;
								var message, message1;
								obj = JSON.parse(oError.responseText);
								message = obj.error.message.value;
							} else if (oError.response.body) {
								var errorModel = new sap.ui.model.xml.XMLModel();
								errorModel.setXML(oError.response.body);
								if (errorModel.getProperty("/0/message") !== "") {
									message = errorModel.getProperty("/0/message");
								} else {
									message = message1;
								}
							} else {
								message = message1;
							}
						} catch (error) {
							message = message1;
						}

					}
				});
				
				
				/*POST ZC_SalesOrdersHeadActivation is called */
				var that = this;
				this.getView().getModel().callFunction("/ZC_SalesOrdersHeadActivation", {
					method: "POST",
					urlParameters: oUrlParams,
					groupId: "batchUpdateGroup2",
					success: function (odata, Response) {

						if (odata !== "" || odata !== undefined) {

							if (odata.salesorder === "") {
								MessageBox.success("Sales Document  " + odata.salesorder + " has been updated");
								that._oDialog3.close();
							} else {
								MessageBox.success("Sales Document  " + odata.salesorder + " has been updated");
								that._oDialog3.close();
							}
						} else {
							MessageBox.error("Not able to delete.");
						}

					},
					error: function (oError) {
						try {
							if (oError.responseText) {
								var obj;
								var message, message1;
								obj = JSON.parse(oError.responseText);
								message = obj.error.message.value;
							} else if (oError.response.body) {
								var errorModel = new sap.ui.model.xml.XMLModel();
								errorModel.setXML(oError.response.body);
								//Read message node
								if (errorModel.getProperty("/0/message") !== "") {
									message = errorModel.getProperty("/0/message");
								} else {
									message = message1;
								}
							} else {
								message = message1;
							}
						} catch (error) {
							message = message1;
						}

					}
				});
				this._oDialog3.open();
			}
		},
		
		/*onCreate function is called on click on + button in View1.vie.xml*/
		/*onCreate opens Create fragment as dialog*/
		onCreate: function () {
			var that = this;
			if (!this._oDialog1) {
				this._oDialog1 = sap.ui.xmlfragment("ZCustDraftLockDemo.ZCustDraftLockDemo.view.create", this);
				this.getView().addDependent(this._Dialog1);
			}
			var currentObject = {
				salesorder: "",
				DraftUUID: "",
				businesspartner: "",
				overallstatus: "",
				SalesDocumentType: "",
				CostCenter: "",
				SoldToParty: "",
				Material: "",
				SalesGroup: "",
				SalesOrg: "",
				Plant: "",
				IsActiveEntity: "false"

			};
			var jModel = new sap.ui.model.json.JSONModel(currentObject);
			sap.ui.getCore().byId("userReg1").setModel(jModel, "CreateModel");
			var vAllData = that.getView().byId("smartid").getModel().oData;
			var jModel1 = new sap.ui.model.json.JSONModel(vAllData);
			sap.ui.getCore().setModel(jModel1, "CreateModel1");
			that._oDialog1.open();
			
			/*Validation given for Input Fields in create.fragment.xml*/
			sap.ui.getCore().byId("businesspartner1").setValueState(sap.ui.core.ValueState.Error);
			sap.ui.getCore().byId("auart1").setValueState(sap.ui.core.ValueState.Error);
			sap.ui.getCore().byId("overallstatus1").setValueState(sap.ui.core.ValueState.Error);
			sap.ui.getCore().byId("auart1").setTooltip("Maximum 4 character.");
			sap.ui.getCore().byId("businesspartner1").setTooltip("Maximum 10 character.");
			sap.ui.getCore().byId("overallstatus1").setTooltip("Maximum 1 character.");
			sap.ui.getCore().byId("vkorg1").setTooltip("Maximum 4 character.");
			sap.ui.getCore().byId("vkgrp1").setTooltip("Maximum 3 character.");
			sap.ui.getCore().byId("kostl1").setTooltip("Maximum 10 character.");
			sap.ui.getCore().byId("kunnr1").setTooltip("Maximum 10 character.");
			sap.ui.getCore().byId("matnr1").setTooltip("Maximum 40 character.");
			sap.ui.getCore().byId("werks1").setTooltip("Maximum 4 character.");
		},
		
		/*onchangecreate is called on every live change in particular input fields in Create.fragment.xml
		Overall status
		Business partner id
		Sales Document Type
		Sales Organisation
		Sales Group
		Cost Center
		Sold To Party
		Material
		Plant
		*/
		onchangecreate: function (oEvent) {
			var that = this;
			var newvalue = oEvent.getParameter("newValue");
			sap.ui.getCore().byId("auart1").setTooltip("Maximum 4 character.");
			sap.ui.getCore().byId("businesspartner1").setTooltip("Maximum 10 character.");
			sap.ui.getCore().byId("overallstatus1").setTooltip("Maximum 1 character.");
			sap.ui.getCore().byId("vkorg1").setTooltip("Maximum 4 character.");
			sap.ui.getCore().byId("vkgrp1").setTooltip("Maximum 3 character.");
			sap.ui.getCore().byId("kostl1").setTooltip("Maximum 10 character.");
			sap.ui.getCore().byId("kunnr1").setTooltip("Maximum 10 character.");
			sap.ui.getCore().byId("matnr1").setTooltip("Maximum 40 character.");
			sap.ui.getCore().byId("werks1").setTooltip("Maximum 4 character.");

			var id = oEvent.getParameter("id");

			var vIsActiveEntity = "false";
			var vsalesorder = sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().salesorder;
			var overallStatus = sap.ui.getCore().byId("overallstatus1").getValue();

			var bp = sap.ui.getCore().byId("businesspartner1").getValue();
			var auart = sap.ui.getCore().byId("auart1").getValue();
			var currentid = oEvent.getParameter("id");
			var newValue = oEvent.getParameter("newValue");

			if (currentid === "businesspartner1" && newValue !== "") {
				sap.ui.getCore().byId("businesspartner1").setValueState(sap.ui.core.ValueState.None);
			}
			if ((currentid === "businesspartner1" && newValue === "") || (currentid === "businesspartner1" && newValue === undefined)) {
				sap.ui.getCore().byId("businesspartner1").setValueState(sap.ui.core.ValueState.Error);
			}

			if (currentid === "auart1" && newValue !== "") {
				sap.ui.getCore().byId("auart1").setValueState(sap.ui.core.ValueState.None);
			}
			if ((currentid === "auart1" && newValue === "") || (currentid === "auart1" && newValue === undefined)) {
				sap.ui.getCore().byId("auart1").setValueState(sap.ui.core.ValueState.Error);
			}

			if (currentid === "overallstatus1" && newValue !== "") {
				sap.ui.getCore().byId("overallstatus1").setValueState(sap.ui.core.ValueState.None);
			}
			if ((currentid === "overallstatus1" && newValue === "") || (currentid === "overallstatus1" && newValue === undefined)) {
				sap.ui.getCore().byId("overallstatus1").setValueState(sap.ui.core.ValueState.Error);
			}

			if (id === "businesspartner1") {

				if (sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID === "") {
					//creating new draft

					var oMetadata = {
						"__metadata": {
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						}
					};

					that.getOwnerComponent().getModel().create("/ZC_SalesOrdersHead", oMetadata, {
						method: "POST",
						success: function (data) {
							sap.ui.getCore().byId("createcancel").setText("Discard Changes");
							//merging data to newly created draft
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
										cdraft + "'" +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"businesspartner": newvalue
							};
                            /*merging data to newly created draft*/
							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup3"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});
						},
						error: function (oError) {
							try {
								if (oError.responseText) {
									var obj;
									var message, message1;
									obj = JSON.parse(oError.responseText);
									message = obj.error.message.value;
								} else if (oError.response.body) {
									var errorModel = new sap.ui.model.xml.XMLModel();
									errorModel.setXML(oError.response.body);
									//Read message node
									if (errorModel.getProperty("/0/message") !== "") {
										message = errorModel.getProperty("/0/message");
									} else {
										message = message1;
									}
								} else {
									message = message1;
								}
							} catch (error) {
								message = message1;
							}
							sap.m.MessageToast.show(message);
						}
					});
				} else {
					//adding to already existing draft
					var adraft = sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID;
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
								adraft + "'" +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"businesspartner": newvalue
					};
					that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + adraft + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup3"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}
			}

			if (id === "overallstatus1") {
				if (sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID === "") {
					//creating new draft

					var oMetadata = {
						"__metadata": {
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						}
					};

					that.getOwnerComponent().getModel().create("/ZC_SalesOrdersHead", oMetadata, {
						method: "POST",
						success: function (data) {
							sap.ui.getCore().byId("createcancel").setText("Discard Changes");
							//adding to newly created draft
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
										cdraft + "'" +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"overallstatus": newvalue
							};

							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup3"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});
						},
						error: function (oError) {
							try {
								if (oError.responseText) {
									var obj;
									var message, message1;
									obj = JSON.parse(oError.responseText);
									message = obj.error.message.value;
								} else if (oError.response.body) {
									var errorModel = new sap.ui.model.xml.XMLModel();
									errorModel.setXML(oError.response.body);
									//Read message node
									if (errorModel.getProperty("/0/message") !== "") {
										message = errorModel.getProperty("/0/message");
									} else {
										message = message1;
									}
								} else {
									message = message1;
								}
							} catch (error) {
								message = message1;
							}
							sap.m.MessageToast.show(message);
						}
					});
				} else {
					//adding to already existing draft
					var adraft = sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID;
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
								adraft + "'" +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"overallstatus": newvalue
					};
					that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + adraft + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup3"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}
			}

			if (id === "auart1") {
				if (sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID === "") {
					//creating new draft

					var oMetadata = {
						"__metadata": {
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						}
					};

					that.getOwnerComponent().getModel().create("/ZC_SalesOrdersHead", oMetadata, {
						method: "POST",
						success: function (data) {
							sap.ui.getCore().byId("createcancel").setText("Discard Changes");
							//adding to newly created draft
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
										cdraft + "'" +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"auart": newvalue
							};

							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup3"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});
						},
						error: function (oError) {
							try {
								if (oError.responseText) {
									var obj;
									var message, message1;
									obj = JSON.parse(oError.responseText);
									message = obj.error.message.value;
								} else if (oError.response.body) {
									var errorModel = new sap.ui.model.xml.XMLModel();
									errorModel.setXML(oError.response.body);
									//Read message node
									if (errorModel.getProperty("/0/message") !== "") {
										message = errorModel.getProperty("/0/message");
									} else {
										message = message1;
									}
								} else {
									message = message1;
								}
							} catch (error) {
								message = message1;
							}
							sap.m.MessageToast.show(message);
						}
					});
				} else {
					//adding to already existing draft
					var adraft = sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID;
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
								adraft + "'" +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"auart": newvalue
					};
					that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + adraft + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup3"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}
			}

			if (id === "vkorg1") {
				if (sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID === "") {
					//creating new draft

					var oMetadata = {
						"__metadata": {
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						}
					};

					that.getOwnerComponent().getModel().create("/ZC_SalesOrdersHead", oMetadata, {
						method: "POST",
						success: function (data) {
							sap.ui.getCore().byId("createcancel").setText("Discard Changes");
							//adding to newly created draft
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
										cdraft + "'" +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"vkorg": newvalue
							};

							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup3"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});
						},
						error: function (oError) {
							try {
								if (oError.responseText) {
									var obj;
									var message, message1;
									obj = JSON.parse(oError.responseText);
									message = obj.error.message.value;
								} else if (oError.response.body) {
									var errorModel = new sap.ui.model.xml.XMLModel();
									errorModel.setXML(oError.response.body);
									//Read message node
									if (errorModel.getProperty("/0/message") !== "") {
										message = errorModel.getProperty("/0/message");
									} else {
										message = message1;
									}
								} else {
									message = message1;
								}
							} catch (error) {
								message = message1;
							}
							sap.m.MessageToast.show(message);
						}
					});
				} else {
					//adding to already existing draft
					var adraft = sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID;
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
								adraft + "'" +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"vkorg": newvalue
					};
					that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + adraft + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup3"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}
			}

			if (id === "vkgrp1") {
				if (sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID === "") {
					//creating new draft

					var oMetadata = {
						"__metadata": {
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						}
					};

					that.getOwnerComponent().getModel().create("/ZC_SalesOrdersHead", oMetadata, {
						method: "POST",
						success: function (data) {
							sap.ui.getCore().byId("createcancel").setText("Discard Changes");
							//adding to newly created draft
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
										cdraft + "'" +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"vkgrp": newvalue
							};

							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup3"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});
						},
						error: function (oError) {
							try {
								if (oError.responseText) {
									var obj;
									var message, message1;
									obj = JSON.parse(oError.responseText);
									message = obj.error.message.value;
								} else if (oError.response.body) {
									var errorModel = new sap.ui.model.xml.XMLModel();
									errorModel.setXML(oError.response.body);
									//Read message node
									if (errorModel.getProperty("/0/message") !== "") {
										message = errorModel.getProperty("/0/message");
									} else {
										message = message1;
									}
								} else {
									message = message1;
								}
							} catch (error) {
								message = message1;
							}
							sap.m.MessageToast.show(message);
						}
					});
				} else {
					//adding to already existing draft
					var adraft = sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID;
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
								adraft + "'" +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"vkgrp": newvalue
					};
					that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + adraft + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup3"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}
			}

			if (id === "kostl1") {
				if (sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID === "") {
					//creating new draft

					var oMetadata = {
						"__metadata": {
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						}
					};

					that.getOwnerComponent().getModel().create("/ZC_SalesOrdersHead", oMetadata, {
						method: "POST",
						success: function (data) {
							sap.ui.getCore().byId("createcancel").setText("Discard Changes");
							//adding to newly created draft
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
										cdraft + "'" +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"kostl": newvalue
							};

							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup3"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});
						},
						error: function (oError) {
							try {
								if (oError.responseText) {
									var obj;
									var message, message1;
									obj = JSON.parse(oError.responseText);
									message = obj.error.message.value;
								} else if (oError.response.body) {
									var errorModel = new sap.ui.model.xml.XMLModel();
									errorModel.setXML(oError.response.body);
									//Read message node
									if (errorModel.getProperty("/0/message") !== "") {
										message = errorModel.getProperty("/0/message");
									} else {
										message = message1;
									}
								} else {
									message = message1;
								}
							} catch (error) {
								message = message1;
							}
							sap.m.MessageToast.show(message);
						}
					});
				} else {
					//adding to already existing draft
					var adraft = sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID;
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
								adraft + "'" +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"kostl": newvalue
					};
					that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + adraft + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup3"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}
			}

			if (id === "kunnr1") {
				if (sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID === "") {
					//creating new draft

					var oMetadata = {
						"__metadata": {
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						}
					};

					that.getOwnerComponent().getModel().create("/ZC_SalesOrdersHead", oMetadata, {
						method: "POST",
						success: function (data) {
							sap.ui.getCore().byId("createcancel").setText("Discard Changes");
							//adding to newly created draft
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
										cdraft + "'" +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"kunnr": newvalue
							};

							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup3"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});
						},
						error: function (oError) {
							try {
								if (oError.responseText) {
									var obj;
									var message, message1;
									obj = JSON.parse(oError.responseText);
									message = obj.error.message.value;
								} else if (oError.response.body) {
									var errorModel = new sap.ui.model.xml.XMLModel();
									errorModel.setXML(oError.response.body);
									//Read message node
									if (errorModel.getProperty("/0/message") !== "") {
										message = errorModel.getProperty("/0/message");
									} else {
										message = message1;
									}
								} else {
									message = message1;
								}
							} catch (error) {
								message = message1;
							}
							sap.m.MessageToast.show(message);
						}
					});
				} else {
					//adding to already existing draft
					var adraft = sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID;
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
								adraft + "'" +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"kunnr": newvalue
					};
					that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + adraft + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup3"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}
			}

			if (id === "matnr1") {
				if (sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID === "") {
					//creating new draft

					var oMetadata = {
						"__metadata": {
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						}
					};

					that.getOwnerComponent().getModel().create("/ZC_SalesOrdersHead", oMetadata, {
						method: "POST",
						success: function (data) {
							sap.ui.getCore().byId("createcancel").setText("Discard Changes");
							//adding to newly created draft
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
										cdraft + "'" +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"matnr": newvalue
							};

							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup3"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});
						},
						error: function (oError) {
							try {
								if (oError.responseText) {
									var obj;
									var message, message1;
									obj = JSON.parse(oError.responseText);
									message = obj.error.message.value;
								} else if (oError.response.body) {
									var errorModel = new sap.ui.model.xml.XMLModel();
									errorModel.setXML(oError.response.body);
									//Read message node
									if (errorModel.getProperty("/0/message") !== "") {
										message = errorModel.getProperty("/0/message");
									} else {
										message = message1;
									}
								} else {
									message = message1;
								}
							} catch (error) {
								message = message1;
							}
							sap.m.MessageToast.show(message);
						}
					});
				} else {
					//adding to already existing draft
					var adraft = sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID;
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
								adraft + "'" +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"matnr": newvalue
					};
					that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + adraft + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup3"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}
			}

			if (id === "werks1") {
				if (sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID === "") {
					//creating new draft

					var oMetadata = {
						"__metadata": {
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						}
					};

					that.getOwnerComponent().getModel().create("/ZC_SalesOrdersHead", oMetadata, {
						method: "POST",
						success: function (data) {
							sap.ui.getCore().byId("createcancel").setText("Discard Changes");
							//adding to newly created draft
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
										cdraft + "'" +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"werks": newvalue
							};

							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup3"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});
						},
						error: function (oError) {
							try {
								if (oError.responseText) {
									var obj;
									var message, message1;
									obj = JSON.parse(oError.responseText);
									message = obj.error.message.value;
								} else if (oError.response.body) {
									var errorModel = new sap.ui.model.xml.XMLModel();
									errorModel.setXML(oError.response.body);
									//Read message node
									if (errorModel.getProperty("/0/message") !== "") {
										message = errorModel.getProperty("/0/message");
									} else {
										message = message1;
									}
								} else {
									message = message1;
								}
							} catch (error) {
								message = message1;
							}
							sap.m.MessageToast.show(message);
						}
					});
				} else {
					//adding to already existing draft
					var adraft = sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID;
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
								adraft + "'" +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"werks": newvalue
					};
					that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + adraft + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup3"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}

			}

		},

		//Delete function is called on click on delete button in View1
		onDelete: function (oEvent) {
			var vSalesorder = this._oBinding.getProperty("salesorder");
			var vDraftID = "guid'00000000-0000-0000-0000-000000000000'";
			var vActive = "true";
			if (vSalesorder === "") {
				vDraftID = this._oBinding.getPath().slice(44, 86);
				vActive = "false";

			}
			var that = this;
			this.getOwnerComponent().getModel().remove("/ZC_SalesOrdersHead(salesorder='" + vSalesorder + "',DraftUUID=" + vDraftID +
				",IsActiveEntity=" + vActive + ")", {
					method: "DELETE",

					success: function (odata, Response) {
                           /*draft is delted*/
						if (odata !== "" || odata !== undefined) {
							if (vSalesorder === "") {
								MessageBox.success(
									"Draft has been deleted", {
										icon: MessageBox.Icon.SUCCESS,
										title: "Success",
										actions: [MessageBox.Action.OK],
										emphasizedAction: MessageBox.Action.OK,
										onClose: function (oAction) {
										}
									}
								);
                               
							} 
							/*Sales order is deleted*/
							else {
								MessageBox.success(
									vSalesorder + "  Document has been deleted", {
										icon: MessageBox.Icon.SUCCESS,
										title: "Success",
										actions: [MessageBox.Action.OK],
										emphasizedAction: MessageBox.Action.OK,
										onClose: function (oAction) {
											//	location.reload();
										}
									}
								);
							}

						} else {
							MessageBox.error("Not able to delete.");
						}

					},
					error: function (oError) {
						try {
							if (oError.responseText) {
								var obj;
								var message, message1;
								obj = JSON.parse(oError.responseText);
								message = obj.error.message.value;
							} else if (oError.response.body) {
								var errorModel = new sap.ui.model.xml.XMLModel();
								errorModel.setXML(oError.response.body);
								//Read message node
								if (errorModel.getProperty("/0/message") !== "") {
									message = errorModel.getProperty("/0/message");
								} else {
									message = message1;
								}
							} else {
								message = message1;
							}
						} catch (error) {
							message = message1;
						}
						sap.m.MessageToast.show(message);

					}

				});
		},
		//table record pressed event
		/*Edit.fragment.xml is opened as dialog based on salesorder status
		normal sales order
		Draft for existing sales order
        Draft with no sales order
        Unsaved Changes for Sales order
        A Locked Sales order
		*/
		pressed: function (oEvent) {
			var that = this;
			if (!this._oDialog3) {
				this._oDialog3 = sap.ui.xmlfragment("ZCustDraftLockDemo.ZCustDraftLockDemo.view.edit", this);
			}

			//setting cancel and discard based on the draft created or not
			var vDraftIDcheck = oEvent.getSource().getBindingContext().getObject().DraftUUID;
			if (vDraftIDcheck === "00000000-0000-0000-0000-000000000000") {
				sap.ui.getCore().byId("cancel").setText("Cancel");
			} else {
				sap.ui.getCore().byId("cancel").setText("Discard Changes");
			}

			var oModel1 = new sap.ui.model.json.JSONModel();
			var salesorder = oEvent.getSource().getBindingContext().getObject().salesorder;
			oModel1.loadData("/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + salesorder +
				"',DraftUUID=guid'00000000-0000-0000-0000-000000000000',IsActiveEntity=true)?$expand=DraftAdministrativeData", null, false);

			//the entries are visible on the fragment
			var currentObject = oEvent.getSource().getBindingContext().getObject();
			var vSalesorder = currentObject.salesorder;
			var jModel = new sap.ui.model.json.JSONModel(currentObject);
			sap.ui.getCore().byId("edit1").setModel(jModel, "ShareModel");
			
			if (oModel1.getData().d !== undefined) {
				if (oModel1.getData().d.DraftAdministrativeData !== null) {
					var flaglastchange = oModel1.getData().d.DraftAdministrativeData.DraftIsLastChangedByMe;
					var flagprocess = oModel1.getData().d.DraftAdministrativeData.DraftIsProcessedByMe;
					if (flaglastchange === false && flagprocess === false) {
						var lockuser;
						if (oModel1.getData().d.DraftAdministrativeData.InProcessByUser === "") {
							//"unsaved changes by another user";	
							lockuser = oModel1.getData().d.DraftAdministrativeData.LastChangedByUser;
							MessageBox.confirm(
								"This object contains unsaved changes for user : " + lockuser, {
									initialFocus: sap.m.MessageBox.Action.CANCEL,
									onClose: function (sButton) {
										if (sButton === MessageBox.Action.OK) {
											that._oDialog3.open();
										}
									}
								});

						}
						if (oModel1.getData().d.DraftAdministrativeData.InProcessByUser !== "") {
							lockuser = oModel1.getData().d.DraftAdministrativeData.InProcessByUser;
							MessageBox.error(
								"This object is locked by user : " + lockuser
							);
							//"locked by another user"	
						}
					}
					if (flaglastchange === true && flagprocess === false || flaglastchange === true && flagprocess === true) {
						//"draft by edit screen and not unsaved and not locked";
						that._oDialog3.open();
					}
				}
			}
			if (oModel1.getData().d === undefined) {
				//"draft created by create fragment left unsaved";

				var vChange = "true";
				var vDraftID = oEvent.getSource().getBindingContext().getObject().DraftUUID;
				var vActive = "true";
				var oUrlParams = {
					PreserveChanges: vChange,
					salesorder: "",
					DraftUUID: vDraftID,
					IsActiveEntity: vActive
				};
				that._oDialog3.open();

			}
			if (oModel1.getData().d !== undefined) {
				if (oModel1.getData().d.DraftAdministrativeData === null) {
					//"normal salesorder without any draft,unsavedchanges and locking"
					that._oDialog3.open();
				}

			}
		},
		
		/*onchangecreate is called on every live change in particular input fields in edit.fragment.xml
		Overall status
		Business partner id
		Sales Document Type
		Sales Organisation
		Sales Group
		Cost Center
		Sold To Party
		Material
		Plant
		*/
		onchangeedit: function (oEvent) {

			var that = this;
			var newvalue = oEvent.getParameter("newValue");
			var id = oEvent.getParameter("id");
			//validation for input fields
			sap.ui.getCore().byId("overallstatus").setTooltip("Maximum one character.");
			sap.ui.getCore().byId("businesspartner").setTooltip("Maximum 10 character.");
			sap.ui.getCore().byId("auart").setTooltip("Maximum 4 character.");
			sap.ui.getCore().byId("vkorg").setTooltip("Maximum 4 character.");
			sap.ui.getCore().byId("vkgrp").setTooltip("Maximum 3 character.");
			sap.ui.getCore().byId("kostl").setTooltip("Maximum 10 character.");
			sap.ui.getCore().byId("kunnr").setTooltip("Maximum 10 character.");
			sap.ui.getCore().byId("matnr").setTooltip("Maximum 40 character.");
			sap.ui.getCore().byId("werks").setTooltip("Maximum 4 character.");
			var vIsActiveEntity = "false";
			var vDraID = sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().DraftUUID;
			var vsalesorder = sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().salesorder;
			if (id === "businesspartner") {
				if (vDraID === "00000000-0000-0000-0000-000000000000") {
					//creatng new draft

					var vChange = "true";
					var vDraftID = "00000000-0000-0000-0000-000000000000";
					var vActive = "true";
					var oUrlParams = {
						PreserveChanges: vChange,
						salesorder: vsalesorder,
						DraftUUID: vDraftID,
						IsActiveEntity: vActive
					};

					var url = "/ZC_SalesOrdersHeadEdit";
					var oURLParameters = {
						salesorder: vsalesorder,
						DraftUUID: vDraftID,
						IsActiveEntity: vActive
					};

					that.getView().getModel().callFunction(url, {
						method: "POST",
						urlParameters: oURLParameters,
						success: function (data) {},
						error: function () {}
					});

					that.getView().getModel().callFunction("/ZC_SalesOrdersHeadEdit", {
						method: "POST",
						urlParameters: oUrlParams,
						success: function (data) {
							sap.ui.getCore().byId("cancel").setText("Discard Changes");
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
										cdraft + "'" +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"businesspartner": newvalue
							};
							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup1"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});

						},
						error: function (oError) {
							try {
								if (oError.responseText) {
									var obj;
									var message, message1;
									obj = JSON.parse(oError.responseText);
									message = obj.error.message.value;
								} else if (oError.response.body) {
									var errorModel = new sap.ui.model.xml.XMLModel();
									errorModel.setXML(oError.response.body);
									//Read message node
									if (errorModel.getProperty("/0/message") !== "") {
										message = errorModel.getProperty("/0/message");
									} else {
										message = message1;
									}
								} else {
									message = message1;
								}
							} catch (error) {
								message = message1;
							}
							sap.m.MessageToast.show(message);
						}
					});

				} else {
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" +
								vDraID + "'" +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"businesspartner": newvalue
					};
					this.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + vDraID + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup1"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}

			}
			if (id === "overallstatus") {

				if (vDraID === "00000000-0000-0000-0000-000000000000") {

					//creating new draft
					var url = "/ZC_SalesOrdersHeadEdit";
					var oURLParameters = {
						salesorder: vsalesorder,
						DraftUUID: vDraID,
						IsActiveEntity: "true"
					};

					that.getView().getModel().callFunction(url, {
						method: "POST",
						urlParameters: oURLParameters,
						success: function (data) {},
						error: function () {}
					});
					var vChange = "true";
					var vDraftID = "00000000-0000-0000-0000-000000000000";
					var vActive = "true";
					var oUrlParams = {
						PreserveChanges: vChange,
						salesorder: vsalesorder,
						DraftUUID: vDraftID,
						IsActiveEntity: vActive
					};
					that.getView().getModel().callFunction("/ZC_SalesOrdersHeadEdit", {
						method: "POST",
						urlParameters: oUrlParams,
						success: function (data) {
							sap.ui.getCore().byId("cancel").setText("Discard Changes");
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" +
										cdraft +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"overallstatus": newvalue
							};

							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup1"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});

						},
						error: function () {}
					});

				} else {
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" + vDraID +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"overallstatus": newvalue
					};
					this.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + vDraID + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup1"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});

				}
			}
			if (id === "auart") {

				if (vDraID === "00000000-0000-0000-0000-000000000000") {
					//creating draft
					var url = "/ZC_SalesOrdersHeadEdit";
					var oURLParameters = {
						salesorder: vsalesorder,
						DraftUUID: vDraID,
						IsActiveEntity: "true"
					};

					that.getView().getModel().callFunction(url, {
						method: "POST",
						urlParameters: oURLParameters,
						success: function (data) {},
						error: function () {}
					});
					var vChange = "true";
					var vDraftID = "00000000-0000-0000-0000-000000000000";
					var vActive = "true";
					var oUrlParams = {
						PreserveChanges: vChange,
						salesorder: vsalesorder,
						DraftUUID: vDraftID,
						IsActiveEntity: vActive
					};

					that.getView().getModel().callFunction("/ZC_SalesOrdersHeadEdit", {
						method: "POST",
						urlParameters: oUrlParams,
						success: function (data) {
							sap.ui.getCore().byId("cancel").setText("Discard Changes");
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" +
										cdraft +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"auart": newvalue
							};
							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup1"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});

						},
						error: function () {}
					});

				} else {
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" + vDraID +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"auart": newvalue
					};
					this.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + vDraID + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup1"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}
			}
			if (id === "vkorg") {
				if (vDraID === "00000000-0000-0000-0000-000000000000") {
					var url = "/ZC_SalesOrdersHeadEdit";
					var oURLParameters = {
						salesorder: vsalesorder,
						DraftUUID: vDraID,
						IsActiveEntity: "true"
					};

					that.getView().getModel().callFunction(url, {
						method: "POST",
						urlParameters: oURLParameters,
						success: function (data) {},
						error: function () {}
					});
					//creating draft
					var vChange = "true";
					var vDraftID = "00000000-0000-0000-0000-000000000000";
					var vActive = "true";
					var oUrlParams = {
						PreserveChanges: vChange,
						salesorder: vsalesorder,
						DraftUUID: vDraftID,
						IsActiveEntity: vActive
					};

					that.getView().getModel().callFunction("/ZC_SalesOrdersHeadEdit", {
						method: "POST",
						urlParameters: oUrlParams,
						success: function (data) {
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" +
										cdraft +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"vkorg": newvalue
							};
							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup1"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});

						},
						error: function () {}
					});

				} else {
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" + vDraID +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"vkorg": newvalue
					};
					this.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + vDraID + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup1"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}
			}
			if (id === "vkgrp") {
				if (vDraID === "00000000-0000-0000-0000-000000000000") {
					var url = "/ZC_SalesOrdersHeadEdit";
					var oURLParameters = {
						salesorder: vsalesorder,
						DraftUUID: vDraID,
						IsActiveEntity: "true"
					};

					that.getView().getModel().callFunction(url, {
						method: "POST",
						urlParameters: oURLParameters,
						success: function (data) {},
						error: function () {}
					});
					//creating draft
					var vChange = "true";
					var vDraftID = "00000000-0000-0000-0000-000000000000";
					var vActive = "true";
					var oUrlParams = {
						PreserveChanges: vChange,
						salesorder: vsalesorder,
						DraftUUID: vDraftID,
						IsActiveEntity: vActive
					};

					that.getView().getModel().callFunction("/ZC_SalesOrdersHeadEdit", {
						method: "POST",
						urlParameters: oUrlParams,
						success: function (data) {
							sap.ui.getCore().byId("cancel").setText("Discard Changes");
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().DraftUUID = cdraft;

							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" +
										cdraft +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"vkgrp": newvalue
							};
							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup1"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});
						},
						error: function () {}
					});

				} else {
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" + vDraID +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"vkgrp": newvalue
					};
					this.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + vDraID + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup1"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});

				}
			}
			if (id === "kostl") {
				if (vDraID === "00000000-0000-0000-0000-000000000000") {
					var url = "/ZC_SalesOrdersHeadEdit";
					var oURLParameters = {
						salesorder: vsalesorder,
						DraftUUID: vDraID,
						IsActiveEntity: "true"
					};

					that.getView().getModel().callFunction(url, {
						method: "POST",
						urlParameters: oURLParameters,
						success: function (data) {},
						error: function () {}
					});
					//creating draft
					var vChange = "true";
					var vDraftID = "00000000-0000-0000-0000-000000000000";
					var vActive = "true";
					var oUrlParams = {
						PreserveChanges: vChange,
						salesorder: vsalesorder,
						DraftUUID: vDraftID,
						IsActiveEntity: vActive
					};

					that.getView().getModel().callFunction("/ZC_SalesOrdersHeadEdit", {
						method: "POST",
						urlParameters: oUrlParams,
						success: function (data) {
							sap.ui.getCore().byId("cancel").setText("Discard Changes");
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().DraftUUID = cdraft;

							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" +
										cdraft +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"kostl": newvalue
							};

							that.getOwnerComponent().getModel().upadte("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup1"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});

						},
						error: function () {}
					});

				} else {
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" + vDraID +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"kostl": newvalue
					};
					this.getOwnerComponent().getModel().upadte("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + vDraID + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup1"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}

			}
			if (id === "kunnr") {
				if (vDraID === "00000000-0000-0000-0000-000000000000") {
					var url = "/ZC_SalesOrdersHeadEdit";
					var oURLParameters = {
						salesorder: vsalesorder,
						DraftUUID: vDraID,
						IsActiveEntity: "true"
					};

					that.getView().getModel().callFunction(url, {
						method: "POST",
						urlParameters: oURLParameters,
						success: function (data) {},
						error: function () {}
					});
					//creating draft
					var vChange = "true";
					var vDraftID = "00000000-0000-0000-0000-000000000000";
					var vActive = "true";
					var oUrlParams = {
						PreserveChanges: vChange,
						salesorder: vsalesorder,
						DraftUUID: vDraftID,
						IsActiveEntity: vActive
					};

					that.getView().getModel().callFunction("/ZC_SalesOrdersHeadEdit", {
						method: "POST",
						urlParameters: oUrlParams,
						success: function (data) {
							sap.ui.getCore().byId("cancel").setText("Discard Changes");
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().DraftUUID = cdraft;
							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" +
										cdraft +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"kunnr": newvalue
							};

							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup1"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});
						},
						error: function () {}
					});

				} else {
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" + vDraID +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"kunnr": newvalue
					};
					this.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + vDraID + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup1"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});

				}
			}
			if (id === "matnr") {
				var url = "/ZC_SalesOrdersHeadEdit";

				if (vDraID === "00000000-0000-0000-0000-000000000000") {
					var oURLParameters = {
						salesorder: vsalesorder,
						DraftUUID: vDraID,
						IsActiveEntity: "true"
					};

					that.getView().getModel().callFunction(url, {
						method: "POST",
						urlParameters: oURLParameters,
						success: function (data) {},
						error: function () {}
					});
					//creating draft
					var vChange = "true";
					var vDraftID = "00000000-0000-0000-0000-000000000000";
					var vActive = "true";
					var oUrlParams = {
						PreserveChanges: vChange,
						salesorder: vsalesorder,
						DraftUUID: vDraftID,
						IsActiveEntity: vActive
					};

					that.getView().getModel().callFunction("/ZC_SalesOrdersHeadEdit", {
						method: "POST",
						urlParameters: oUrlParams,
						success: function (data) {
							sap.ui.getCore().byId("cancel").setText("Discard Changes");
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().DraftUUID = cdraft;

							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" +
										cdraft +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"matnr": newvalue
							};

							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup1"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});

						},
						error: function () {}
					});
				} else {
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" + vDraID +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"matnr": newvalue
					};
					this.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + vDraID + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup1"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});

				}
			}
			if (id === "werks") {

				if (vDraID === "00000000-0000-0000-0000-000000000000") {
					//creating draft
					var url = "/ZC_SalesOrdersHeadEdit";
					var oURLParameters = {
						salesorder: vsalesorder,
						DraftUUID: vDraID,
						IsActiveEntity: "true"
					};

					that.getView().getModel().callFunction(url, {
						method: "POST",
						urlParameters: oURLParameters,
						success: function (data) {},
						error: function () {}
					});
					var vChange = "true";
					var vDraftID = "00000000-0000-0000-0000-000000000000";
					var vActive = "true";
					var oUrlParams = {
						PreserveChanges: vChange,
						salesorder: vsalesorder,
						DraftUUID: vDraftID,
						IsActiveEntity: vActive
					};

					that.getView().getModel().callFunction("/ZC_SalesOrdersHeadEdit", {
						method: "POST",
						urlParameters: oUrlParams,
						success: function (data) {
							sap.ui.getCore().byId("cancel").setText("Discard Changes");
							var cdraft = data.DraftUUID;
							sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().DraftUUID = cdraft;

							var oPayload = {
								"__metadata": {
									"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" +
										cdraft +
										",IsActiveEntity=" + vIsActiveEntity + ")",
									"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
								},
								"werks": newvalue
							};
							that.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + cdraft +
								"'" +
								",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
									groupId: "batchUpdateGroup1"
								}, {
									method: "MERGE",
									success: function (data) {},
									error: function (oError) {
										try {
											if (oError.responseText) {
												var obj;
												var message, message1;
												obj = JSON.parse(oError.responseText);
												message = obj.error.message.value;
											} else if (oError.response.body) {
												var errorModel = new sap.ui.model.xml.XMLModel();
												errorModel.setXML(oError.response.body);
												//Read message node
												if (errorModel.getProperty("/0/message") !== "") {
													message = errorModel.getProperty("/0/message");
												} else {
													message = message1;
												}
											} else {
												message = message1;
											}
										} catch (error) {
											message = message1;
										}
										sap.m.MessageToast.show(message);
									}
								});

						},
						error: function () {}
					});
				} else {
					var oPayload = {
						"__metadata": {
							"uri": "/sap/opu/odata/sap/ZC_SALESORDERSHEAD_CDS/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=" + vDraID +
								",IsActiveEntity=" + vIsActiveEntity + ")",
							"type": "ZC_SALESORDERSHEAD_CDS.ZC_SalesOrdersHeadType"
						},
						"werks": newvalue
					};
					this.getOwnerComponent().getModel().update("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + vDraID + "'" +
						",IsActiveEntity=" + vIsActiveEntity + ")", oPayload, {
							groupId: "batchUpdateGroup1"
						}, {
							method: "MERGE",
							success: function (data) {},
							error: function (oError) {
								try {
									if (oError.responseText) {
										var obj;
										var message, message1;
										obj = JSON.parse(oError.responseText);
										message = obj.error.message.value;
									} else if (oError.response.body) {
										var errorModel = new sap.ui.model.xml.XMLModel();
										errorModel.setXML(oError.response.body);
										//Read message node
										if (errorModel.getProperty("/0/message") !== "") {
											message = errorModel.getProperty("/0/message");
										} else {
											message = message1;
										}
									} else {
										message = message1;
									}
								} catch (error) {
									message = message1;
								}
								sap.m.MessageToast.show(message);
							}
						});
				}
			}
		},
		Exit: function (oEvent) {
			this._oDialog3.close();

		},
		//Line selection through radio button enable delete button
		onTableSelectionChange: function (oEvent) {
			var oButton = this.byId("idPersoButton");
			oButton.setEnabled(true);
			this.getView().byId("idPersoButton").setVisible(true);
			//	this.getView().byId("ideditButton").setVisible(true);
			this._oBinding = oEvent.getSource().getSelectedItem().getBindingContext();
		},

		// onClose event handler of the fragment
		onClose: function (oEvent) {
			// if draft only then discard changes else only cancel
			var that = this;
			var vIsActiveEntity = "false";
			var vsalesorder = sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().salesorder;
			var vdraftID = sap.ui.getCore().byId("edit1").getModel("ShareModel").getData().DraftUUID;

			if (vdraftID !== "00000000-0000-0000-0000-000000000000") {

				MessageBox.confirm(
					"Do you really want to discard all the changes?", {
						initialFocus: sap.m.MessageBox.Action.OK,
						onClose: function (sButton) {
							if (sButton === MessageBox.Action.OK) {
								that.getOwnerComponent().getModel().remove("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + vdraftID +
									"'" +
									",IsActiveEntity=" + vIsActiveEntity + ")", {
										method: "DELETE",

										success: function (odata, Response) {

											that._oDialog3.close();
										},
										error: function (oError) {
											try {
												if (oError.responseText) {
													var obj;
													var message, message1;
													obj = JSON.parse(oError.responseText);
													message = obj.error.message.value;
												} else if (oError.response.body) {
													var errorModel = new sap.ui.model.xml.XMLModel();
													errorModel.setXML(oError.response.body);
													//Read message node
													if (errorModel.getProperty("/0/message") !== "") {
														message = errorModel.getProperty("/0/message");
													} else {
														message = message1;
													}
												} else {
													message = message1;
												}
											} catch (error) {
												message = message1;
											}
											sap.m.MessageToast.show(message);
											that._oDialog3.open();
										}
									});
								that._oDialog3.close();
								//	 that._oDialog3.open();	
							}
							that._oDialog3.close();
						}
					});

			}
			that._oDialog3.close();

		},

		onexit: function () {
			var that = this;
			var vIsActiveEntity = "false";
			var vsalesorder = sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().salesorder;
			var vdraftID = sap.ui.getCore().byId("userReg1").getModel("CreateModel").getData().DraftUUID;
			if (vdraftID !== "00000000-0000-0000-0000-000000000000") {

				MessageBox.confirm(
					"Do you really want to discard all the changes?", {
						initialFocus: sap.m.MessageBox.Action.OK,
						onClose: function (sButton) {
							if (sButton === MessageBox.Action.OK) {
								that.getOwnerComponent().getModel().remove("/ZC_SalesOrdersHead(salesorder='" + vsalesorder + "',DraftUUID=guid'" + vdraftID +
									"'" +
									",IsActiveEntity=" + vIsActiveEntity + ")", {
										method: "DELETE",

										success: function (odata, Response) {

											that._oDialog1.close();
										},
										error: function (oError) {
											try {
												if (oError.responseText) {
													var obj;
													var message, message1;
													obj = JSON.parse(oError.responseText);
													message = obj.error.message.value;
												} else if (oError.response.body) {
													var errorModel = new sap.ui.model.xml.XMLModel();
													errorModel.setXML(oError.response.body);
													//Read message node
													if (errorModel.getProperty("/0/message") !== "") {
														message = errorModel.getProperty("/0/message");
													} else {
														message = message1;
													}
												} else {
													message = message1;
												}
											} catch (error) {
												message = message1;
											}
											sap.m.MessageToast.show(message);
											that._oDialog1.open();
										}
									});
								that._oDialog1.close();
								//	 that._oDialog3.open();	
							}
							that._oDialog1.close();
						}
					});

			}
			that._oDialog1.close();

		},
		onCloseCreate: function () {
			this._oDialog1.close();
		},
		onCloseedit: function () {
			this._oDialog3.close();
		},
		onBeforeRebindTable: function (oEvent) {
			var mBindingParams = oEvent.getParameter("bindingParams");

			var oFilter = new sap.ui.model.Filter("IsActiveEntity", sap.ui.model.FilterOperator.EQ, false);
			var oFilter1 = new sap.ui.model.Filter("SiblingEntity/IsActiveEntity", sap.ui.model.FilterOperator.EQ, null);
			var comFil = new sap.ui.model.Filter([oFilter, oFilter1]);
			mBindingParams.parameters.expand = "to_BusinessPartner,to_Status,DraftAdministrativeData";
			mBindingParams.parameters.select = "salesorder,businesspartner,to_BusinessPartner/CompanyName,overallstatus,to_Status/SalesOrderOverallStatus_Text,createdat,createdby,changedat,changedby,auart,kostl,kunnr,matnr,vkgrp,vkorg,werks,DraftUUID,IsActiveEntity,HasDraftEntity,HasActiveEntity,DraftEntityLastChangeDateTime,DraftEntityCreationDateTime,DraftAdministrativeData";
			mBindingParams.filters.push(comFil);
		},
		onRefreshMlstBtnPress: function (oEvent) {
			this.oView.getParent()._mManifestModels[""].refresh(true);
			this.getView().byId("smartid").getModel().refresh(true);
			this.getView().getElementBinding().refresh(true);

		}

	});
});

After performing all the steps, the application works in following ways :-

1.Select the radio button corresponding to the sales order and then the delete button will be enabled and on click of the button delete operation will be performed.

2.Select the record and update operation in edit sales order screen

Perform changes in edit screen

  • on click of close button, edit sales order dialog box closes and draft created is visible

  • on click of discard changes button,draft is deleted

  • on click of save button ,draft is updated

3.On click of “+” button ,create sales orderscreen appears

Mandatory fields are maintained; Fill in sales order fields

  • on click of close button, create sales order screen is closed and draft is displayed

  • on click of discard changes button, draft is deleted

  • on click of create button, new sales order is created

  States of salesorder

 

 

 

 

 

 

 

 

 

1.Normal Sales order

2.Draft for existing sales order using edit screen

3.Draft with no sales order no using create screen

4.A Locked  sales order

5.Unsaved changes for sales order

 

Conclusion-

In this blog we are able to develop a Draft capable custom app using BOPF Framework.

We hope you find this blog series interesting and helpful in understanding Durable Lock Concept and how to develop Draft capable custom application.

 

We would like to thanks Karan Bahl for supporting us throughout the POC.

Have a great learning ahead.

 

Thanks,

Anjali Thakur

Anubhuti Kumari

Randa Khaled

Randa Khaled

Author Since: November 19, 2020

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x