Script that DOES NOT RUN per Company

I have the following script that pops up a message in Company Code HMC for users other than TAG when a certain UD is populated.  Works fine....

retVal = 0
Set oUI = oSession.AsObject(oSession.UI)
TRANS = ""
USER = ""
COMPANYCODE = ""
retVal = oBusObj.GetValue("UDF_TRANSMITTED_TO_WAREHOUSE$", TRANS)
USER = oSession.UserCode
COMPANYCODE = oSession.CompanyCode
If USER <> "TAG" THEN
If COMPANYCODE = "HMC" THEN
If TRANS= "Y" THEN
  sMsg = "WARNING: CANNOT CHANGE!  This line has already been transmitted."
  retVal = oScript.SetError(sMsg)
End If
End If
End If
...my question involves when the script is invoked.  I went into User-Defined Field and Table Maintenance, selected the User-Defined Scripts button on the right and "told" Sage 100 when to run the script.  However, I do not want the script to run at all in a certain Company Code.  Is this even possible?  I know I set the script above to only perform in HMC however it is still invoked in other Company Codes and I want to prevent that.  In other words, in Company Code TST I do not get the Message from the script but I am sure the script is still invoked.
Thanks!
Parents
  • 0

    Wrap your whole script inside an if statement.  For example:

    if oSession.CompanyCode = "TST" then

    ...

    end if

  • 0 in reply to Kevin M

    Thanks but the script is invoked, right?  In other words the script will still run in TST which is what I want to avoid.  Imagine a Company Code on the following screen so that I could control which Company invokes the script.  Does anyone know how to that?

  • 0 in reply to ssafm

    @ssafm

    There is no way to turn off an individual script from being invoked for a company.  You can turn scripting off for the entire company in Company Maintenance however.  

    Library Master/Company Maintenance

    Select your company code and go to the "2. Preferences" tab and un-check the "Allow External Access".  This will turn off all scripts for the entire company. 

    Not sure if that's what you want to do or not.  Otherwise, what Kevin is proposing is the recommendation for not executing the script logic for a specific company.

    E

  • 0 in reply to ssafm

    Why does it matter as long as the invoked script in the wrong company code doesn't do anything?

  • 0 in reply to Kevin M

    Generally speaking I would agree with you Kevin,  however I can imagine that it could slow down processing because it still has to walk through the script from beginning to end even if it skips executing statements?   I've never done a test to that point so I don't know if it could make a significant difference or not.

  • 0 in reply to TomTarget

    That is why I put the company filter as the first non-comment line in the script.  If that is false, it just skips to the associated end if, and I've never noticed a performance hit using this method.

  • 0 in reply to Kevin M

    I do exactly the same thing.  Since it is not truly a "compiled" code,  I assume it still has to at least "read" down the script to find the END IF.   In most cases the code won't be long enough to have any impact on performance.  I once did a script that was several pages long but it pretty much ran infrequently so it really wouldn't have made a dramatic difference.  I have often wondered it that script was run more frequently whether there would have been a noticeable performance hit.

    I also do a similar if for the user so when I am initially installing it on a client system I can make it run only for me so that I can do final testing in the client's environment.

  • 0 in reply to Kevin M

    Turns out the fact that the script is invoked breaks Service Pro from MSI.  We verified it by completely removing the script from the client install.  Service Pro uses SDATA (which I know very little about) and MSI said that often SDATA and Sage 100 scripts collide...

Reply
  • 0 in reply to Kevin M

    Turns out the fact that the script is invoked breaks Service Pro from MSI.  We verified it by completely removing the script from the client install.  Service Pro uses SDATA (which I know very little about) and MSI said that often SDATA and Sage 100 scripts collide...

Children
  • 0 in reply to ssafm

    The scripts' presence itself collides?  or what the script does versus what the code from Service Pro does collides?  Does Service Pro use a specific user to execute it's logic, something that you can skip your script based on?  The user-defined scripts should execute okay when using SDATA (which is just using BOI by the way), depending on what is actually being done.    The above script should be based on whether there is a UI present, as you are displaying a message box.  This should always be taken into consideration when adding messages during a script.  The script is attached at the business layer.

    Here is the recommended method for testing for the presence of a UI

    ' Recommended UI detection - if no UI then do not use any type of MsgBox or other UI.

    ' This is important because if your script pops a MsgBox during an automated process

    ' such as an import, or webservices running as a background process, the service will hang.

     

    If (IsObject(oUIObj)) Then

         ' This is either a UI Event Script or a Button link script

        ' – because oUIObj is directly available.

         MASUI = True

    Else

         ' This is a Business Event script. Must test if UI is present/available

         MASUI = CBool(oScript.UIObj)

         If (MASUI) Then

                 ' Need to get my own handle to access oUIObj functionality such as InvokeChange(), InvokeLookup(), Etc.

                 Set myUIObj = oSession.AsObject(oScript.UIObj)

         End If

    End If

    If MASUI Then

         ' Ok to Message box

          oSession.AsObject(oSession.UI).MessageBox "", "Whatever"

    ...

    End If

    Hope this helps

    Elliott