Волшебная кнопка

  • Автор темы morpheus
  • Дата начала
M

morpheus

Автор




Продублирую тут... кнопка выкладывается на панель инструментов, позволяет быстро и удобно редактировать, создавать, удалять, менять значения полей документа. Сильно облегчает жизнь. (поделился Шмурыгин Сергей)

Код:
_act := "Редактировать элементы поля|1" : "Добавить в поле элемент|2" : "Очистить поле|5" : "Удалить поле|3" : "Новое поле|4"; 

_dsp := @Left( _act; "|"); 
_al := @RightBack( _act; "|"); 
_fld := ""; 
_str := ""; 
_tmp := ""; 
_val := ""; 
_selType := ""; 
_sel := @Prompt( [OkCancelList]:[NoSort]; @DbTitle; "Выбери действие: "; @Subset(_dsp; 1); _dsp); 
_pos := @Member( _sel; _dsp ); 
_sel := @Subset(@Subset(_al; _pos); -1); 
_item := @DocFields; 
_empty := ""; 

_DataTypes := "Text" : "Date" : "Integer"; 

@If( _sel = "1"; 
@Do( 

_fld := @Prompt( [OkCancelList]; "Редактирование поля"; "Выбери имя поля: "; @Subset( _item; 1); _item ); 

_val := @GetField(_fld); 

_selType := @If( 
@IsTime( _val ); "Date"; 
@IsNumber(_val); "Integer"; 
@Elements(_val) = 1; 
@If(_val != ""; "Text"; 
@Prompt( [OkCancelList] : [NoSort]; "Тип поля"; "Выбери тип данных: "; @Subset( _DataTypes; 1 );_DataTypes ) 
); 
@Elements(_val) = 0; 
@Prompt( [OkCancelList] : [NoSort]; "Тип поля"; "Выбери тип данных: "; @Subset( _DataTypes; 1 );_DataTypes ); 
""); 

@If( @Elements(_val) = 0; 
@Set( "_tmp";@Prompt( [OkCancelEdit]; "New Value" + " " + _selType; "Новое значение для " + _fld + " : "; "")); 
@Do( 
@For(n := 1; n <= @Elements( _val ); n := n + 1; 

_str := @Prompt( [OkCancelEdit]; "New Value" + @Text( n ) + " " + _selType; "Измени " + @Text( n )+ "-й эл-т поля " + _fld + " (всего " + @Text( @Elements(_val) ) + ") : "; @Text(_val[n]) ); 

@If( @Trim( _str ) = ""; @Set("_empty"; "1"); "" ); 
@If( n = 1; 
_tmp := _str; 
_tmp := _tmp : _str) 

) 
) 
); 

@If(_empty = "1" & @Elements(_tmp) > 1; @Do( 

@If(_selType = "Date"; 
@Set("_tmp"; @Trim( _tmp )); 
_selType = "Integer"; 
@Set("_tmp"; @Trim( _tmp )); 
@Prompt([YesNo];"Поле " + _fld + " содержит пустые значения"; "Удалить из поля незаполненные элементы? "); 
@Set("_tmp"; @Trim( _tmp )); "") 
);""); 

@If( @Elements( _tmp ) <= 1 & _tmp = ""; @Return( @SetField( _fld; "") ); "" ); 

@If(_selType = "Date"; 
@SetField( _fld; @If(@IsError(@TextToTime(_tmp));@Return( @Prompt([Ok];"Error"; "Поле содержит некорректное значение") ); @TextToTime(_tmp)) ); 
_selType = "Integer";@SetField( _fld; @If( @IsError(@TextToNumber(_tmp)); @Return( @Prompt([Ok];"Error"; "Поле содержит некорректное значение") ); @TextToNumber(_tmp)) ); 
@SetField( _fld; _tmp )) 

); 

_sel = "2"; 
@Do( 
_fld := @Prompt( [OkCancelList]; "Добавление значения в поле"; "Выбери имя поля: "; @Subset( _item; 1); _item ); 
_val := @GetField(_fld); 

_selType := @If( 
@IsTime( _val ); "Date"; 
@IsNumber(_val); "Integer"; 
@Elements(_val) = 1 | @Elements(_val) = 0; 
@If(_val != ""; "Text"; 
@Prompt( [OkCancelList] : [NoSort]; "Тип поля"; "Выбери тип данных: "; @Subset( _DataTypes; 1 );_DataTypes ) 
); 
""); 

@Set( "_tmp";@Prompt( [OkCancelEdit]; "New Value" + " " + _selType; "Новый элемент для " + _fld + " : "; "")); 
@If( @Elements(_val) > 0; 
@Set( "_tmp";@Text(_val) : _tmp); 
"" 
); 

@If(_selType = "Date"; 
@SetField( _fld; @If(@IsError(@TextToTime(_tmp));@Return( @Prompt([Ok];"Error"; "Поле содержит некорректное значение") ); @TextToTime(_tmp)) ); 
_selType = "Integer";@SetField( _fld; @If( @IsError(@TextToNumber(_tmp)); @Return( @Prompt([Ok];"Error"; "Поле содержит некорректное значение") ); @TextToNumber(_tmp))); 
@SetField( _fld; _tmp )); 
@Return("") 
); 

_sel = "3"; 
@Do( 
_fld := @Prompt( [OkCancelList]; "Удаление поля"; "Выбери имя поля: "; @Subset( _item; 1); _item ); 
@If( !@Prompt([YesNo]; "Внимание"; "Вы действительно хотите удалить поле - " + _fld + "? "); @Return( "" ); ""); 
@SetField(_fld; @DeleteField); 
@Return("") 
); 
_sel = "4"; 
@Do( 
_fld := @Prompt( [OkCancelEdit]; "Новое поле"; "Укажи наименование нового поля: "; ""); 
@If(_fld = "";@Return("");"" ); 

@If( @IsMember( @UpperCase( _fld ); @UpperCase( _item ) ); @Return(@Prompt([Ok]; "Ошибка"; "Поле " + _fld + " уже есть в документе")); "" ); 

_val := ""; 
@SetField(_fld; _val); 
@Return("") 
); 

_sel = "5"; 
@Do( 
_fld := @Prompt( [OkCancelList]; "Очистка поля"; "Выбери имя поля: "; @Subset( _item; 1); _item ); 
@If( !@Prompt([YesNo]; "Внимание"; "Вы действительно хотите очистить поле - " + _fld + "? "); @Return( "" ); ""); 
@SetField(_fld; ""); 
@Return("") 
); 

"")
 
N

nvyush

Слегка доработал напильником.
_back := " < ... > ";
_act := "Сохранить|0" : "Редактировать элементы поля|1" : "Добавить элемент в поле|2" : "Очистить поле|5" : "Удалить поле|3" : "Создать новое поле|4" : "------------------------------|" : "Очистить фильтр представления|6";

_error := "Ошибка";
_typeSelecting := "Выбор типа данных поля '";
_selectType := "Выберите тип данных:";
_wrongType := "Некорректное значение для поля типа ";
_selectField := "Выберите поле:";
_dsp := @Left( _act; "|");
_al := @RightBack( _act; "|");
_fld := "";
_str := "";
_tmp := "";
_val := "";
_selType := "";
_tText := "Text";
_tDate := "Date";
_tNumber := "Number";
_DataTypes := _tText : _tDate : _tNumber;
_empty := "";
_cmd := "";

_sel := @Subset(_dsp; 1);

@DoWhile(
@Set("_item"; @DocFields);
@If(_cmd = "";
@Do(

@Set("_sel"; @Prompt([OkCancelList]:[NoSort]; @DbTitle; "Выберите действие: "; _sel; _dsp));
@Set("_pos"; @Member( _sel; _dsp));
@Set("_cmd"; _al[_pos])
);
"");

@If(_cmd = "1";
@Do(
@If(_fld = ""; @Set("_fld"; @Prompt([OkCancelList]; "Редактирование поля"; _selectField; _back; _back : _item)); "");
@If(_fld = _back; @Do(@Set("_item"; ""); @Set("_cmd"; ""); @Set("_fld"; ""));
@Do(
@Set("_val"; @GetField(_fld));

@Set("_selType"; @If(
@IsTime(_val ); _tDate;
@IsNumber(_val); _tNumber;
@Elements(_val) = 1;
@If(_val = ""; @Prompt([OkCancelList] : [NoSort]; _typeSelecting + _fld + "'"; _selectType; @Subset(_DataTypes; 1); _DataTypes); _tText);
@Elements(_val) = 0;
@Prompt([OkCancelList] : [NoSort]; _typeSelecting + _fld + "'"; _selectType; @Subset(_DataTypes; 1); _DataTypes); _tText));

@If(@Elements(_val) = 0;
@Set("_tmp"; @Prompt([OkCancelEdit]; "Редактирование поля '" + _fld + "' (" + _selType + ")"; "Введите новое значение поля '" + _fld + "': "; ""));
@Do(
@For(n := 1; n <= @Elements(_val); n := n + 1;
_str := @Prompt([OkCancelEdit]; "Редактирование поля '" + _fld + "' (" + _selType + ")"; "Измените элемент поля '" + _fld + "' (" + @Text(n) + " из " + @Text(@Elements(_val) ) + "):"; @Text(_val[n]));

@If(@Trim(_str) = ""; @Set("_empty"; 1); "");
@If(n = 1; _tmp := _str; _tmp := _tmp : _str)
)
)
);

@If(_empty = 1 & @Elements(_tmp) > 1; @Do(
@If(_selType = _tDate; @Set("_tmp"; @Trim(_tmp));
_selType = _tNumber; @Set("_tmp"; @Trim(_tmp));
@Prompt([YesNo];"Поле '" + _fld + "' содержит пустые значения"; "Удалить из поля незаполненные элементы?");
@Set("_tmp"; @Trim(_tmp)); "")
); "");

@If(@Elements(_tmp) <= 1 & _tmp = ""; @SetField(_fld; "");
_selType = _tDate;
@If(@IsError(@TextToTime(_tmp)); @Do(@Prompt([Ok]; _error; _wrongType + _selType); @Set("_cmd"; "1")); @Do(@SetField(_fld; @TextToTime(_tmp)); @Set("_fld"; "")));
_selType = _tNumber;
@If(@IsError(@TextToNumber(_tmp)); @Do(@Prompt([Ok]; _error; _wrongType + _selType); @Set("_cmd"; "1")); @Do(@SetField(_fld; @TextToNumber(_tmp)); @Set("_fld"; "")));
@Do(@SetField(_fld; _tmp); @Set("_fld"; ""))
)
)
)
);

_cmd = "2";
@Do(
@If(_fld = ""; @Set("_fld"; @Prompt([OkCancelList]; "Добавление значения в поле"; _selectField; _back; _back : _item)); "");
@If(_fld = _back; @Do(@Set("_item"; ""); @Set("_cmd"; ""); @Set("_fld"; ""));
@Do(
@Set("_val"; @GetField(_fld));

@Set("_selType"; @If(
@IsTime(_val ); _tDate;
@IsNumber(_val); _tNumber;
@Elements(_val) = 1;
@If(_val = ""; @Prompt([OkCancelList] : [NoSort]; _typeSelecting + _fld + "'"; _selectType; @Subset(_DataTypes; 1); _DataTypes); _tText);
@Elements(_val) = 0;
@Prompt([OkCancelList] : [NoSort]; _typeSelecting + _fld + "'"; _selectType; @Subset(_DataTypes; 1); _DataTypes); _tText));

@Set("_tmp"; @Prompt([OkCancelEdit]; "Добавление значения в поле '" + _fld + "' (" + _selType + ")"; "Введите значение нового элемента поля '" + _fld + "':"; ""));
@If(@Elements(_val) > 0; @Set("_tmp"; @Text(_val) : _tmp); "");

@Set("_cmd"; "");
@If(
_selType = _tDate;
@If(@IsError(@TextToTime(_tmp)); @Do(@Prompt([Ok]; _error; _wrongType + _selType); @Set("_cmd"; "2")); @SetField(_fld; @TextToTime(_tmp)));
_selType = _tNumber;
@If(@IsError(@TextToNumber(_tmp)); @Do(@Prompt([Ok]; _error; _wrongType + _selType); @Set("_cmd"; "2")); @SetField(_fld; @TextToNumber(_tmp)));
@Do(@SetField(_fld; _tmp))
);
@If(_cmd = ""; @Set("_fld"; ""); "")
)
)
);

_cmd = "3";
@Do(
@Set("_fld"; @Prompt([OkCancelList]; "Удаление поля"; _selectField; _back; _back : _item));
@If(_fld = _back; @Set("_cmd"; ""); @Prompt([YesNo]; "Внимание"; "Вы действительно хотите удалить поле '" + _fld + "'?"); @SetField(_fld; @DeleteField); "");
@Set("_fld"; "")
);

_cmd = "4";
@Do(
@Set("_fld"; @Prompt([OkCancelEdit]; "Создание нового поля"; "Укажите название нового поля:"; ""));
@If(_fld = ""; "";
@IsMember(@UpperCase(_fld); @UpperCase(_item)); @Prompt([Ok]; _error; "Поле '" + _fld + "' уже есть в документе!");
@Do(@Set("_cmd"; "2"))
)
);

_cmd = "5";
@Do(
@Set("_fld"; @Prompt([OkCancelList]; "Очистка поля"; _selectField; _back; _back : _item));
@If(_fld = _back; @Set("_cmd"; ""); @Prompt([YesNo]; "Внимание"; "Вы действительно хотите очистить поле '" + _fld + "'?"); @SetField(_fld; ""); "");
@Set("_fld"; "")
);

_cmd = "6";
@Do(
@SetViewInfo([SetViewFilter]; ""; ""; 1);
@Set("_cmd"; "0")
);
"End if"
);
_cmd != "0"
);
 
K

Klido

есть ещё какой-то такой вариант - где брал уже не помню...висит в агенте, на кнопку не пробовал :(
в отличии от верхнего выбирает поля типа Names из АК - удобнее, но флаг все равно сразу не ставит...

Код:
REM {Get a listing of all the fields on the current document};
List := @DocFields;
REM {Possible data types to choose from.};
DataTypes := "Text" : "Date" : "Integer" : "Password" :
"Name" : "Common Name" : "Remove Field" :
"Text Multi Value" : "Date Multi Value" : "Integer	Multi Value"
: "Name Multi Value" : "Common Name Multi Value";
REM {Prompt for which field needs to be updated.};
EditField := @Prompt( [OkCancelList]; "Select a field to alter";
"Select the field you wish to alter:"; "CustomerReply"; List );
REM {Prompt for which data type you would like the data to be};
REM {This needs to be done before value prompt to determine if the Picklist or any prompting needs to be used.};
DataType := @Prompt( [OkCancelList] : [NoSort];
"data type or action for field: " + EditField;
"Please Select the correct data type or action for field: " + EditField; "Text"; DataTypes );
REM {Based on what type of data is being entered different prompts will happen if any at all.};
RawValue := @If( @Contains( DataType; "Name Multi Value" );
@PickList( [Name] ); @Contains( DataType; "Name" );
@PickList( [Name] : [Single] ); DataType = "Remove Field"; "";
@Contains( DataType; "Multi Value" ); @Prompt( [OkCancelEdit];
"New Value for field: " + EditField; "Please enter the new desired value for: " + EditField + " seperated with ## for each value."; @Abstract([TextOnly]; 254; ""; @Text( EditField) )); @Prompt( [OkCancelEdit];
"New Value for field: " + EditField; "Please enter the new desired value for: "
+ EditField + "."; @Abstract([TextOnly]; 254; ""; @Text( EditField) ) ) );
REM {If data conversion doesn't work then don't set field.};
@If( DataType = "Date"; @If( @SetField( EditField;
@TextToTime( RawValue ) ) ); DataType = "Integer";
@If( @IsError( @TextToNumber( RawValue ) ); "";
@SetField( EditField; @TextToNumber( RawValue ) ) );
DataType = "Common Name"; @SetField( EditField;
@Name( [CN]; RawValue ) ); DataType = "Password";
@SetField( EditField; @Password( RawValue ) );
DataType = "Remove Field"; @SetField( EditField; @DeleteField );
DataType = "Text Multi Value"; @SetField( EditField;
@Explode( RawValue; "##" ) ); DataType = "Date Multi Value";
@SetField( EditField; @TextToTime( @Explode( RawValue; "##" ) ) );
DataType = "Integer Multi Value"; @If( @IsError
( @TextToNumber( @Explode( RawValue; "##" ) ) ); "";
@SetField( EditField; @TextToNumber(@Explode( RawValue; "##" ) ) ) );
DataType = "Name Multi Value"; @SetField( EditField;
@Explode( RawValue; "##" ) ); DataType = "Common Name Multi Value";
@SetField( EditField; @Name( [CN]; @Explode( RawValue; "##" ) ) );
@SetField( EditField; RawValue ) ); "";
 

lmike

нет, пердело совершенство
Lotus Team
27.08.2008
7 982
611
BIT
447
дубль от https://codeby.net/threads/47979.html?vi...st&p=227649
******************************************
в состав клиента LDN входит возможность создавать Smart Icon - некие макросы для обработки документов
простые случаи и вызов стандартных формул/команд - это понятно
вот работа с множественными документами и интерактивом (хотя и простым) - уже сложнее ;)
приведу ссылку
<div class="sp-wrap"><div class="sp-head-wrap"><div class="sp-head folded clickable">"и код"</div></div><div class="sp-body"><div class="sp-content"><!--shcode--><pre><code class='""'>REM {Edit Document Fields 6.0.0 by Chad Schelfhout.};
REM {Visit http://www.chadsmiley.com/EditDocumentFields for the latest updates};

REM {Changable constants};
cEnableConfirmation := @True;
cFieldHistoryValues := 10;
cStandardSeparators := ":" : ";" : " ";
cPromptTitle := @DbTitle + " - " + @ViewTitle;

REM {Unchangable constants};
cProfileName := "ChadSmiley Tools";
cEditLastField := "edfLastField";
cEditLastFieldDataType := "edfLastFieldDataType";
cEditLastFieldDataTypeValue := "edfLastFieldDataTypeValue";
cEditLastSeparator := "%~%";
cValueListSeparator := "^";
cFromRawValueSeparator := "%@%";
cSemicolonReplace := "#SC#";
cMaxSearchForSelectedDocs := 5520;
cMaxUpdatedDocuments := 1000;
cArraySeparator := ";";
cNoteEntryLength := 11;
cPromptNewLineOne := @Char(13);
cPromptNewLineTwo := cPromptNewLineOne + cPromptNewLineOne;
cPromptTab := @Char(9);
cCategoryNoteID := "NT00000000";
cTextExtractList := "Text Left":"Text Left Back":"Text Right":"Text Right Back";
cNoPromptList := cTextExtractList:"Remove Field":"Unique":"Sort Ascending":"Sort Descending":"Implode":"Explode":"Proper Case Text":"Proper Case Text Multi Value":"Lower Case Text":"Lower Case Text Multi Value":"Upper Case Text":"Upper Case Text Multi Value":"Password Convert":"Trim":"Trim then Unique";
cErrorCheckCode := "@Implode( @Unique( @Explode( NoteIDList : ErrorNoteID; cArraySeparator; @False ) ) )";
cErrorInformation := "\"Error documents: \" + @Implode( @Unique( @Explode( ErrorNoteIDList; cArraySeparator; @False ) ); \", \" ) + cPromptNewLineOne + \"Not updated documents: \" + @Implode( @Unique( @Explode( ErrorNoteIDList; cArraySeparator; @False ) ); \", \" )";


REM {Data types|@Function execution};
DataTypesCombo := @Explode(
"Integer|@TextToNumber( RawValue )$"+
"Integer Multi Value|@TextToNumber( @Explode( RawValue; Separator; @True) )$"+
"Date|@ToTime( RawValue )$"+
"Date Multi Value|@ToTime( @Explode( RawValue; Separator; @True) )$"+
"Text|@Text( RawValue )$"+
"Text Multi Value|@Text( @Explode( RawValue; Separator; @True) )$"+
"Text Left|@Left( @Text( @GetField( EditField[ef] ) ); ExtractValue )$"+
"Text Left Back|@LeftBack( @Text( @GetField( EditField[ef] ) ); ExtractValue )$"+
"Text Right|@Right( @Text( @GetField( EditField[ef] ) ); ExtractValue )$"+
"Text Right Back|@RightBack( @Text( @GetField( EditField[ef] ) ); ExtractValue )$"+
"Trim|@Trim( @Text( @GetField( EditField[ef] ) ) )$"+
"Trim then Unique|@Unique(@Trim( @Text( @GetField( EditField[ef] ) ) ) )$"+
"Name|RawValue$"+
"Name Multi Value|RawValue$"+
"Common Name|@Name( [CN]; RawValue )$"+
"Common Name Multi Value|@Name( [CN]; @Explode( RawValue; \":\"; @True ) )$"+
"Upper Case Text|@UpperCase( @Implode( @Text( @GetField( EditField[ef] ) ) ) )$"+
"Lower Case Text|@LowerCase( @Implode( @Text( @GetField( EditField[ef] ) ) ) )$"+
"Proper Case Text|@ProperCase( @Implode( @Text( @GetField( EditField[ef] ) ) ) )$"+
"Upper Case Text Multi Value|@UpperCase( @Explode( @Text( @GetField( EditField[ef] ) ); Separator; @True ))$"+
"Lower Case Text Multi Value|@LowerCase( @Explode( @Text( @GetField( EditField[ef] ) ); Separator; @True) )$"+
"Proper Case Text Multi Value|@ProperCase( @Explode( @Text( @GetField( EditField[ef] ) ); Separator; @True) )$"+
"Replace Substring|@ReplaceSubstring( @GetField( EditField[ef] ); FromRawValue; RawValue )$"+
"Replace|@Explode( @Replace( @GetField( EditField[ef] ); FromRawValue; RawValue ); Separator; @True )$"+
"Implode|@Implode( @Text( @GetField( EditField[ef] ) ); Separator )$"+
"Explode|@Explode( @Text( @GetField( EditField[ef] ) ); Separator; @True )$"+
"Formula|@Eval( RawValue )$"+
"Abbreviate Name|@Name([Abbreviate]; RawValue )$"+
"Abbreviate Name Multi Value|@Name( [Abbreviate]; @Explode( RawValue; Separator; @True ) )$"+
"Password Set|@Password( RawValue )$"+
"Password Convert|@Password( @GetField( EditField[ef] ) )$"+
"Remove Field|@DeleteField$"+
"Unique|@Unique(@GetField( EditField[ef]))$"+
"+ Append Values|@If(" +
" @GetField(EditField[ef]) = \"\"; RawValue;" +
" @Contains(DefaultDataType; \"Date\");" +
" @If( @IsError( @ToTime( RawValue ) );" +
" \"\";" +
" @SetField( EditField[ef]; @GetField(EditField[ef]) : @TextToTime( @Explode( RawValue; Separator ) ) ) );" +
" @Contains(DefaultDataType; \"Integer\" );" +
" @If( @IsError( @TextToNumber( @Explode( RawValue; Separator ) ) );" +
" \"\";" +
" @SetField( EditField[ef]; @GetField(EditField[ef]) : @TextToNumber( @Explode( RawValue; Separator ) ) ) );" +
" @SetField( EditField[ef]; @GetField(EditField[ef]) : @Explode( RawValue; Separator ) ) )$"+
"Sort Ascending|@Sort(@GetField(EditField[ef]); [Ascending] )$"+
"Sort Descending|@Sort(@GetField(EditField[ef]); [Descending])"; "$" );

DataTypes := @Word( DataTypesCombo; "|"; 1 );
DataTypesAction := @Word( DataTypesCombo; "|"; 2 );

REM {Get a listing of all the fields on the current document};
List := @Sort( @DocFields );

REM {Look for last field modified in Profile Doc};
FieldList := @Explode( @GetProfileField( cProfileName; cEditLastField; @UserName ); cArraySeparator; @True );

REM {Get the list of forms and field that was updated using Edit Document Fields};
FieldListForms := @Word( FieldList; cEditLastSeparator; 1 );
FieldListField := @Word( FieldList; cEditLastSeparator; 2 );
FieldListLastIndex := @Member( Form; FieldListForms );
REM {If the FieldListLastIndex is greater than zero then set the last field to the what was in the profile document};
@If( FieldListLastIndex > 0;
@Do( LastField := FieldListField[ FieldListLastIndex ];
FieldList := @ReplaceSubstring( FieldList; FieldList[ FieldListLastIndex ]; "" ) );
LastField :="" );

REM {Prompt for which field needs to be updated. Loop until a field is selected or 'Cancel' is selected};
@DoWhile(
EditField := @Prompt( [OkCancelEditCombo]; cPromptTitle; "Select the field you wish to alter or enter a new field to add:"; LastField; @Trim( @Unique( List : LastField ) ) );
EditField = "" );
EditFieldPromptTitle := "Change '" + EditField + "' in " + cPromptTitle;

REM {This will allow the retrieval of the data type of the field that was last selected. Data is stored like Form+Field%~%DataType.};
FormFieldList := @Explode( @GetProfileField( cProfileName; cEditLastFieldDataType; @UserName ); cArraySeparator; @True );
FormFieldListFormField := @Word( FormFieldList; cEditLastSeparator; 1 );
FormFieldListDataType := @Word( FormFieldList; cEditLastSeparator; 2 );
FormFieldListFormulaCode := @ReplaceSubstring( @Word( FormFieldList; cEditLastSeparator; 3 ); cSemicolonReplace; ";" );
FormFieldListIndex := @Member( Form + EditField; FormFieldListFormField );
@If( FormFieldListIndex > 0;
@Do( DefaultDataType := FormFieldListDataType[ FormFieldListIndex ];
FormFieldListFormulaCode := FormFieldListFormulaCode[ FormFieldListIndex ];
FormFieldList := @ReplaceSubstring( FormFieldList; FormFieldList[ FormFieldListIndex ]; "" ) );
DefaultDataType :="" );

REM {If there was no data type used for the field on the form the try to determine the data type};
DefaultDataType :=
@If( DefaultDataType != "";
DefaultDataType;
@If(
@IsNumber( @GetField( EditField ) );
@If( @Count( @GetField( EditField ) ) > 1;
"Integer Multi Value";
"Integer" );
@IsTime( @GetField( EditField ) );
@If( @Count( @GetField( EditField ) ) > 1;
"Date Mult iValue";
"Date" );
@If( @Count( @GetField( EditField ) ) > 1;
"Text Multi Value";
"Text" )
)
);

REM {If the data type is a type of error then select the data type of text};
DefaultDataType := @IfError( DefaultDataType; "Text" );

REM {Prompt for which data type you would like the data to be. This needs to be done before value prompt to determine if the Picklist or any prompting needs to be used.};
DataType := @Prompt( [OkCancelList]; EditFieldPromptTitle; "Please select the correct data type or action for field: " + EditField + "."; DefaultDataType; DataTypes );

REM {The DataTypeAction will contain the formula that will be executed to retrieve the new value};
DataTypeAction := DataTypesAction[ @Member( DataType; DataTypes ) ];

REM {If formula was used on this field then use that instead of the fields value. Format the original value as text because the @Prompt command requires text.};
OriginalValue := @If( DataType = "Formula" & DefaultDataType = "Formula" & FormFieldListFormulaCode != "";
FormFieldListFormulaCode;
@If( @Contains( DefaultDataType; MultiValue );
@Implode( @Text( @GetField( EditField ) ); cArraySeparator );
@Text( @GetField( EditField ) ) )
);

REM {This will allow the retrieval of history of values of the field. Data is stored like Form+Field+DataType%~%ValueList.};
FormFieldListDataTypeValues := @Explode( @GetProfileField( cProfileName; cEditLastFieldDataTypeValue; @UserName ); cArraySeparator; @True );
FormFieldListFormFieldDataType := @Word( FormFieldListDataTypeValues; cEditLastSeparator; 1 );
FormFieldListValuesLists := @Word( FormFieldListDataTypeValues; cEditLastSeparator; 2 );
FormFieldListDTIndex := @Member( Form + EditField + DataType; FormFieldListFormFieldDataType );
@If( FormFieldListDTIndex > 0;
@Do( FormFieldListValuesList := FormFieldListDataTypeValues[ FormFieldListDTIndex ];
FormFieldListValuesList := @ReplaceSubstring( @Trim( @Explode( FormFieldListValuesLists[ FormFieldListDTIndex ]; cValueListSeparator; @False ) ); cSemicolonReplace; ";" );
FormFieldListDataTypeValues := @ReplaceSubstring( FormFieldListDataTypeValues; FormFieldListDataTypeValues[ FormFieldListDTIndex ]; "" ) );
FormFieldListValuesList :="" );

REM {Prompt for additional fields and determine the string that they are searching for.};
@If( DataType = ("Replace Substring":"Replace" );
@Do( EditField := @Unique( EditField : @Prompt( [OkCancelListMult]; cPromptTitle; "Select any addtional fields you wish to alter:"; EditField; List ) );
FromRawValue := @Prompt( [OkCancelEditCombo]; EditFieldPromptTitle; "Enter or select the text (case sensitive) to search for in: " + @Implode( EditField; ", " ) + "."; ""; @Unique( @Word( FormFieldListValuesList; cFromRawValueSeparator; 2 ) ) ) );
@Do( EditField := EditField;
FromRawValue := "" )
);

REM { With the Edit combo there will be a list of standard seperators to choose from.};
Separator := @If( DataType = ("Implode":"Explode" );
@Prompt( [OkCancelEditCombo]; cPromptTitle; "Enter or select the " + @If( DataType = "Implode"; "separator"; "separators" ) + ":"; ""; @Unique( @If( FormFieldListValuesList = ""; cStandardSeparators; FormFieldListValuesList : cStandardSeparators ) ) );
cArraySeparator );

REM {Determine the string to search for};
ExtractValue := @If( DataType = cTextExtractList;
@Prompt( [OkCancelEditCombo]; cPromptTitle; "Enter or select the search string or string length:"; @Subset( FormFieldListValuesList; 1 ); @Unique( FormFieldListValuesList ) );
"" );

REM {Based on what type of data is being entered different prompts will happen if any at all.};
RawValue := @If(
@Contains( DataType; "Name Multi Value" ); @PickList( [Name] );
@Contains( DataType; "Name" ); @PickList( [Name] : [Single] );
DataType = ( cNoPromptList ); "";
@Contains( DataType; "Multi Value" ); @Prompt( [OkCancelEditCombo]; EditFieldPromptTitle; "Enter or select the new desired value for: " + @Implode( EditField; ", " ) + "." + cPromptNewLineTwo + "Seperated with; for each value."; OriginalValue; @Unique( OriginalValue : FormFieldListValuesList ) );
@Contains( DataType; "+ Append Values" ); @Prompt( [OkCancelEditCombo]; EditFieldPromptTitle; "Enter or select values to append: " + @Implode( EditField; ", " ) + "." + cPromptNewLineTwo + "Seperated with; for each value."; ""; @Unique( FormFieldListValuesList ) );
DataType = ("Replace Substring":"Replace" ); @Prompt( [OkCancelEditCombo]; EditFieldPromptTitle; "Enter or select the text to repalce with in: " + EditField + "."; ""; @Unique( @Word( FormFieldListValuesList; cFromRawValueSeparator; 1 ) ) );
DataType = "Formula"; @Do( @DoWhile(
OriginalValue := @Prompt( [OkCancelEditCombo]; EditFieldPromptTitle; "Enter or select the new desired formula for: " + EditField + "."; OriginalValue; @Unique( OriginalValue : FormFieldListValuesList ) );
tempReturnCheck := @CheckFormulaSyntax( OriginalValue );
@If( tempReturnCheck != "1"; @Prompt( [Ok]; "Invalid Formula - " + EditFieldPromptTitle;
"Invalid Formula entered: " +
cPromptNewLineTwo + cPromptTab + "Error: " + cPromptTab + cPromptTab + @Text( tempReturnCheck ) +
cPromptNewLineOne + cPromptTab + "Formula: " + cPromptTab + cPromptTab + OriginalValue ); "" );
tempReturnCheck != "1" );
OriginalValue );
@Prompt( [OkCancelEditCombo]; EditFieldPromptTitle; "Enter or select the new desired value for: " + EditField + "."; OriginalValue; @Unique( OriginalValue : FormFieldListValuesList ) )
);

REM {Store Field in Profile doc};
@SetProfileField( cProfileName; cEditLastField; @Unique( @Trim( FieldList : ( Form + cEditLastSeparator + EditField[1] ) ) ); @UserName );

REM {Store Data Type of Field in Profile doc};
@SetProfileField( cProfileName; cEditLastFieldDataType;
@Unique( @Trim( FormFieldList : ( Form + EditField[1] + cEditLastSeparator + DataType + cEditLastSeparator +
@ReplaceSubstring(
@If( DataType = "Formula"; RawValue; FormFieldListFormulaCode );
";"; cSemicolonReplace ) ) ) );
@UserName );

REM {Store Data Value of Field in Profile doc};
@SetProfileField( cProfileName; cEditLastFieldDataTypeValue;
@Unique( @Trim( FormFieldListDataTypeValues : ( Form + EditField[1] + DataType + cEditLastSeparator +
@Implode(
@Subset(
@Unique(
@ReplaceSubstring(
@If( DataType = ("Implode":"Explode" ); Separator;
DataType = cTextExtractList; ExtractValue;
DataType = ( "Replace Substring":"Replace" ); RawValue + cFromRawValueSeparator + FromRawValue;
RawValue ) : FormFieldListValuesList;
";"; cSemicolonReplace ) );
cFieldHistoryValues );
cValueListSeparator ) ) ) );
@UserName );REM {If multi docs selected, only process those checked ... an unchecked doc cannot be NavNextSelected};
@Command([NavNextSelected]);
@UpdateFormulaContext;

REM {Store all Note IDs before manipulation in case field modifications cause categorized views or sorted columns to reorganize};
NoteIDList := @Text( @NoteID );
ErrorNoteIDList := "";
@Command([NavNextSelected]);
@UpdateFormulaContext;

REM {Start Looping Selected documents to gather all the documents that need to be updated.};
@While( ( @Left( NoteIDList; cNoteEntryLength ) != ( @Text( @NoteID + cArraySeparator ) ) ) & ( @Length( NoteIDList ) < cMaxSearchForSelectedDocs );
NoteIDList := NoteIDList + cArraySeparator + @Text( @NoteID );
NoteIDList := @ReplaceSubstring( NoteIDList; cCategoryNoteID + cArraySeparator; "" );
@Command([NavNextSelected]);
@UpdateFormulaContext
);
REM {Remove all category Note IDs};
NoteIDList := @ReplaceSubstring( NoteIDList; cCategoryNoteID; "" );
REM {Remove all duplicate Note IDs};
NoteIDList := @Unique( @Explode( NoteIDList; cArraySeparator; @False ) );
@StatusBar( "Found " + @Text( @Elements( NoteIDList ) ) + " documents." );
NotNoteIDList := "";

REM {Determine if the document should be updated.};
tmpPrompt := @Implode( "The following information will be used to update the " + @Text( @Elements( NoteIDList ) ) + " document" + @If( @Elements( NoteIDList ) > 1; "s"; "" ) + "." + cPromptTab + cPromptTab +
cPromptNewLineTwo + cPromptTab + "Field:" + cPromptTab + cPromptTab + EditField +
cPromptNewLineOne + cPromptTab + "Data type/action: " + cPromptTab + DataType +
cPromptNewLineOne + cPromptTab +
@If( DataType = ("Implode":"Explode" ); "Separator: " + cPromptTab + Separator;
DataType = ("Text Left":"Text Left Back":"Text Right":"Text Right Back" ); "Search string: " + cPromptTab + ExtractValue;
DataType = ("Replace Substring":"Replace" ); "Search string: " + cPromptTab + FromRawValue + cPromptNewLineOne + cPromptTab + "Replace string: " + cPromptTab + RawValue;
DataType = cNoPromptList;
"";
"Value: " + cPromptTab + cPromptTab + @Text( RawValue ) ) +
cPromptNewLineTwo + "Would you like to continue?" );
@If( cEnableConfirmation;
@Do(
@StatusBar( @Explode( tmpPrompt; cPromptNewLineOne; @True ) );
@If( @Prompt( [YesNo]; EditFieldPromptTitle;
tmpPrompt );
""; @Return ( "" ) ) );
"" );

REM {Loop through selected docs taking each NoteIDList out of the list as it is processed};
DocUpdateCount := 0;
DocNavigationCount := 0;
@While( DocUpdateCount < @Elements( NoteIDList );

@If( @TextToNumber( @Text( @DocumentUniqueID ) ) != 0;
@Do(
NoteIDList := @Replace( NoteIDList; @NoteID; "" );
NotNoteIDList := NotNoteIDList : @NoteID;
@For( ef := 1; ef <= @Elements( EditField ); ef := ef + 1;
formulaResult := @Eval( DataTypeAction );
REMark := " **REM** The values entered above will be applied to all selected doc. If data conversion doesn't work then don't set field.";
@If( @IsError( formulaResult );
@Do(
tmpPrompt := "Error with NoteID of " + @NoteID + ". Continue?" + cPromptTab +
cPromptNewLineOne + cPromptTab + "Error: " + cPromptTab + cPromptTab + @Text( FormulaResult ) +
cPromptNewLineOne + cPromptTab + "Formula: " + cPromptTab + cPromptTab + DataTypeAction +
cPromptNewLineOne + cPromptTab + @If( @Contains( DataTypeAction; "EditField[ef]" ); "EditField[ef]:"; "Field:" + cPromptTab ) + cPromptTab + EditField[ef] +
cPromptNewLineOne + cPromptTab + "Data type/action: " + cPromptTab + DataType +
cPromptNewLineOne + cPromptTab +
@If( DataType = ("Replace Substring":"Replace" ); "FromRawValue: " + cPromptTab + @Text( FromRawValue )+ cPromptNewLineOne + cPromptTab + "RawValue: " + cPromptTab + @Text( RawValue );
DataType = cNoPromptList;
"";
"RawValue: " + cPromptTab + @Text( RawValue ) );
@StatusBar( @Explode( tmpPrompt; cPromptNewLineOne; @True ) );
@If( @Prompt( [YesNo];"Error - " + EditFieldPromptTitle; tmpPrompt );
ErrorNoteIDList := ErrorNoteIDList+ cArraySeparator + @Text( @NoteID );
@Return( @If( @Eval( cErrorCheckCode ) != "";
@StatusBar( @Explode( @Eval( cErrorInformation ); cPromptNewLineOne; @True ) ):
@Prompt( [Ok]; "Unable to Update - " + EditFieldPromptTitle; @Eval( cErrorInformation ) );
"" ) ) ) );
@SetField( EditField[ef]; formulaResult )
)
);
@If( DocNavigationCount > cMaxUpdatedDocuments;
NoteIDList := "";
@Do(
DocUpdateCount := DocUpdateCount + 1;
@Command([NavNextSelected]);
@UpdateFormulaContext;
REMark := " **REM** If we haven't processed all docs yet but the current doc is not in the NoteIDList list, keep looping ... if cnt exceeds MaxUpdatedDocuments assume infinite loop and stop ";
@If( DocUpdateCount < @Elements( NoteIDList ) & ( !@Member( @NoteID; NoteIDList ) ) & ( !@Member( @NoteID; NotNoteIDList) );
@While( (! @Member( @NoteID; NoteIDList ) & DocNavigationCount < cMaxUpdatedDocuments );
@Command([NavNextSelected]);
@UpdateFormulaContext;
DocNavigationCount := DocNavigationCount + 1);
"")
)
)
);
@Do( @Command([NavNextSelected]);
@UpdateFormulaContext )
)
);

@If( @Implode( @Unique( @Explode( NoteIDList : ErrorNoteIDList; cArraySeparator; @False ) ) ) != "";
@StatusBar( @Explode( @Eval( cErrorInformation ); cPromptNewLineOne; @True ) ):
@Prompt( [Ok]; "Unable to Update - " + EditFieldPromptTitle; @Eval( cErrorInformation ) );
"" );

@StatusBar( "Navigated through " + @Text( DocUpdateCount + DocNavigationCount ) + " documents." );
@StatusBar( "Performed '" + DataType + "' for '" + @Implode( EditField; ", " ) + "' field" + @If( @Elements( EditField ) > 1; "s "; " " ) + "on " + @Text( DocUpdateCount ) + " document" + @If( DocUpdateCount > 1; "s"; "" ) + "." )[/CODE]
 
Мы в соцсетях:

Обучение наступательной кибербезопасности в игровой форме. Начать игру!