diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index db70affe93..6b56b279ff 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -4263,9 +4263,30 @@ protected function PrepareValueFromPostedForm($sFormPrefix, $sAttCode, $sClass = case 'Set': case 'TagSet': $sTagSetJson = utils::ReadPostedParam("attr_{$sFormPrefix}{$sAttCode}", null, 'raw_data'); - if ($sTagSetJson !== null) { // bulk modify, direct linked set not handled - $value = json_decode($sTagSetJson, true); - } + if ($sTagSetJson !== null) { // bulk modify, direct linked set not handled + $value = json_decode($sTagSetJson, true); + if ($this->IsNew()) { + if ($value['orig_value'] != '' ) { + foreach ($value['orig_value'] as $val) { + if (!in_array($val, $value['removed'])) { + $value['added'][] = $val; + } + } + } + } else { + $acurrentValues = $this->Get($sAttCode)->GetValues(); + foreach ($value['orig_value'] as $val) { + if ( !in_array($val, $acurrentValues) && !in_array($val, $value['removed']) && !in_array($val, $value['added']) ) { + $value['added'][] = $val; + } + } + foreach ($acurrentValues as $val) { + if ( !in_array($val, $value['orig_value']) && !in_array($val, $value['removed']) && !in_array($val, $value['added']) ) { + $value['removed'][] = $val; + } + } + } + } break; default: