diff --git a/layouts/v7/modules/Settings/Workflows/AdvanceFilterCondition.tpl b/layouts/v7/modules/Settings/Workflows/AdvanceFilterCondition.tpl
index eaaf653d63b3187100dd6e36d99d74efc6f02c60..a018f960af5a1201d91dbcfae4ab70d6c9f9afae 100644
--- a/layouts/v7/modules/Settings/Workflows/AdvanceFilterCondition.tpl
+++ b/layouts/v7/modules/Settings/Workflows/AdvanceFilterCondition.tpl
@@ -70,9 +70,11 @@
 			 <option value="none">{vtranslate('LBL_NONE',$MODULE)}</option>
 			{assign var=ADVANCE_FILTER_OPTIONS value=$ADVANCED_FILTER_OPTIONS_BY_TYPE[$FIELD_TYPE]}
 			{foreach item=ADVANCE_FILTER_OPTION from=$ADVANCE_FILTER_OPTIONS}
-				<option value="{$ADVANCE_FILTER_OPTION}" {if $ADVANCE_FILTER_OPTION eq $CONDITION_INFO['comparator']} selected {/if}>
-					{vtranslate($ADVANCED_FILTER_OPTIONS[$ADVANCE_FILTER_OPTION])}
-				</option>
+				<option value="{$ADVANCE_FILTER_OPTION}"
+                                {if $ADVANCE_FILTER_OPTION === $CONDITION_INFO['comparator']}
+                                        selected
+                                {/if}
+                                >{vtranslate($ADVANCED_FILTER_OPTIONS[$ADVANCE_FILTER_OPTION])}</option>
 			{/foreach}
 		</select>
 	</span>
diff --git a/layouts/v7/modules/Settings/Workflows/resources/AdvanceFilter.js b/layouts/v7/modules/Settings/Workflows/resources/AdvanceFilter.js
index ee2f992877ac7be95990759f431778cc3ffdee87..d1559a86a1dbf47ccce49d3606ac791d6c4cd16f 100644
--- a/layouts/v7/modules/Settings/Workflows/resources/AdvanceFilter.js
+++ b/layouts/v7/modules/Settings/Workflows/resources/AdvanceFilter.js
@@ -485,7 +485,7 @@ Vtiger_Owner_Field_Js('Workflows_Ownergroup_Field_Js',{},{
 	}
 });
 
