Tip

Edit data without writing an agent

If you have a need to update data for a document and you always create an agent then this code is for you! All you need to do is paste this code into a SmartIcon.

There are five simple steps to using this code:
1) Select the document to update.
2) Click on the SmartIcon.
3) Select the field to update.
4) Select the data type or action to be performed
5) Enter a new .

Limitations:
1) Only perform the operation on one document at a time
2) Field value is limited to 254 because of the @Prompt limitations
3) Using Abstract for Multi value removes the multi value separator

The data types or actions are:
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 "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 )
);
""

This was first published in November 2001

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.