@SetField

Question why does @SetField not work when the document is saved, but works after the document as been saved once.

Here is my code that appears in an action button:

FIELD SaveAction:=SaveAction;

@If(TCategory = “”; @Prompt([Ok];“Missing Data”;“Please select the main category before sending the reply”);@Success);

@If(TCategory = “”;@Return(“”);@Success);

@Command([EditDocument];“1”);

@Command([ViewRefreshFields]);

@SetField(“SaveAction”;“Reply being sent by --”);

@Command([ViewRefreshFields]);

@PostedCommand([FileSave]);

@PostedCommand([Compose];“”:“Reply”)

I tried without the temp variable and with.

Any suggestions would be helpful.

Thanks,

Subject: @SetField

When I use @setfield, I always get inconsistent results.

Try This

Field SaveAction := “Reply being sent by —“

You can also replace the string with a variable.

HTH

Subject: @SetField

From the Designer Help:

Assigns a value to a field stored within a document (use @Set for temporary variables). This is similar to using the FIELD keyword, except that @SetField can be used within another @function. If the field does not exist, this command creates it and applies the specified value to it.

With Release 6, you no longer need to declare the field receiving the assignment prior to setting its value with @SetField. For R5 or earlier clients, declare the field at the beginning of the formula, as follows:

FIELD Fieldname:=Fieldname;

The field that @SetField creates and assigns the specified value to if the specified field does not exist in the document is not visible to the user. You can remove a field added to a form this way using the @DeleteField function.


That means that even if the field doesn’t exist in the document, you don’t need to call it first using FIELD… Just put the value straight into it using @SetField($FieldName;$Value);, if it doesn’t exist, it will create it. You do need to save the document after if you want to keep the value as you did modify the field’s content. It’s the same as editing the form manually and changing the value in a field, if you don’t save it, it won’t stick obviously…

Subject: RE: @SetField

I appreciate all the suggestions and help however, I have tried setting a variable and tried not setting a variable. In further reading in the forum I saw that the @SetField has to be the first in the formula, is that true?

Here is my formula:

tmp := @Name([CN];@UserName);

@If(TCategory = “”; @Prompt([Ok];“Missing Data”;“Please select the main category before sending the reply”);@Success);

@If(TCategory = “”;@Return(“”);@Success);

@If(Assigned = “”;@SetField(“Assigned”;tmp);“”);

@Command([ViewRefreshFields]);

@SetField(“SaveAction”;"Info being sent by - ");

@Command([ViewRefreshFields]);

@PostedCommand([FileSave]);

@PostedCommand([Compose];“”:“RRForm”)

Now the field “SaveAction” is a subform put in the form.

Thanks again