-Vtiger_Picklist_Field_Js('Workflows_Picklist_Field_Js',{},{
+AdvanceFilter_Picklist_Field_Js('Workflows_Picklist_Field_Js',{},{
 
     getUi : function(){
         var selectedOption = app.htmlDecode(this.getValue());
diff --git a/modules/com_vtiger_workflow/WorkFlowScheduler.php b/modules/com_vtiger_workflow/WorkFlowScheduler.php
index e24a18c355ba4965fa03fc51e5b51645562f9511..1c4e5184dcfcbe40d609f104f7be67a3fbde6c5e 100755
--- a/modules/com_vtiger_workflow/WorkFlowScheduler.php
+++ b/modules/com_vtiger_workflow/WorkFlowScheduler.php
@@ -215,8 +215,22 @@ class WorkFlowScheduler {
 				if($operation == 'has changed from') continue;
 
 				$value = $condition['value'];
+                
+                $fieldname = $condition['fieldname'];
+				preg_match('/(\w+) : \((\w+)\) (\w+)/', $condition['fieldname'], $matches);
+				if (count($matches) != 0) {
+					list($full, $referenceField, $referenceModule, $fieldname) = $matches;
+				}
+				if($referenceField) {
+					$moduleName = $referenceModule;
+				} else {
+					$moduleName = $queryGenerator->getModule();
+				}
+				$moduleModel = Vtiger_Module_Model::getInstance($moduleName);
+				$fieldModel = $moduleModel->getField($fieldname);
+                
 				if(in_array($operation, $this->_specialDateTimeOperator())) {
-					$value = $this->_parseValueForDate($condition);
+					$value = $this->_parseValueForDate($condition, $fieldModel);
 				}
 				$columnCondition = $condition['joincondition'];
 				$groupId = $condition['groupid'];
@@ -294,7 +308,7 @@ class WorkFlowScheduler {
 	 * @param <Array> $condition
 	 * @return <String>
 	 */
-	function _parseValueForDate($condition) {
+	function _parseValueForDate($condition,$fieldModel = false) {
 		$value = $condition['value'];
 		$operation = $condition['operation'];
 
@@ -303,6 +317,11 @@ class WorkFlowScheduler {
 		$admin = Users::getActiveAdminUser();
 		$adminTimeZone = $admin->time_zone;
 		@date_default_timezone_set($adminTimeZone);
+        $fieldType = array();
+		if($fieldModel){
+			$dataType = $fieldModel->get('typeofdata');
+			$fieldType = explode('~',$dataType);
+		}
 
 		switch($operation) {
 			case 'less than days ago' :		//between current date and (currentdate - givenValue)
diff --git a/pkg/vtiger/modules/ServiceContracts/modules/ServiceContracts/ServiceContracts.php b/pkg/vtiger/modules/ServiceContracts/modules/ServiceContracts/ServiceContracts.php
index d63ec22015fd984cad18cdb1f13697c9d2fc0366..4de09bc771ab2db2476379472480108cd778b6c5 100644
--- a/pkg/vtiger/modules/ServiceContracts/modules/ServiceContracts/ServiceContracts.php
+++ b/pkg/vtiger/modules/ServiceContracts/modules/ServiceContracts/ServiceContracts.php
@@ -532,8 +532,11 @@ class ServiceContracts extends CRMEntity {
 		$totalUnits = decimalFormat($this->column_fields['total_units']);
 
 		$contractStatus = $this->column_fields['contract_status'];
+        
+        $checkServiceContractExistence = $this->db->pquery('SELECT if (EXISTS (select vsc.servicecontractsid from vtiger_servicecontracts  vsc WHERE vsc.servicecontractsid = ?), 1, 0) AS exist_sc', array($this->id));
+        $ServiceContractExistFlag = isset($checkServiceContractExistence->fields['exist_sc']) ? $checkServiceContractExistence->fields['exist_sc'] : "1";
 
-		// Update the End date if the status is Complete or if the Used Units reaches/exceeds Total Units
+        // Update the End date if the status is Complete or if the Used Units reaches/exceeds Total Units
 		// We need to do this first to make sure Actual duration is computed properly
 		if($contractStatus == 'Complete' || (!empty($usedUnits) && !empty($totalUnits) && $usedUnits >= $totalUnits)) {
 			if(empty($endDate)) {
@@ -542,7 +545,9 @@ class ServiceContracts extends CRMEntity {
 			}
 		} else {
 			$endDate = null;
-			$this->db->pquery('UPDATE vtiger_servicecontracts SET end_date=? WHERE servicecontractsid = ?', array(null, $this->id));
+			if ( $ServiceContractExistFlag !== "0") {
+				$this->db->pquery('UPDATE vtiger_servicecontracts SET end_date=? WHERE servicecontractsid = ?', array(null, $this->id));
+			}
 		}
 
 		// Calculate the Planned Duration based on Due date and Start date. (in days)
@@ -575,7 +580,9 @@ class ServiceContracts extends CRMEntity {
 		if(count($updateCols) > 0) {
 			$updateQuery = 'UPDATE vtiger_servicecontracts SET '. implode(",", $updateCols) .' WHERE servicecontractsid = ?';
 			array_push($updateParams, $this->id);
-			$this->db->pquery($updateQuery, $updateParams);
+			if ( $ServiceContractExistFlag !== "0") {
+				$this->db->pquery($updateQuery, $updateParams);
+			}
 		}
 	}
 
diff --git a/vtlib/Vtiger/Module.php b/vtlib/Vtiger/Module.php
index bbc9ca0c4339468e9242a263bcdae74456d42284..98fe399d757d52987e809c440375b6e4bfa14740 100644
--- a/vtlib/Vtiger/Module.php
+++ b/vtlib/Vtiger/Module.php
@@ -15,6 +15,11 @@ include_once('vtlib/Vtiger/ModuleBasic.php');
  * @package vtlib
  */
 class Vtiger_Module extends Vtiger_ModuleBasic {
+    
+    const ONE_TO_ONE = '1:1';
+	const ONE_TO_MANY = '1:N';
+	const MANY_TO_ONE = 'N:1';
+	const MANY_TO_MANY = 'N:N';
 
 	/**
 	 * Function to get the Module/Tab id
@@ -79,13 +84,22 @@ class Vtiger_Module extends Vtiger_ModuleBasic {
 		$useactions_text = $actions;
 		if(is_array($actions)) $useactions_text = implode(',', $actions);
 		$useactions_text = strtoupper($useactions_text);
-
+        if($fieldId != null){
+            //Default relation type if relation fieldid is set
+            $relationType = Vtiger_Module::ONE_TO_MANY;
+        } else  {
+            //Default relation type if relation fieldid is not set
+            $relationType = Vtiger_Module::MANY_TO_MANY;
+        }
 		// Add column to vtiger_relatedlists to save extended actions
 		Vtiger_Utils::AddColumn('vtiger_relatedlists', 'actions', 'VARCHAR(50)');
-
-		$adb->pquery("INSERT INTO vtiger_relatedlists(relation_id,tabid,related_tabid,name,sequence,label,presence,actions,relationfieldid) VALUES(?,?,?,?,?,?,?,?,?)",
-			Array($relation_id,$this->id,$moduleInstance->id,$function_name,$sequence,$label,$presence,$useactions_text,$fieldId));
-
+		$adb->pquery("INSERT INTO vtiger_relatedlists(relation_id,tabid,related_tabid,name,sequence,label,presence,actions,relationfieldid,relationtype) VALUES(?,?,?,?,?,?,?,?,?,?)",
+			Array($relation_id,$this->id,$moduleInstance->id,$function_name,$sequence,$label,$presence,$useactions_text,$fieldId,$relationType));
+        
+        if(method_exists($this,'set')) {
+            $this->set('relation_id', $relation_id);
+        }
+        
 		self::log("Setting relation with $moduleInstance->name [$useactions_text] ... DONE");
 	}