Sage MAS 90 and 200 Sage MAS 500 blogs Product Feedback Support Training
Reply
Sage MAS 90 Customer
hyanaga
Posts: 34
Registered: 11-16-2010
0

Error after using bSave in a VBScript

Our client has a validation script that runs on Save of a Sales Order.  It checks all the lines on the order, and looks for 2 required items (ORD & FREI).  If those items aren't there, we change bSave to false and use a MsgBox to remind the user to enter the required lines.

 

The script works fine the first time it fires.  If the user then adds both line items on the order, then saves, everything is fine.  However, if the user enters only adds one of the required lines, then saves the sales order, the script fires again, reminding them that they need both items.

 

However, this time after the user adds the second required item, when the sales order is saved, the MAS error pops up "Enter Sales Orders and Quotes already exists.  Save canceled."

 

I was so proud of this script until this came up!  It would really solve a big issue at the client.  Has anyone experienced this, and if so, is it resolvable?  (I tried running a trace on the database, and I can't figure out what's causing it to fail.)

 

Here is my script, in case it's an error within it:

 

If Form.Controls("txtSONum") <> "" and (Form.Controls("lkuSource").Text = "FULFILLMENT" or Form.Controls("lkuSource").Text = "WEB" or Form.Controls("lkuSource").Text = "PRODUCTION" or Form.Controls("lkuSource").Text = "PROTOTYPE") Then

  Dim ItemID, r, m, frt, op

  frt = 0

  op = 0

  Form.Controls("grdDetail").col = 1

  If Form.Controls("grdDetail").DataRowCnt > 0 Then

    m = Form.Controls("grdDetail").DataRowCnt

    For r = 1 to m

    Form.Controls("grdDetail").row = r

    ItemID = Form.Controls("grdDetail").value

    'MsgBox ItemID

    If Left(ItemID,4) = "FREI" Then

      frt = 1

    end if

    If Left(ItemID,3) = "ORD" Then

      op = 1

    End If

    If Frt = 1 and op = 1 Then

    Exit For

    End If

  Next

End if

If frt = 0 or op = 0 Then

  MsgBox "Both Freight and Order Processing line items are required for this order."

  bSave = False

End if

End if

 

Thanks!
Hollie
Sage Employee
gstorres
Posts: 37
Registered: 10-29-2008
0

Re: Error after using bSave in a VBScript

[ Edited ]

Try moving your validation outside the DM event.  Look for other field level validation and add your code there.

  ** Just realized your code is in VBScript.  Not actually in the source code. Sorry. **

Gerard Tan-Torres
Sage 500 Engineering
Sage MAS 90 Customer
hyanaga
Posts: 34
Registered: 11-16-2010
0

Re: Error after using bSave in a VBScript

Yep, we're trying to stay in the Customizer framework, so we're using VBScript on the events available to Customizer, which are sadly lacking...

 

Thx, Hollie

Thanks!
Hollie
Sage MAS Partner
LouDavis
Posts: 545
Registered: 10-29-2008
0

Re: Error after using bSave in a VBScript

Are you doing this in MAS 500 or MAS 90 as I see you are registered as a MAS 90 Customer.

Louis Davis MCSD, MCAD, MCITP
e2b teknologies, inc
www.e2btek.com

Sage MAS 90 Customer
hyanaga
Posts: 34
Registered: 11-16-2010
0

Re: Error after using bSave in a VBScript

I am both a MAS 90 and MAS 500 consultant, I don't know why it says I'm a customer. 

 

This is for a MAS 500 customer.  I don't think those control references would work in MAS 90.  :smileyhappy:

 

Thx, Hollie

Thanks!
Hollie
Sage Employee
gstorres
Posts: 37
Registered: 10-29-2008
0

Re: Error after using bSave in a VBScript

There is an effort in 7.50 to improve the features of customizer.  I'll make sure to bring up this topic during our discussions.

 

Gerard Tan-Torres
Sage 500 Engineering
Sage MAS Partner
LouDavis
Posts: 545
Registered: 10-29-2008
0

Re: Error after using bSave in a VBScript

I've seen the message you described even doing modifications using VB 6.  It indicates that your script is always trying to create new records instead of updating the existing ones.  Working with the grids on a MAS 500 form is difficult at best using Customizer especially when talking about the Sales Order Entry screen.  Customizer really was not designed to manipulate data in the grids though as you can see you do have access to the control.

 

Most likely what is happening is the underlying code for the task isn't recognizing that an update needs to occur and tries to create the record(s) again.  You may have to rethink how you need to accomplish what you want to do either by redesigning your Customizer routine to manually update the records after the task does it save, or modify the task using VB 6 and the Enter Sales Order Entry source code to add your routine to the task itself so it properly saves the data you need.

Louis Davis MCSD, MCAD, MCITP
e2b teknologies, inc
www.e2btek.com

Sage MAS 500 Customer
JohnHanrahan
Posts: 207
Registered: 11-03-2010
0

Re: Error after using bSave in a VBScript

You could write a trigger (maybe).  Should work though and doesn't require a custom mod.  I'm not sure if I'm thinking it all the way through though...

Sage MAS 90 Customer
hyanaga
Posts: 34
Registered: 11-16-2010
0

Re: Error after using bSave in a VBScript

Thanks for your replies.  Unfortunately, Louis, neither of those options works for their scenario.  The user has to choose an item to be added, so I can't add the record for them, since there are several options, but at least one of those options must be included by the user.  In addition, the client does not want to modify source code.  So it's back to the drawing board!  The weird thing is that it seems to happen only if the user gets the error twice; if they add all the required items after the first error, there's no problem.  But if they only enter one required item and not the second, the script fires and then they can't save the SO.

 

I'm going to run this with SQL profiler on and see what's happening in the background, I haven't tried that yet.

 

Hollie

Thanks!
Hollie
Sage MAS 90 Customer
hyanaga
Posts: 34
Registered: 11-16-2010
0

Re: Error after using bSave in a VBScript

A trigger, hmmm.  I'll have to think about that one. If I use a trigger to validate the lines, I'll still have to capture it in the VB and stop the save, won't I?  or maybe the trigger would catch it before the save, where it doesn't seem to be doing that now.  I'll look into that one.

 

Hollie

Thanks!
Hollie