Edit Document Fields 4.1.0 Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
REM {Edit Document Fields 4.1.0 by Chad Schelfhout.};
REM {Visit http://www.chadsmiley.com/EditDocumentFields for the latest updates};
 
REM {Get a listing of all the fields on the current document};
List := @Sort( @DocFields );
REM {Reusable title.};
PromptTitle := @DbTitle + " - " + @ViewTitle;
REM {Possible data types to choose from.};
REM {I called Number Integer because use keyboard to select what you want with keyboard quicker.};
DataTypes := @Explode( "Text,Date,Integer,Password,Name,Common Name,Abbreviate Name,Remove Field,Text Multi Value,Date Multi Value,Integer Multi Value,Name Multi Value,Common Name Multi Value,Abbreviate Name Multi Value,Upper Case Text,Lower Case Text,Proper Case Text,Upper Case Text Multi Value,Lower Case Text Multi Value,Proper Case Text Multi Value,+ Append Values,Sort Ascending,Sort Descending,Replace,Replace Substring,Unique,Implode,Explode" ; "," ); 
REM {Prompt for which field needs to be updated.};
@DoWhile(
	EditField := @Prompt( [OkCancelEditCombo] ; PromptTitle ; "Select the field you wish to alter:" ; @Environment( "edfLastField" ) ; List );
	EditField = "" );
@Environment( "edfLastField"; EditField );
REM {Based on the field that was selected determine the current field type using the GetField function.};
DefaultDataType :=
	@If(
		@IsNumber( @GetField( EditField ) ) ;
			@If( @Count( @GetField( EditField ) ) > 1 ;
				"Integer Multi Value";
				"Integer" ) ;
		@IsTime( @GetField( EditField ) ) ;
			@If( @Count( @GetField( EditField ) ) > 1 ;
				"Date Multi Value";
				"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};
REM {This needs to be done before value prompt to determine if the Picklist or any prompting needs to be used.};
DataType := @Prompt( [OkCancelList] ; EditField + " - " + PromptTitle; "Please select the correct data type or action for field: " + EditField + "."; DefaultDataType ; DataTypes );
REM {Format the original value as text because the @Prompt command requires text.};
OriginalValue := @If( @Contains( DefaultDataType ; "Multi Value" ) ; @Implode( @Text( @GetField( EditField ) ) ; ";" ); @Text( @GetField( EditField ) ) );
EditField := @If( DataType = "Replace Substring" | DataType = "Replace" ; @Prompt( [OkCancelListMult] ; PromptTitle ; "Select any addtional fields you wish to alter:" ; EditField ; List ); EditField );
REM {Determine the string that they are searching for.};
FromRawValue := @If( DataType = "Replace Substring" | DataType = "Replace" ; @Prompt( [OkCancelEdit] ; EditField + " - " + PromptTitle ; "Please enter the text to search for in: " + @Implode( EditField ; ", " ) + "." ; "" ) ; "" ) ;
ReplaceFailure := @False;
Separator := @If( DataType = "Implode" | DataType = "Explode" ; @Prompt( [OkCancelEdit] ; PromptTitle ; "Enter the " + @If( DataType = "Implode" ; "separator" ; "separators" ) + ":" ; "" ); ";" );
REM {Based on what type of data is being entered different prompts will happen if any at all.};
REM {Use the GetField function instead of using Abstract which always returned text and did not convert non text data.};
RawValue := @If(
	@Contains( DataType ; "Name Multi Value" );	@PickList( [Name] );
	@Contains( DataType ; "Name" ) ;	@PickList( [Name] : [Single] );
	DataType = ( "Remove Field":"Unique":"Sort Ascending":"Sort Descending":"Implode":"Explode") ; 	"" ;
	@Contains( DataType ; "Multi Value" ); 	@Prompt( [OkCancelEdit] ; EditField + " - " + PromptTitle; "Please enter the new desired value for: " + @Implode( EditField ; ", " ) + "." + @Char(13) + @Char(13) + "Seperated with ; for each value." ; OriginalValue ) ;
	@Contains( DataType ; "+ Append Values" ); 	@Prompt( [OkCancelEdit] ; EditField + " - " + PromptTitle; "Please enter values to append: " + @Implode( EditField ; ", " ) + "." + @Char(13) + @Char(13) + "Seperated with ; for each value." ; "" ) ;
	DataType = ("Replace Substring":"Replace") ; 	@Prompt( [OkCancelEdit] ; EditField + " - " + PromptTitle ; "Please enter the text to repalce with in: " + EditField + "." ; "" ) ;
	@Prompt( [OkCancelEdit] ; EditField + " - " + PromptTitle ; "Please enter the new desired value for: " + EditField + "." ; OriginalValue )
	);
REM {Add each document's UNID to a growing list, check each doc against the list as };
REM {we navigate through selected docs; Once a duplicate is found all should be processed, end loop};
REM {The values entered above will be applied to all selected docs ...};
REM {If data conversion doesn't work then don't set field.};
UNID:="";
@While(! @Contains(UNID;@Text(@DocumentUniqueID) + ":" );
	UNID:= UNID + ":" + @Text(@DocumentUniqueID);
	@For( ef := 1;
		ef <= @Elements(EditField);
		ef := ef + 1;
		FieldDataType := @If( @IsNumber( @GetField( EditField[ef] ) ) ; @If( @Count( @GetField( EditField[ef]) ) > 1 ; "Integer Multi Value"; "Integer" ) ; @IsTime( @GetField( EditField[ef] ) ) ; @If( @Count( @GetField( EditField[ef]) ) > 1 ; "Date Multi Value"; "Date" ) ; @If( @Count( @GetField( EditField[ef]) ) > 1 ; "Text Multi Value"; "Text" ) );
FieldDataType := @IfError( DefaultDataType ; "Text" );
		@If(
		DataType = "Date" ; @If( @IsError( @ToTime( RawValue ) ) ;
			"" ;
			@SetField( EditField[ef] ; @ToTime( RawValue ) ) );
		DataType = "Integer" ; @If( @IsError( @TextToNumber( RawValue ) ) ;
			"" ;
			@SetField( EditField[ef] ; @TextToNumber( RawValue ) ) ) ;
		DataType = "Common Name" ; @SetField( EditField[ef] ; @Name( [CN]; RawValue ) ) ;
		DataType = "Abbreviate Name" ; @SetField( EditField[ef] ; @Name( [Abbreviate]; RawValue ) ) ;
		DataType = "Password" ; @SetField( EditField[ef] ; @Password( RawValue ) ) ;
		DataType = "Remove Field" ; @SetField( EditField[ef] ; @DeleteField ) ;
		DataType = "Text Multi Value" ; @SetField( EditField[ef] ; @Explode( RawValue ; ";" ) ) ;
		DataType = "+ Append Values" ; @If(
			@Contains(DefaultDataType; "Date");
				@If( @IsError( @ToTime( RawValue ) ) ;
					"" ;
					@SetField( EditField[ef] ; @GetField(EditField[ef]) : @TextToTime( @Explode( RawValue ; ";" ) ) ) ) ;
			@Contains(DefaultDataType; "Integer");
				@If( @IsError( @TextToNumber( @Explode( RawValue ; ";" ) ) ) ;
					"" ;
					@SetField( EditField[ef] ; @GetField(EditField[ef]) : @TextToNumber( @Explode( RawValue ; ";" ) ) ) ) ;
			@SetField( EditField[ef] ; @GetField(EditField[ef]) : @Explode( RawValue ; ";" ) ) );
		DataType = "Date Multi Value" ; @If( @IsError( @ToTime( RawValue ) ) ;
			"" ;
			@SetField( EditField[ef] ; @TextToTime( @Explode( RawValue ; ";" ) ) ) ) ;
		DataType = "Integer Multi Value" ; @If( @IsError( @TextToNumber( @Explode( RawValue ; ";" ) ) ) ;
			"" ;
			@SetField( EditField[ef] ; @TextToNumber( @Explode( RawValue ; ";" ) ) ) ) ;
		DataType = "Name Multi Value" ; @SetField( EditField[ef] ; @Explode( RawValue ; ":" ) ) ;
		DataType = "Common Name Multi Value" ; @SetField( EditField[ef] ; @Name( [CN]; @Explode( RawValue ; ":" ) ) );
		DataType = "Abbreviate Name Multi Value" ; @SetField( EditField[ef] ; @Name( [Abbreviate]; @Explode( RawValue ; ":" ) ) );
		DataType = "Upper Case Text" ; @If( @Contains( DefaultDataType ; "Text" ) ; @SetField( EditField[ef] ; @UpperCase( RawValue ) ) ; "" );
		DataType = "Lower Case Text" ; @If( @Contains( DefaultDataType ; "Text" ) ; @SetField( EditField[ef] ; @LowerCase( RawValue ) ); "" );
		DataType = "Proper Case Text" ; @If( @Contains( DefaultDataType ; "Text" ) ; @SetField( EditField[ef] ; @ProperCase( RawValue ) ); "" );
		DataType = "Upper Case Text Multi Value" ; @If( @Contains( DefaultDataType ; "Text" ) ; @SetField( EditField[ef] ; @UpperCase( @Explode( RawValue ; ";" ) ) ); "" );
		DataType = "Lower Case Text Multi Value" ; @If( @Contains( DefaultDataType ; "Text" ) ; @SetField( EditField[ef] ; @LowerCase( @Explode( RawValue ; ";" ) ) ); "" );
		DataType = "Proper Case Text Multi Value" ; @If( @Contains( DefaultDataType ; "Text" ) ; @SetField( EditField[ef] ; @ProperCase( @Explode( RawValue ; ";" ) ) ); "" );
		DataType = "Unique" ; @SetField( EditField[ef] ; @Unique( @GetField( EditField[ef] ) ) );
		DataType = "Implode" ; @SetField( EditField[ef] ; @Implode( @GetField( EditField[ef] ) ; Separator ) );
		DataType = "Explode" ; @SetField( EditField[ef] ; @Explode( @GetField( EditField[ef] ) ; Separator ) );
		DataType = "Sort Ascending" ; @SetField( EditField[ef] ; @Sort( @GetField( EditField[ef] )  ; [Ascending] ) );
		DataType = "Sort Descending" ; @SetField( EditField[ef] ; @Sort( @GetField( EditField[ef] )  ; [Descending] ) );
		DataType = "Replace Substring" ; @If( @Contains( FieldDataType ; "Text" ) ;
			@SetField( EditField[ef] ; @ReplaceSubstring( @GetField( EditField[ef] ) ; FromRawValue ; RawValue ) ) ;
			ReplaceFailure := @True ) ;
		DataType = "Replace" ; @If( @Contains( FieldDataType ; "Text" ) ;
			@SetField( EditField[ef] ; @Explode( @Replace( @GetField( EditField[ef] ) ; FromRawValue ; RawValue ) ; ";" ) ) ;
		ReplaceFailure := @True );
	@SetField( EditField[ef] ; RawValue )
		)
	);
	@Command([NavNextSelected]);
	@UpdateFormulaContext);
	@If( ReplaceFailure ; @Prompt( [Ok]  ; "Unable to Replace" ; "Unable to replace some or all because the original value is not text.")  ; "" );
"";
@StatusBar( "Peformed '" + DataType + "' for '" + @Implode( EditField ; ", " ) + "' field" + @If( @Elements( EditField ) >  1; "s " ; " " ) + "on " + @Text( @Elements( @Explode(UNID ; ";" ; @False ) ) ) + " document" + @If( @Elements( @Explode(UNID ; ";" ; @False ) ) > 1 ; "s" ; "" ) + "." );

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">