Community

Problems truncating a field

Within a form I have a 15-char field ('Code') for a 13-char code which occasionally has a '-n' suffix (to indicate a duplicate). When I do a database lookup for this field I want to use only the first 13 chars, ie. dump the suffix if it exists.

I have created another field on the form called 'Code_13' and I am trying to write the first 13 chars of the 'Code' field to it via a Script rule (rather than a Custom script), but I cannot find a form that works. I have spent a lot of time looking at the 'Flexicapture Help' but I cannot find any relevant code samples - in fact any code samples at all.

I have tried scripts in the 'Code' field to push the value into the 'Code_13' field and scripts in the 'Code_13' field to pull the value from the 'Code' field.

I have tried many variations of script syntax, including:

me.Field("Code_13").Value = LEFT("Code",13)
me.Field("Code_13").Value = LEFT(me.Field("Code").Value,13)
Me.Field("Code_13") = LEFT(Field("Code").Value,13).ToString

me.Field("Code_13") = Code.Substring(0, 13)
me.Field("Code_13") = Field("Code".Substring(0, 13))

Field("FormName\Code") = "000000000012345"
Field("FormName\Code_13").Value = LEFT("FormName\Code",13)

I have had error messages saying the 'Code_13' field doesn't exist in spite of it being visible on the form (I must be missing something here) but I cannot find a way to enter '000000000012345' to the 'Code' field and get '0000000000123' to display in the 'Code_13' field. Can anyone tell me what the syntax should be?

Thanks,

Steve

Was this article helpful?

0 out of 0 found this helpful

Comments

2 comments

  • Avatar
    Alberto Torino
    Hello Steve:
    Did you inlcude 'Code_13' as an available field in your script rule?. (Uncheck the readonly option when including).
    Your sintax "me.Field("Code_13").Value = LEFT(me.Field("Code").Value,13)" should work fine.
    Regards,
    0
  • Avatar
    Permanently deleted user
    Thank you very much, Atorino

    As usual, once something like this is pointed out you feel like kicking yourself.

    I hadn't been adding the non-updated field (ie. 'Code') as an 'Available' field in the Rule Settings tab of the Script Properties screen. I suppose I thought that the tab was where you specified the field that the script amended, but not that all other referenced fields should be included there also. When I looked at the screen again in the light of your reply I realised that the section of the tab was actually headed 'Available Fields' and that I could add as many fields there as required. I think the Flexicapture Help could have been a little more proactive in making this clear, but it was still my mistake.

    With your help my script is now working.

    Thanks again,

    Steve
    0

Post is closed for comments.