Modifica dei campi in un documento via barra degli strumenti

TIPS ADMIN

  • 2 commenti
Mi è capitato spesso di dover cambiare al volo i valori di un documento.
Per farlo senza dover necessariamente ricorrere ad un agente ho usato il sistema che riporto di seguito per aggiungere un pulsante che svolge questa funzione dalla barra degli strumenti.

Ho trovato il tip su  http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256E3700680660

Per usarlo fare i seguenti passi:
Image:Modifica dei campi in un documento via barra degli strumenti
1. andare in File -> Preferenze -> Barra degli strumenti


Image:Modifica dei campi in un documento via barra degli strumenti

2. selezionare Personalizza barra (consiglio di scegliere la barra Universal);

3. trovare un'icona a proprio piacimento;

4. dargli un titolo;
Image:Modifica dei campi in un documento via barra degli strumenti

5. inserire nella parte del codice il codice seguente...
REM {Get a listing of all the fields on the current document};
List := @DocFields;
REM {Possible data types to choose from.};
REM {I called Number Integer because use keyboard to select what you want
with keyboard quicker.};
DataTypes := "Text" : "Date" : "Integer" : "Password" : "Name" : "Common
Name" : "**** Remove Field ****" : "Text Multi Value" : "Date Multi Value"
: "Integer Multi Value" : "Name Multi Value";
REM {Prompt for which field needs to be updated.};
EditField := @Prompt([OkCancelList]; "Select Field To Update"; "Select the
field you wish to update:"; ""; List : "**** ADD A NEW FIELD ****");
REM {If adding a new field, prompt for the field name};
NewFieldName := @If(EditField = "**** ADD A NEW FIELD ****";
@Prompt([OkCancelEdit]; "Enter Field Name"; "Enter the name of the new
field:"; ""); "");
CheckFieldName := @If(@IsMember(NewFieldName; List) & NewFieldName != "";
@Return(@Prompt([Ok]; "Already In List"; "The field " + NewFieldName + "
already exists on the document.")); "");
UpdateVariable := @If(NewFieldName = ""; ""; EditField := NewFieldName);
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};
REM { Picklist or any prompting needs to be used.};
DataType := @Prompt([OkCancelList] : [NoSort]; "Choose Data Type"; "Please
Select the correct data type or action for field: " + EditField; "Text";
DataTypes);
REM {For multi-valued fields, let the user choose the separator to use};
Separator := @If(@Contains(DataType; "Multi Value");
@Prompt([OkCancelList] : [NoSort]; "Choose Separator"; "Choose the
separator to split out your multiple values"; ":"; (":" : ";" : "+" : "-"
: "*")); "");
REM {Pull out the current value of the field};
CurrValue1 := @Eval(@Text(EditField));
CurrValue2 := @Abstract([TextOnly]; 254; ""; @Text(EditField));
CurrValue := @If(@IsNumber(CurrValue1) | @IsTime(CurrValue1);
@Implode(@Text(CurrValue1); Separator); CurrValue2 != ""; CurrValue2;
@Implode(@Text(CurrValue1); Separator));
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";
"Please enter the new desired value for: " + EditField + " seperated with
" + Separator + " for each value."; CurrValue);
@Prompt([OkCancelEdit]; "New Value"; "Please enter the new desired value
for: " + EditField + "."; CurrValue)
);
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 = "Password"; @SetField(EditField; @Password(RawValue));
DataType = "**** Remove Field ****"; @SetField(EditField; @DeleteField);
DataType = "Text Multi Value"; @SetField(EditField; @Explode(RawValue;
Separator));
DataType = "Date Multi Value"; @SetField(EditField;
@TextToTime(@Explode(RawValue; Separator)));
DataType = "Integer Multi Value";
@If(@IsError(@TextToNumber(@Explode(RawValue; Separator))); "";
@SetField(EditField; @TextToNumber(@Explode(RawValue; Separator))));
DataType = "Name Multi Value"; @SetField(EditField;
@Explode(@Name([Canonicalize]; RawValue); Separator));
@SetField(EditField; RawValue)
);
""



et voilà il gioco è fatto.

Funziona solo su un documento alla volta quindi non per cose di massa, ma l'ho trovata utile.

2 Commenti:

  • #1 glauco 09/20/2007 1:22:41 PM

    Questa versione ti permette anche di creare il campo se non esiste e funziona su tutti i doc selezionati (chiaramente modifica lo stesso campo per tutti i docuemnti)

    REM {Edit Document Fields 5.1.0 by Chad Schelfhout.};

    REM {Visit { Link } for the latest updates};

    REM {Constants};

    EditLastField := "edfLastField";

    EditLastFieldDataType := "edfLastFieldDataType";

    EditLastSeparator := "%~%";

    ProfileName := "ChadSmiley Tools";

    PromptTitle := @DbTitle + " - " + @ViewTitle;

    MaxSearchForSelectedDocs := 5520;

    MaxUpdatedDocuments := 1000;

    ArraySeperator := ";";

    NoteEntryLength := 11;

    PormptNewLine := @Char(13) + @Char(13);

    CategoryNoteID := "NT00000000";

    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) )$"+

    "Name|RawValue$"+

    "Name Multi Value|RawValue$"+

    "Common Name|@Name( [CN]; RawValue )$"+

    "CommonName 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( ProfileName ; EditLastField ; @UserName ) ; ArraySeperator ; @True ) ;

    REM {Get the list of forms and field that was updated using Edit Document Fields};

    FieldListForms := @Word( FieldList ; EditLastSeparator ; 1 );

    FieldListField := @Word( FieldList ; EditLastSeparator ; 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] ; PromptTitle ; "Select the field you wish to alter or enter a new field to add:" ; LastField ; @Trim( @Unique( List : LastField ) ) );

    EditField = "" );

    EditFieldPromptTitle := EditField + " - " + PromptTitle;

    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( ProfileName ; EditLastFieldDataType ; @UserName ) ; ArraySeperator ; @True ) ;

    FormFieldListFormField := @Word( FormFieldList ; EditLastSeparator ; 1 );

    FormFieldListDataType := @Word( FormFieldList ; EditLastSeparator ; 2 );

    FormFieldListFormulaCode := @Word( FormFieldList ; EditLastSeparator ; 3 );

    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 ) ) ; ArraySeperator );

    @Text( @GetField( EditField ) ) )

    );

    REM {Prompt for additional fields and determine the string that they are searching for.};

    @If( DataType = @Explode( "Replace Substring;Replace" ; ArraySeperator ) ;

    @Do( EditField := @Unique( EditField : @Prompt( [OkCancelListMult] ; PromptTitle ; "Select any addtional fields you wish to alter:" ; EditField ; List ) );

    FromRawValue := @Prompt( [OkCancelEdit] ; EditFieldPromptTitle ; "Please enter the text (Case sensitive) to search for in: " + @Implode( EditField ; ", " ) + "." ; "" ) );

    @Do( EditField := EditField;

    FromRawValue := "" )

    );

    Separator := @If( DataType = @Explode( "Implode;Explode" ; ArraySeperator ) ;

    @Prompt( [OkCancelEdit] ; PromptTitle ; "Enter the " + @If( DataType = "Implode" ; "separator" ; "separators" ) + ArraySeperator ; "" );

    ArraySeperator );

    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 = @Explode( "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" ; ArraySeperator ) ; "" ;

    @Contains( DataType ; "Multi Value" ) ; @Prompt( [OkCancelEdit] ; EditFieldPromptTitle; "Please enter the new desired value for: " + @Implode( EditField ; ", " ) + "." + PormptNewLine + "Seperated with ; for each value." ; OriginalValue ) ;

    @Contains( DataType ; "+ Append Values" ) ; @Prompt( [OkCancelEdit] ; EditFieldPromptTitle; "Please enter values to append: " + @Implode( EditField ; ", " ) + "." + PormptNewLine + "Seperated with ; for each value." ; "" ) ;

    DataType = @Explode("Replace Substring;Replace" ; ArraySeperator ) ; @Prompt( [OkCancelEdit] ; EditFieldPromptTitle ; "Please enter the text to repalce with in: " + EditField + "." ; "" ) ;

    DataType = "Formula" ; @Do( @DoWhile(

    OriginalValue := @Prompt( [OkCancelEdit] ; EditFieldPromptTitle ; "Please enter the new desired formula for: " + EditField + "." ; OriginalValue ) ;

    tempReturnCheck := @CheckFormulaSyntax( OriginalValue );

    @If( tempReturnCheck != "1"; @Prompt( [Ok] ; "Invalid Formula" ; @Text( tempReturnCheck ) ) ; "" );

    tempReturnCheck != "1" );

    OriginalValue );

    @Prompt( [OkCancelEdit] ; EditFieldPromptTitle ; "Please enter the new desired value for: " + EditField + "." ; OriginalValue )

    );

    REM {Store Field in Profile doc};

    @SetProfileField( ProfileName ; EditLastField ; @Unique( @Explode( FieldList : ( Form + EditLastSeparator + EditField[1] ) ; ArraySeperator ; @False ) ); @UserName );

    REM {Store Data Type of Field in Profile doc};

    @SetProfileField( ProfileName ; EditLastFieldDataType ; @Unique( @Explode( FormFieldList : ( Form + EditField[1] + EditLastSeparator + DataType + EditLastSeparator + @If( DataType = "Formula" ; RawValue ; FormFieldListFormulaCode ) ) ; ArraySeperator ; @False ) ) ; @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 );

    @Command([NavNextSelected]);

    @UpdateFormulaContext;

    REM {Start Looping Selected documents};

    @While( ( @Left( NoteIDList ; NoteEntryLength ) != ( @Text( @NoteID + ArraySeperator ) ) ) & ( @Length( NoteIDList ) < MaxSearchForSelectedDocs ) ;

    NoteIDList := NoteIDList + ArraySeperator + @Text( @NoteID );

    NoteIDList := @ReplaceSubstring( NoteIDList ; CategoryNoteID + ArraySeperator ; "" );

    @Command([NavNextSelected]);

    @UpdateFormulaContext

    );

    NoteIDList := @ReplaceSubstring( NoteIDList ; CategoryNoteID ; "" );

    NoteIDList := @Unique( @Explode( NoteIDList ; ArraySeperator ; @False ) );

    @StatusBar( "Found " + @Text( @Elements( NoteIDList ) ) + " documents." );

    NotNoteIDList := "";

    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 );

    @Return( @Prompt( [Ok] ;"Error" ; @Text( FormulaResult ) ) );

    @SetField( EditField[ef] ; formulaResult )

    )

    );

    @If( DocNavigationCount > MaxUpdatedDocuments ;

    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 < MaxUpdatedDocuments );

    @Command([NavNextSelected]);

    @UpdateFormulaContext;

    DocNavigationCount := DocNavigationCount + 1);

    "")

    )

    )

    );

    @Do( @Command([NavNextSelected]);

    @UpdateFormulaContext )

    )

    );

    @If( @Implode( @Unique( @Explode( NoteIDList ; ArraySeperator ; @False ) ) ) != "" ; @StatusBar( "Unable to update the following documents: " + @Implode( @Unique( @Explode( NoteIDList ; ArraySeperator ; @False ) ) ; ", " ) + "." ); "" );

    @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" ; "" ) + "." )

  • #2 marinos 09/20/2007 9:49:15 AM

    Ottimo. Se potesse determinare il tipo di campo sarebbe il massimo. Grazie. Marino

Commenta articolo
 

Questo spazio web è stato creato da per un uso pubblico e gratuito. Qualsiasi tipo di collaborazione sarà ben accetta.
Per maggiori informazioni, scrivete a info@dominopoint.it

About Dominopoint
Social
Dominopoint social presence: