Trying to set PO ROG batch as "Private" through scripting

SOLVED

Hey all,


I'm having a fun time trying to do a seemingly easy task.  We have a customer that would like to set all their PO batches to be private when they are entered, even when they are not selected to be when they are created.

I figured I could set a flag or edit the Entry Batch screen to force that through Custom office, but it turns out that's a Library Master screen and I cannot edit it.  Bummer.

So, I assume my only choice would be through scripting, which I'm not good at but with which I'm willing to tinker.

I thought I could create a script to post-validate on the PO number since the batch number would have been entered by then.
This is that I have

nBatch = 0
retVal = 0
oBatch = 0

retVal = oBusObj.GetValue("BatchNo$",nBatch)

Set oSS = oScript.NewObject("SY_Session")
Set oScript = CreateObject("ProvideX.Script")
Set oBatch = oScript.NewObject("SY_BatchManager_bus", oSS, "P/O", "01", nBatch)

retVal = oBatch.nSetKeyValue("BatchNo$",nBatch)
if retVal = 0 Then
MsgBox (oBatch.sLastErrorMsg)
else
retVal = oBusObj.SetValue("PrivateBatch$","N")

End if

However, I get an error 88 invalid/unknown property name.  Object doesn't support this property or method: 'oScript.NewObject"
I'm sure I'm royally messing it up but hoping someone may shed some light on this.

Also, I'm not married to this idea if there is another way of going about this.

Thanks in advance

Parents
  • 0

    It looks like you are confusing what's needed between an external script (executed from outside the sage 100 desktop) and an internal script (triggered by a button added via Custom Office or a table or UI event script).

    If you look at a given object's page on the online file layouts and object reference, you should see that if they deal with batches, they should inherit SY_BatchDataEntry which is detailed on this page.

    http://help-sage100.na.sage.com/2019/FLOR/#Object_Reference/BaseSystem/SY_BatchDataEntry.htm

    The above object includes a SelectNewBatch method which can be used to mark a newly created batch as private by passing "Y" in the second argument. I do not know if this can be used on existing batches,

    The above object also includes a GetBatchHandle method which if you pass the UI object handle of the current object, it should return the handle to the batch manager object which i assume would be SY_BatchManager_Bus and should be on the current batch record, at that point i would think you would just need to use SetValue on the PrivateBatch$ field but i'm not sure if that will require a Write method as well, and if it does, i'm not sure if it will require being followed up with a SetKey to get the batch record back in an edit state for the entry task.

  • +1 in reply to David Speck
    verified answer

    Just following up, the SelectNewBatch does not seem to work on existing batches and i could not get GetBatchHandle to work with current UI handle.

    One way to do this is with the following.

    I do not know for sure what kind of effect this might have on other standard functionality within the session this occurs under but it does achieve what you want.

    If oBusObj.BatchEnabled = 1 Then
        oBatch_Bus = 0 : oBusObj.GetValue "coBatch", oBatch_Bus
        If oBatch_Bus > 0 Then
            Set oBatch_Bus = oSession.AsObject(oBatch_Bus)
            PrivateBatch = "" : oBatch_Bus.GetValue "PrivateBatch$", PrivateBatch
            If PrivateBatch <> "Y" Then
                oBatch_Bus.SetValue "PrivateBatch$", "Y"
                oBatch_Bus.Write
                oBatch_Bus.SetKey oBatch_Bus.GetKey() ' I do not know for sure whether this line is really needed but it makes sure to put the batch back into an edit state after the Write.
            End If
            Set oBatch_Bus = Nothing
        End If
    End If

Reply
  • +1 in reply to David Speck
    verified answer

    Just following up, the SelectNewBatch does not seem to work on existing batches and i could not get GetBatchHandle to work with current UI handle.

    One way to do this is with the following.

    I do not know for sure what kind of effect this might have on other standard functionality within the session this occurs under but it does achieve what you want.

    If oBusObj.BatchEnabled = 1 Then
        oBatch_Bus = 0 : oBusObj.GetValue "coBatch", oBatch_Bus
        If oBatch_Bus > 0 Then
            Set oBatch_Bus = oSession.AsObject(oBatch_Bus)
            PrivateBatch = "" : oBatch_Bus.GetValue "PrivateBatch$", PrivateBatch
            If PrivateBatch <> "Y" Then
                oBatch_Bus.SetValue "PrivateBatch$", "Y"
                oBatch_Bus.Write
                oBatch_Bus.SetKey oBatch_Bus.GetKey() ' I do not know for sure whether this line is really needed but it makes sure to put the batch back into an edit state after the Write.
            End If
            Set oBatch_Bus = Nothing
        End If
    End If

Children