1 Reply Latest reply on Mar 16, 2012 2:18 PM by philmodjunk

    Help with a script.

    MarcMcCall

      Title

      Help with a script.

      Post

      Hey All,

       

      I could use a little help with a script.  I have a SSN field with an on object modify bullet control script set on it.  When something is typed into the field it is sent to another field and stored, and a bullet replaces what is typed in the original field.  I need to import a bunch of data into the DB, but do not want to import it into the store field, and if I import it into the field with the script set on it it will not trigger the script, transfer the data and show the bullets.  I have tested using a setvariable setfield scripts on another script that uses that sends data to that field from a popup window, and it would not work right, I had to use the copy paste into the field and after the paste it places my cursor in the field at the end of the script and on validate it triggers the transfer and bullet script just fine.  So what I think I would like to do, is when I import the data set up an import field to temporarilly store the SSN number and after all the records are imported, run a copy paste script that will copy from the temp field and paste in the field with the script trigger set up on it to activate the bullets and tranfer the data.  unless someone has a better idea than this.  I particularly would like to do something like this, because admin access will be allowed viewing of the SSN store field and if the SSN number is wrong, the other field will not control the store field if the script wasnt used to move the data.  I didn't write the script, just adapted it to my field.  

      Bellow is the script I have set to trigger on the field with this parrameter "GetFieldName(T01_ACCOUNTS::SSN_Store)"

       

      • Set Error Capture [ On ]
      • Allow User Abort [ Off ]
      • #BULLET CONTROL
      • #to run as an OnObjectModify event.
      • #Capture status values
      • Set Variable [ $tring; Value:Get(ActiveFieldContents) ]
      • Set Variable [ $bulletField; Value:GetFieldName(GetField(Get(ActiveFieldName))) ]
      • Set Variable [ $added; Value:Let([ Nt = Substitute($tring; "•"; ""); c1 = Left(Nt; 1); p1 = Position($tring; c1; 1; 1); cN = Right(Nt; 1); pN = Position($tring; cN; Length($tring); -1)]; If(p1; Middle($tring; p1; pN - p1 + 1)) ) ]
      • Set Variable [ $cursor; Value:Get(ActiveSelectionStart) ]
      • If [ IsEmpty($added) and Length($tring) < Length(GetField(Get(ScriptParameter))) ]
      • #delete text
      • Set Field By Name [ Get(ScriptParameter); Let( Source = GetField(Get(ScriptParameter)); Left(Source; $cursor - 1) & Right(Source; Length($tring) - $cursor + 1) ) ]
      • Else If [ IsEmpty($added) ]
      • #Reject bullets
      • Set Field By Name [ $bulletField; Let([ SLnth = Length(GetField(Get(ScriptParameter))); $over = Length($tring) - SLnth]; If(SLnth; Substitute(10^SLnth - 1; "9"; "•")) ) ]
      • Else
      • #Insert new text
      • Set Field By Name [ Get(ScriptParameter); Let( Source = GetField(Get(ScriptParameter)); Left(Source; $cursor - 1 - Length($added)) & $added & Right(Source; Length($tring) - $cursor + 1) ) ]
      • Set Field By Name [ $bulletField; Substitute(10^Length($tring) - 1; "9"; "•") ]
      • End If
      • Set Selection [ Start Position: $cursor - $over; End Position: $cursor - 1 - $over ]
      • ##

        • 1. Re: Help with a script.
          philmodjunk

          If you are using import records to import the data, you don't need to use a script trigger at all. The import records action produces a found set of the imported data and then you can either loop through that found set or use Replace Field Contents to update fields in the set of imported records. In some cases, this can even be handled with an auto-entered calculation if you enable auto-enter options for the import.

          This expression caught my eye:

          Let([ Nt = Substitute($tring; "•"; "");
                   c1 = Left(Nt; 1);
                   p1 = Position($tring; c1; 1; 1);
                   cN = Right(Nt; 1);
                   pN = Position($tring; cN; Length($tring); -1)
                 ];
                 If(p1; Middle($tring; p1; pN - p1 + 1))
                )

          As fara as I can tell, If I've interpreted it correctly, it takes the contents of $tring and deletes all bullet characters. This could be done with just the first part: Nt = Substitute($tring; "•"; "")

          The rest of the expression doesn't seem to modify the results produced by the first step.

          The following script would filter out all bullet characters, storing what remains as the SSN in the "Store" field while leaving an equivalent number of bullet characters behind in the original field:

          Go to record/request/page [first]
          Loop
             Set Variable  [$SSN ; value: Filter ( T01_ACCOUNTS::SSN_Entry ; -9876543210 // leave out the - if you only want digits ) ]
             Set Field [ T01_ACCOUNTS::SSN_Store ; $SSN ]
             Set Field [T01_ACCOUNTS::SSN_Entry ; Substitute ( 10^Length ( $SSN ) - 1 ; 9 ; "•" ) ]
             Go to Record/Request/Page [next ; exit after last]
          End Loop

          For manually entered SSN's I'd use the OnObjectKeystroke trigger to move the entered data digit by digit to the store field, entering a matching bullet character into the Entry field. Back space, and delete keys can be detected and the approprate changes to both fields implemented. Exit Script [False] can be used at the end of such a script to keep the entered character from every appearing in the visible Entry field.