Sage MAS 90 and 200 Sage MAS 500 blogs Product Feedback Support Training
Reply
Contributor
kmandevi
Posts: 11
Registered: 12-07-2011
0

Create New Item Code Button

I have created an external link button connecting to a VB_Script.

I would like that button to create a new Item Code and refresh the screen.

 

I am searching for a way to create a new line in the script for a button, but have not found anything.  I was thinking it would be something like:

 

retVal = oUIObj.AddLine()
retVal = oUIObj.SetValue("ITEMCODE",NEXT_PN)
retVal = oUIObj.Write

  NEXT_PN is my variable that determines what the next item code should be.

 

I am getting the following error:

OLE Error Number : 424

Description : Object required: 'oUIObj'

Language : VBScript

 

Any Ideas?

 

Thanks in advance.

I am on Mas 200 V4.4.0.4

Super Contributor
connex
Posts: 794
Registered: 10-29-2008
0

Re: Create New Item Code Button

[ Edited ]

If you are running the button script under MAS 200 with the 'Execute Script on Client' option, but not physically on the server then you are aren't running under the advanced script context which only exists on the server. Thus the oUIObj is not recognized.

Dan Burleson
Sage Authorized Consultant - Ask me about advanced scripting!
e-mail me here
Sage Employee
jepritch
Posts: 236
Registered: 08-25-2009
0

Re: Create New Item Code Button

Also, further to Dan's comments.  These methods you are attempting AddLine(), SetValue(), and Write() are methods of the oBusObj and not the oUIObj.

 

Elliott

Contributor
kmandevi
Posts: 11
Registered: 12-07-2011
0

Re: Create New Item Code Button

[ Edited ]

Thanks for the help guys,

 

I changed that option to run the script on the server and now I am getting this as an error:

 

"OLE Error Number : 70

Description : Permission denied: 'MsgBox'

Language : VBScript"

 

I think I may need two scripts one run on the clients computer to interact with the user and one on the server to create the new part numbers.  Any ideas how to do this?  I will continue searching.

 

I may as well post all of my code too:

myFile = "FILEPATH HIDDEN"
Call Get_PN(NEXT_PN,ANS,myFile)

If ANS<>2 Then
	USE = 1
	Call Write_PN(Next_PN,USE,myFile)
	OLD_NO = NEXT_PN
	NEXT_PN = InputBox("PN","NEW ITEM","_"&NEXT_PN&"-1")
	NEXT_PN = UCase(NEXT_PN)
	If NEXT_PN <> "" THEN
		NEXT_NO = right(left(NEXT_PN,7),6)
		If NEXT_NO < OLD_NO THEN
			NEXT_NO = OLD_NO
		ELSE
			NEXT_NO = NEXT_NO + 1
		END IF
		USE = 0
		Call Write_PN(Next_NO,USE,myFile)
		'CREATE NEW PN IN MAS
		retVal = oBusObj.AddLine()
		retVal = oBusObj.SetValue("ITEMCODE",NEXT_PN)
		retVal = oBusObj.Write()
		

	ELSE
		USE = 0
		Call Write_PN(OLD_NO,USE,myFile)	
	END IF
		
End If




'-----------------------------------------------------------------
Sub Get_PN(NEXT_PN,ANS,myFile)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
DIM fso, f, tso
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(myFile, ForReading)
NEXT_PN = f.ReadLine
USE = f.ReadLine
f.close
If Use=1 Then
	ANS = MsgBox ("Someone is creating a new PN right now, Please try again in a moment.",VBRetryCancel, "Busy")
	If ANS=4 Then
		Call Get_PN(NEXT_PN,ANS,myFile)
	End If
End If
End Sub
'-----------------------------------------------------------------
Sub Write_PN(NEXT_NO,USE,myFile)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
DIM fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(myFile, ForWriting, True)
f.WriteLine NEXT_NO
f.WriteLine USE
f.close
End Sub

 

Super Contributor
connex
Posts: 794
Registered: 10-29-2008
0

Re: Create New Item Code Button

[ Edited ]

You should use the MessageBox method:

 

strWarnMessage = "You should take the class or read up on all of Steve Malmgram's posts!"

retVal = oSession.AsObject(oSession.UI).MessageBox("",strWarnMsg)

Dan Burleson
Sage Authorized Consultant - Ask me about advanced scripting!
e-mail me here
Contributor
kmandevi
Posts: 11
Registered: 12-07-2011
0

Re: Create New Item Code Button

Good Idea, I will read up on Steve's stuff.

Contributor
kmandevi
Posts: 11
Registered: 12-07-2011
0

Re: Create New Item Code Button

I have modified my code a bit and split it into two scripts.  I have moved the buttons into a dialog window with a UDF, because there was no inputbox function available.  The first script suggests the next PN in the list.  The next code actually creates the new item code and fills in some default values.  

 

