Sage MAS 90 and 200 Sage MAS 500 blogs Product Feedback Support Training
Reply
unidentified user
chief_chef
Posts: 8
Registered: 09-07-2011
0

Prevent New Standard Items From Being Created

I’m trying to come up with a way to prevent standard inventory items from being created based on certain criteria regarding the ItemCode$.  For instance I may not want the users to be allowed to enter an item that begins with a space.  The ItemCode$ field is not available in the validation logic for scripting, so I was looking at the Post-Read Table.  I notice in SY_Maint there is this cSetToReadOnlyReason$.  Would the following Post-Read script for CI_Item be the best way to handle this?  Does anyone see any issues with this approach?

 

CI_Item_ItemCode = ""

retVal = 0

 

If (oBusObj.EditState = 2) Then
retVal = oBusObj.GetValue("ItemCode$", CI_Item_ItemCode)

 

If (Left(CI_Item_ItemCode, 1) = " ") Then
oBusObj.SetToReadOnly("Item Code cannot begin with a space.")
End If
End If

Sage MAS 90 Customer
Thill
Posts: 20
Registered: 11-06-2009
0

Re: Prevent New Standard Items From Being Created

I haven't used SetToReadOnly, but if that's working for you, the code looks fine.

 

To check the ItemCode, consider using the Trim function instead of Left.  This would catch codes beginning or ending with a space.

 

...

 

If (Trim(CI_Item_ItemCode) <> CI_Item_ItemCode) Then


...

Tony D: Software Engineer
Kencove Farm Fence
unidentified user
chief_chef
Posts: 8
Registered: 09-07-2011
0

Re: Prevent New Standard Items From Being Created

Thanks for the suggestion.  I have settled on the following bit of code that seems to work:

 

CI_Item_ItemCode = ""

retVal = 0

 

If (oBusObj.EditState = 2) Then

                retVal = oBusObj.GetValue("ItemCode$", CI_Item_ItemCode)

 

                If (Trim(CI_Item_ItemCode) <> CI_Item_ItemCode) Then

                                If CBool(oScript.UIObj) Then

                                                retVal = oSession.AsObject(oSession.UI).MessageBox("Invalid Item Code", "Item Code cannot begin with a space.")

                                                retVal = oScript.InvokeButton("BT_CANCEL")

                                Else

                                                oBusObj.SetToReadOnly("Item Code cannot begin with a space.")

                                End If

                End If

End If