Computed when composed changing again

I’ve searched the forum and see that there is a lot of info on CWC fields.I have one that is supposed to grab the doc creators initials and save it for use on a view.

I created a hidden field called takeByInitials, CWC, with formula of:

@Left(@Name([CN];@UserName); 1) + @MiddleBack(@Name([CN];@UserName); " "; 1)

This computes the initials of the creator based on the common name.

I don’t want this field to change, so users can tell who first opened this doument.

That works fine, except some of the docs have changed to one of the other users who have made revisions to the document (usually the second revision), but I can’t recreate it.

After reading a bunch, I’ve changed the code to:

@If(@IsNewDoc;

(@Left(@Name([CN];@UserName); 1) + @MiddleBack(@Name([CN];@UserName); " "; 1));

(@Left(TakenBy; 1) + @MiddleBack(TakenBy; " "; 1)))

TakenBy is a visible computed field that holds the creators common name “@Name([CN];@UserName)”.

This too seems to work, except that if I go back to a document that has the wrong initials in it, the code doesn’t change back to the creators initials.

I think I understood that a CWC field could be changed later using code within the document.

BTW, I’ve also tried to change the value by using an @SetField(takenByInitials;(@Left(TakenBy; 1) + @MiddleBack(TakenBy; " "; 1)) in another field later on in the document, to no avail.

Any other ideas, or am I missing something obvious?

Thanks in advance,

Bob

Subject: computed when composed changing again

Computed when Composed fields work as follows.

If a document (either new or existing) is opened with the form, and that field does not already exist on the document, compute the field. If it does exist, leave it alone.

@Left(@Name([CN];@UserName); 1) + @MiddleBack(@Name([CN];@UserName); " "; 1)

This computes the initials of the creator based on the common name.

I don’t want this field to change, so users can tell who first opened this doument.

That looks like the correct formula, and will work for new documents that are being created. It won’t work for existing documents that don’t have the field.

That works fine, except some of the docs have changed to one of the other users who have made revisions to the document (usually the second revision), but I can’t recreate it.

That sounds like these documents existed before you added the CWC to the form. So when they are being edited for the first time, the CWC code kicks off, using the name of the editor, not necessaraly who originaly created the document.

After reading a bunch, I’ve changed the code to:

@If(@IsNewDoc;

(@Left(@Name([CN];@UserName); 1) + @MiddleBack(@Name([CN];@UserName); " "; 1));

(@Left(TakenBy; 1) + @MiddleBack(TakenBy; " "; 1)))

TakenBy is a visible computed field that holds the creators common name “@Name([CN];@UserName)”.

This too seems to work, except that if I go back to a document that has the wrong initials in it, the code doesn’t change back to the creators initials.

Does TakenBy actualy have the creators name in it for an existing document ? If so, that should work. However, I’m guessing that they don’t, and it’s being calculated to the first person who edits the documents.

I think I understood that a CWC field could be changed later using code within the document.

That’s correct. Code can modify CWC fields.

As a rule-of-thumb : Whenever you add a computed field to a form, you need to think about existing records. Do they need to be updated with a value, or is it sufficient to allow the computation to happen when they are next edited ?

In your case, when you added your creator initial field, you have the problem that existing documents don’t know who the creator was, as Notes does not store that information. (It may be extracted from the $UpdatedBy field if you want to go that route) Thus, your field is actually capturing the initials of the first person to edit the document.

Subject: RE: computed when composed changing again

Thanks for the detailed response, but…These are all new docs that did have the CWC field in them when composed. The TakenBy field also is populated when the form is first opened, and saved in the new doc.

That’s what’s puzzling, these fields have been in there and working, but I am noticing that some of the CWC takenbyinitials are changing somehow. And the new code that should change them, to the existing TakenBy name, doesn’t.

Thanks,

Bob

Subject: RE: computed when composed changing again

In that case, I’d start looking for logic in the application that might be modifying those fields. What you are describing should not be happening based on just the form field definitions.

Subject: RE: computed when composed changing again

Thanks for your response,I am working on an old form with lots of programming in it, but the takenByInitials CWC field I just added last month to provide new info for a new view.

I’ll keep looking through this form and other areas that might interact.

Thanks for verifying my thoughts that I had the fields programmed correctly.

Bob