What I am having trouble with now is displaying the newly created item code after the script is finished.  I do have and invoke button to move away from the Dialog window, but I cannot seem to refresh the screen for item maintenance. 

 

Any Ideas to refresh the screen and display the newly created item?

 

Dialog Screen:

 

Suggest PN Script:

myFile = "FILE PATH HIDDEN"
retVal = ""
NEXT_PN = ""
Call Get_PN(NEXT_PN,ANS,myFile)

	CI_ItemCode_bus_UDF_EXTDES = "_"& NEXT_PN &"-1"
	
'-----------------------------------------------------------------
Sub Get_PN(NEXT_PN,ANS,myFile)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
DIM fso, f, tso
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(myFile, ForReading)
NEXT_PN = f.ReadLine
f.close
End Sub

 

Create PN Code:

 

' 
' language VBScript
' 
' panel variables
' CI_ItemCode_bus_UDF_EXTDES
' 
' system variables
' MAS_SCR_CMP : company code
' MAS_SCR_USR : user code
' MAS_SCR_MOD : module code
' MAS_SCR_DTE : current app date
' MAS_SCR_LIB : library
' MAS_SCR_PNL : panel
' MAS_SCR_OBJ : control [BT_LINK_x]
' MAS_SCR_CS  : 1 if running Sage MAS 200 on client
' MAS_SCR_DBG : 1 to show script before and following execution

myFile = "FILE PATH HIDDEN"
NEXT_PN = ""
USE = ""
newRow = ""
'ANS = oSession.AsObject(oSession.UI).Messagebox(".Y",CI_ItemCode_bus_UDF_EXTDES)
Call Get_PN(OLD_NO,ANS,myFile)
NEXT_PN = CI_ItemCode_bus_UDF_EXTDES
	If NEXT_PN <> "" THEN
		NEXT_NO = right(left(NEXT_PN,7),6)
		If NEXT_NO < OLD_NO THEN
			NEXT_NO = OLD_NO
		ELSE
			NEXT_NO = NEXT_NO + 1
		END IF
		
		'CREATE NEW PN IN MAS
		newRow = oBusObj.SetKey(NEXT_PN)
		
		IF newRow = 1 Then
			ANS = oSession.AsObject(oSession.UI).Messagebox("","This Part Number Already Exists, Try Again!")
		Else
			T = left(NEXT_PN,1)
			If T = "C" Then
				retVal = oBusObj.SetValue("PRODUCTLINE$","RM")
				retVal = oBusObj.SetValue("UDF_ENG_TYPE$","PS")			
			End If
			If T = "P" THEN
				retVal = oBusObj.SetValue("PRODUCTLINE$","MTS")
				retVal = oBusObj.SetValue("UDF_ENG_TYPE$","DWG")
			End If
			If T = "A" THEN
				retVal = oBusObj.SetValue("PRODUCTLINE$","MTS")
				retVal = oBusObj.SetValue("UDF_ENG_TYPE$","PL")
			End If
			If T = "T" THEN
				retVal = oBusObj.SetValue("PRODUCTLINE$","MTS")
				retVal = oBusObj.SetValue("UDF_ENG_TYPE$","DWG")
				retVal = oBusObj.SetValue("UDF_ENG_TITLE$","Tooling,")
			End If



			Call Write_PN(Next_NO,USE,myFile)
			
		End If
	END IF
'click ok and refresh screen
retVal = oScript.InvokeButton("BT_OK")


'------I have tried all of this stuff below with no success--------
'retVal = oBusObj.Write()
'retVal = oBusObj.nMoveFirst()
'Set oItem = oScript.AsObject(oItem)
'retVal = oItemCode.GetValue("ItemCode$", itemCode)
'ANS = oSession.AsObject(oSession.UI).Messagebox("",itemcode)
'retVal = oITEM.Write()
'retVal = oScript.MovePrevious()
'retVal = oScript.MoveNext()
'retVal = oScript.InvokeButton("BT_CANCEL")
'retVal = oScript.InvokeButton("BT_NEXT")
'retVal = oScript.InvokeButton("fldr.PNL_CMNEW_1")
'retVal = oScript.InvokeButton("fldr.PMAIN")
'newRow = oBusObj.SetKey(NEXT_PN)
'retVal = oScript.InvokeButton("fldr.PNL_CMNEW_1")

		
'-----------------------------------------------------------------
Sub Write_PN(NEXT_NO,USE,myFile)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
DIM fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(myFile, ForWriting, True)
f.WriteLine NEXT_NO
f.WriteLine USE
f.close
End Sub
'-----------------------------------------------------------------
Sub Get_PN(NEXT_PN,ANS,myFile)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
DIM fso, f, tso
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(myFile, ForReading)
NEXT_PN = f.ReadLine
f.close
End Sub