Добрый день!
почему я не могу сделать изменения? выбивает после того, как я меняю данные о виде деятельности и отраслей.
Нравится
Здравствуйте,
из данного сообщения можно сделать вывод, что Вы забили перевести Dataset в режим редактирования: Dataset.Edit();
Чтобы более точно ответить, необходимо видеть полный код, где возникает данная проблема.
//-----------------------------------------------------------------------------
// scr_AccountEdit
//-----------------------------------------------------------------------------
var AccountEdit = new Object();
function InitializeDataset() {
SetAttribute(dlData.Dataset, 'CommunicationDataset',
'ds_AccountCommunication');
SetAttribute(dlData.Dataset, 'AddressDataset', 'ds_AccountAddress');
SetAttribute(dlData.Dataset, 'CampaignDataset', 'ds_AccountInCampaign');
BaseDBEdit.Subject = 'Account';
BaseDBEdit.Dataset = dlData.Dataset;
}
function Initialize() {
InitializeDataset();
}
/* PRODUCT XRM */
function GetAccountBalanceForPeriod(AccountID, StartDays, EndDays, BalanceType){
var NowDate = new Date();
var BalanceSelectQuery = GetSingleItemByCode('sq_AccountsBalance',
'GetDatasetDisplayValue2');
ApplySelectQueryFilter(BalanceSelectQuery, 'AccountID', AccountID, true);
var EndDate;
if(!IsEmptyValue(EndDays)){
EndDate = AddDateDays(NowDate, (-1) * EndDays).getVarDate();
}
var StartDate;
if(!IsEmptyValue(StartDays)) {
StartDate = AddDateDays(NowDate, (-1) * StartDays).getVarDate();
}
EnableSelectQueryFilters(BalanceSelectQuery, (BalanceType == 'PL'), ['IsPL']);
EnableSelectQueryFilters(BalanceSelectQuery, (BalanceType == 'CF'), ['IsCF']);
ApplySelectQueryFilter(BalanceSelectQuery, 'DateTo', EndDate,
(!IsEmptyValue(EndDate)));
ApplySelectQueryFilter(BalanceSelectQuery, 'DateFrom', StartDate,
(!IsEmptyValue(StartDate)));
var BalanceDataset = BalanceSelectQuery.Open();
return BalanceDataset;
}
function InitializePostponementPayment(Window) {
var Dataset = dlData.Dataset;
edtPostponementPayment.DisableEvents();
try {
if (Dataset.State == dstInsert) {
edtPostponementPayment.Value = '15';
} else
if (Dataset.State == dstEdit) {
edtPostponementPayment.Value = Dataset('PostponementPayment') * 1;
}
} finally {
edtPostponementPayment.EnableEvents();
}
RefreshPostponementPayment(GetAttribute(Window, 'RecordID'));
edtPostponementPayment.IsReadOnly = !GetCanEditData(Dataset);
}
function RefreshPostponementPayment(AccountID){
var Dataset = dlData.Dataset;
var Value = Dataset.ValAsInt('PostponementPayment');
if (Value <= 0) {
Value = 14;
}
var HalfValue = parseInt(Value / 2);
edtPostPaymentPeriod1.Caption = " до " + HalfValue + " дней:";
edtPostPaymentPeriod2.Caption = " " + HalfValue + " - " +
Value + " дней:";
edtPostPaymentPeriod3.Caption = " более " + Value + " дней:";
edtAmmountPL.Tag = '0,' + HalfValue + ',PL';
edtAmmountCF.Tag = '0,' + HalfValue + ',CF';
edtAmmountPL30.Tag = HalfValue + ',' + Value + ',PL';
edtAmmountCF30.Tag = HalfValue + ',' + Value + ',CF';
edtAmmountPL90.Tag = Value + ',0,PL';
edtAmmountCF90.Tag = Value + ',0,CF';
var BasicAmountPL = GetAccountBalanceForPeriod(AccountID, HalfValue, 0, 'PL').
ValAsFloat('BasicAmount');
var BasicAmountCF = GetAccountBalanceForPeriod(AccountID, HalfValue, 0, 'CF').
ValAsFloat('BasicAmount');
var BasicAmountPLTotal = BasicAmountPL;
var BasicAmountCFTotal = BasicAmountCF;
edtAmmountCF.Value = AddDelimiter(BasicAmountCF);
edtAmmountPL.Value = AddDelimiter(BasicAmountPL);
if((BasicAmountPL == 0)||( BasicAmountCF == 0)){
lblPLPercent.Caption = "0 %";
} else {
lblPLPercent.Caption = AddDelimiter(((BasicAmountCF/BasicAmountPL)* 100).toFixed(2)) + " %"
}
BasicAmountPL = GetAccountBalanceForPeriod(AccountID, Value, HalfValue, 'PL').
ValAsFloat('BasicAmount');
BasicAmountCF = GetAccountBalanceForPeriod(AccountID, Value, HalfValue, 'CF').
ValAsFloat('BasicAmount');
BasicAmountPLTotal = BasicAmountPLTotal + BasicAmountPL;
BasicAmountCFTotal = BasicAmountCFTotal + BasicAmountCF;
edtAmmountCF30.Value = AddDelimiter(BasicAmountCF);
edtAmmountPL30.Value = AddDelimiter(BasicAmountPL);
if ((BasicAmountPL == 0) ||
(BasicAmountCF == 0)) {
lblPL30Percent.Caption = "0 %";
} else {
lblPL30Percent.Caption = AddDelimiter(((BasicAmountCF/BasicAmountPL) * 100).toFixed(2)) + ' %';
}
BasicAmountPL = GetAccountBalanceForPeriod(AccountID, null, Value, 'PL').
ValAsFloat('BasicAmount');
BasicAmountCF = GetAccountBalanceForPeriod(AccountID, null, Value, 'CF').
ValAsFloat('BasicAmount');
BasicAmountPLTotal = BasicAmountPLTotal + BasicAmountPL;
BasicAmountCFTotal = BasicAmountCFTotal + BasicAmountCF;
edtAmmountCF90.Value = AddDelimiter(BasicAmountCF);
edtAmmountPL90.Value = AddDelimiter(BasicAmountPL);
if ((BasicAmountPL == 0) || (BasicAmountCF == 0)) {
lblPL90Percent.Caption = "0 %";
} else {
lblPL90Percent.Caption = AddDelimiter(((BasicAmountCF/BasicAmountPL)* 100).toFixed(2)) + '%';
}
var BalanceAmount = (BasicAmountCFTotal - BasicAmountPLTotal).toFixed(2);
AccountEdit.BalanceAmount = BalanceAmount;
}
function AddDelimiter(Value){
var ParentValue = Value + '';
var StrValue = Value + '';
if (StrValue.indexOf('.') != -1) {
StrValue = StrValue.substr(0,StrValue.indexOf('.'));
}
if (StrValue.indexOf('-') != -1) {
StrValue = StrValue.substr(1);
}
var StrLen = StrValue.length;
var i = 0;
while (StrLen > 3) {
StrLen = StrLen - 3;
StrValue = StrValue.substr(0,StrLen) + ' ' + StrValue.substr(StrLen);
}
if (ParentValue.indexOf('.') != -1) {
StrValue = StrValue + ',' + ParentValue.substr(ParentValue.indexOf('.') + 1);
}
if (ParentValue.indexOf('-') != -1) {
StrValue = '-' + StrValue;
}
return StrValue;
}
function UpdateAccountBasicCurrencyCaptions() {
var CurrencyID = GetBasicCurrencyID();
var CurrencySymbol = GetCurrencySymbol(CurrencyID);
var SettledCreditField = dlData.Dataset.DataFields.ItemsByName('SettledCredit');
SettledCreditField.Caption = "Разрешенный кредит, " + CurrencySymbol;
lblCF.Caption = "Оплаты, " + CurrencySymbol;
lblPL.Caption = "Обязательства, " + CurrencySymbol;
edtBalanceAmount.Caption = "Текущий баланс, " + CurrencySymbol;
edtRemainAmount.Caption = "Остаток, " + CurrencySymbol;
}
function RecalcBalance(SettledCredit) {
var BalanceAmount = AccountEdit.BalanceAmount;
var RemainAmount = (SettledCredit + BalanceAmount*1).toFixed(2);
edtBalanceAmount.Value = AddDelimiter(BalanceAmount);
edtRemainAmount.Value = AddDelimiter(RemainAmount);
}
function SetPostponementPayment(Value) {
var Dataset = dlData.Dataset;
if ((Dataset.State == dstEdit) ||
(Dataset.State == dstInsert)) {
dlData.Dataset('PostponementPayment') = (Value * 1);
}
}
/* ENDPRODUCT XRM */
function InitializeCommunicationActionSmartTags() {
for (var i = 1; i < 6; i++) {
RefreshCommunicationActionSmartTag(
Self.ComponentsByName('edtCommunication' + i + 'Type'),
Self.ComponentsByName('edtCommunication' + i));
}
}
function CallCommunicationActionSmartTagHandler(ActionMenuItem) {
scr_CommunicationActionSmartTag.HandleCommunicationActionSmartTag(ActionMenuItem);
}
function InitAccountInfo() {
var Dataset = dlData.Dataset;
AccountEdit.OldName = Dataset.Values('Name');
}
function CheckAccountData() {
var Dataset = dlData.Dataset;
var NewName = Dataset.Values('Name');
var AccountID = Dataset.Values('ID');
var NameWasChanged = (NewName != AccountEdit.OldName);
var Result = true;
if ((NameWasChanged) && (!GetAttribute(Self, 'isMassEdit'))) {
var IsAccountLicensed = GetIsAccountLicensed(AccountID);
if (IsAccountLicensed) {
var Message = "Изменение '%1' контрагента у пользователя системы, может стать причиной повреждения лицензии. Продолжить?"
var SubjectName = Dataset.DataFields('Name').Caption;
var MessageStr = FormatStr(Message, SubjectName);
var Result = (ShowConfirmationDialog(MessageStr) == mrYes);
}
}
return Result;
}
function PrepareFinanceDetail() {
pgFinance.IsVisible = !Self.Attributes('HideFinanceDetail');
}
// ----------------------------------------------------------------------------
// Event handlers
// ----------------------------------------------------------------------------
function wnd_AccountEditOnPrepare(Window) {
Initialize();
wnd_BaseDBEditOnPrepare(Window);
/* PRODUCT XRM */
UpdateAccountBasicCurrencyCaptions();
InitializePostponementPayment(Self);
PrepareFinanceDetail();
/* ENDPRODUCT XRM */
InitAccountInfo();
InitializeCommunicationActionSmartTags();
RecalcBalance(dlData.Dataset('SettledCredit'));
}
function edtOwnerOnPrepareSelectWindow(LookupDataControl) {
PrepareLookupDataControl(LookupDataControl, dlData.Dataset);
}
function edtCountryOnPrepareSelectWindow(LookupDataControl, SelectWindow) {
FilterLookupDataControlLookupDatasetByTerritory(LookupDataControl,
edtTerritory.DataField.Value);
}
function edtCityOnPrepareSelectWindow(LookupDataControl) {
FilterLookupDataControlLookupDatasetByState(LookupDataControl,
edtState.DataField.Value);
FilterLookupDataControlLookupDatasetByCountry(LookupDataControl,
edtCountry.DataField.Value);
}
function edtStateOnPrepareSelectWindow(LookupDataControl) {
FilterLookupDataControlLookupDatasetByCountry(LookupDataControl,
edtCountry.DataField.Value);
}
function btnOKOnClick(Control) {
if (!CheckAccountData()) {
return;
}
scr_BaseDBEdit.btnOKOnClick(Control);
}
function dlDataOnDatasetDataChange(DataField) {
var ActivityName = DataField.Name;
var FieldName = DataField.Name;
var Dataset = DataField.ParentDataFields.ParentDataset;
var ActivityValue = DataField.Value;
/* PRODUCT XRM */
if (FieldName == 'PostponementPayment') {
RefreshPostponementPayment(Dataset('ID'));
}
if ((FieldName == 'SettledCredit') || (FieldName == 'PostponementPayment')) {
if (Dataset.ValAsFloat('SettledCredit') < 0) {
ShowWarningDialog("Разрешенный кредит не может быть меньше 0");
Dataset('SettledCredit') = 0;
return;
}
RecalcBalance(Dataset('SettledCredit'));
}
/* ENDPRODUCT XRM */
if (FieldName.indexOf('Communication') == 0) {
var Index = FieldName.substr(13, 1);
var CommTypeDataControl =
Self.ComponentsByName('edtCommunication' + Index + 'Type');
var CommDataControl =
Self.ComponentsByName('edtCommunication' + Index);
RefreshCommunicationActionSmartTag(CommTypeDataControl, CommDataControl,
(FieldName.indexOf('Type') > -1));
}
if (ActivityName == 'ActivityID') {
if (IsEmptyValue(ActivityValue)) {
Dataset.DataFields('FieldID').Value = null;
} else {
Dataset.DataFields('FieldID').Value =
GetFieldValueFromLookupDatasetByLookupField(DataField, 'FieldID');
}
}
}
/* PRODUCT XRM */
function amiBalanceSelectOnExecute(ActionMenuItem, Sender) {
var Tag = Sender.Tag;
if (dlData.Dataset.State == dstInsert) {
if (ShowConfirmationDialog(NeedToSaveRecordBeforeProceed) != wmrYes) {
return;
}
if (!CheckAccountData()) {
return;
}
if (!WindowWasPrepared(Self)) {
return;
}
Self.ComponentsByName('btnOK').IsEnabled = false;
try {
var Result = SaveChangesWithCheck(Self, BaseDBEdit);
}
finally {
Self.ComponentsByName('btnOK').IsEnabled = true;
}
if (!Result) {
return;
}
dlData.Dataset.Edit();
}
if (IsEmptyValue(Tag)) {
return;
}
var AccountID = GetAttribute(Self, 'RecordID');
var FilterValues = Tag.split(',');
var wndOpportunities = Services.GetNewItemByUSI('wnd_CashflowGridArea');
var Dataset = wndOpportunities.ComponentsByName('dlData').Dataset;
Dataset.Close();
var NowDate = new Date();
var DateTo = AddDateDays(NowDate, (-1) * FilterValues[0]);
var DateFrom = AddDateDays(NowDate, (-1) * FilterValues[1]);
Dataset.Close();
ApplyDatasetFilter(Dataset, 'AccountBalanceDateFrom', DateFrom.getVarDate(),
(FilterValues[1] != 0));
ApplyDatasetFilter(Dataset, 'AccountBalanceDateTo', DateTo.getVarDate(), true);
ApplyDatasetFilter(Dataset, 'DebtorCreditorID', AccountID, true);
ApplyDatasetFilter(Dataset, 'IsActual', true, true);
EnableSelectQueryFilters(Dataset.SelectQuery, (FilterValues[2] == 'PL'), ['IsPL']);
EnableSelectQueryFilters(Dataset.SelectQuery, (FilterValues[2] == 'CF'), ['IsCF']);
wndOpportunities.Attributes('NotifyObject') = Self;
wndOpportunities.Attributes('IsFromAccountFinanceEdit') = true;
if (FilterValues[2] == 'PL') {
wndOpportunities.Attributes('DefaultRecipientID') = AccountID;
}
if (FilterValues[2] == 'CF') {
wndOpportunities.Attributes('DefaultPayerID') = AccountID;
}
wndOpportunities.Prepare();
wndOpportunities.Show();
Dataset.Open();
}
function edtPostponementPaymentOnChange(Edit) {
var PostponementPayment = new String(
IsEmptyValue(Edit.Value) ? 0 : Edit.Value);
if ((!IsIntegerValue(PostponementPayment)) || (((PostponementPayment*1)+'').length > 4) ||
(PostponementPayment*1 < 0) || (PostponementPayment*1 > 9999)) {
ShowWarningDialog("Отсрочка платежей должна быть целым положительным числом от 0 до 9999");
} else {
SetPostponementPayment(PostponementPayment);
}
}
/* ENDPRODUCT XRM */
function wnd_AccountEditOnNotify(ScriptableService, Sender, Message, Data) {
/* PRODUCT XRM */
if ((Message == MSG_AFTERCLOSE) &&
(ExtractUSICodeEx(Sender.USI) == 'wnd_CashflowGridArea')) {
var Dataset = dlData.Dataset;
if ((Dataset.State != dstBrowse) &&
(Dataset.State != dstInsert) &&
(Dataset.State != dstEdit)) {
return;
}
RefreshPostponementPayment(Dataset('ID'));
RecalcBalance(Dataset('SettledCredit'));
}
/* ENDPRODUCT XRM */
}
function dlDataOnDatasetAfterOpen(Dataset) {
/* PRODUCT XRM */
AccountEdit.IsPostponementPaymentInitialized = false;
/* ENDPRODUCT XRM */
}
Весь код сервиса не обязательно было выгружать, достаточно было показать код функции dlDataOnDatasetDataChange где появляется проблема.
У Вас проблема скорее всего в коде:
if (ActivityName == 'ActivityID') { if (IsEmptyValue(ActivityValue)) { Dataset.DataFields('FieldID').Value = null; } else { Dataset.DataFields('FieldID').Value = GetFieldValueFromLookupDatasetByLookupField(DataField, 'FieldID'); } }
У меня этот код отрабатывает корректно.
Опишите более подробно кейс воспроизведения.
я сделал back up, но не помогло (при добавлении или редактировании вид деятельности или отраслей контрагента выбивает даную ошибку, не могу разобраться где именно и что делать .... сейчас моя функция имеет вид:
function dlDataOnDatasetDataChange(DataField) {
var FieldName = DataField.Name;
var Dataset = DataField.ParentDataFields.ParentDataset;
/* PRODUCT XRM */
if (FieldName == 'PostponementPayment') {
RefreshPostponementPayment(Dataset('ID'));
}
if ((FieldName == 'SettledCredit') || (FieldName == 'PostponementPayment')) {
if (Dataset.ValAsFloat('SettledCredit') < 0) {
ShowWarningDialog("Разрешенный кредит не может быть меньше 0");
Dataset('SettledCredit') = 0;
return;
}
RecalcBalance(Dataset('SettledCredit'));
}
/* ENDPRODUCT XRM */
if (FieldName.indexOf('Communication') == 0) {
var Index = FieldName.substr(13, 1);
var CommTypeDataControl =
Self.ComponentsByName('edtCommunication' + Index + 'Type');
var CommDataControl =
Self.ComponentsByName('edtCommunication' + Index);
RefreshCommunicationActionSmartTag(CommTypeDataControl, CommDataControl,
(FieldName.indexOf('Type') > -1));
}
}
Возможно у Вас проблема была не здесь, а в другом месте конфигурации.
Выполните отладку кода при помощи Microsoft Visual Studio или Microsoft Script Debugger.