Dude the direct answer to your question is your oBusObj.SecurityAccess = 0. When you open a task from Launcher, SecurityAccess is set from your Role Maintenance access and the value returned is between 0 - 7, 7 representing the most access. However, for all Inquiry screens it's always 0 even if you're the super-user in the super-role. So this as as a rule makes it impossible to Write() via another biz object like you are trying not just the current biz object. In fact, even if your script called some Perform Logic to run some pvx object commands and do the same math as your script, it would run into the same exact error on it's Write(). So you have 2 options:
1. Call Perform Logic from script that does not create an object out of IM_ItemWarehouse_bus but writes directly to IM_ItemWarehouse table. Don't recommend this.
2. Use BOI when you detect you're on an Inquiry screen. The combination of the nSetUser, nLookupTask, and nSetProgram in BOI determines the SecurityAccess which means it's independent of the current screen you have open. You're basically running this code externally as if you were not in the Launcher. I've posted a sample here. Note the following things to pay attention to:
* Regular event script code runs if StartProgram in not an inquiry screen otherwise BOI code. I could've alternately checked oBusObj.SecurityAccess value or check if StartProgram is specifically UCase("IM_ItemInquiry_ui")
* On the BOI code, oSS is used instead of oSession because oSession is already in use with the current screen.
* On the BOI code, oPvxScript is used instead of oScript because oScript already in use with the current screen.
* Change the BOI_HomePath, BOIUser, and BOIpswd to yours.
* The MsgBox instead of MessageBox() on the BOI code side is correct cuz we always run BOI Mas90 style.
* Remove all the MsgBox's when you're done with it.
' ------------------- SCRIPT MAIN ------------------
'Init VARs
sItemCode="" : sItemType=""
sWhse="000"
Randomize
nRandom = Round(100*Rnd,2) : r=oScript.DebugPrint("nRandom: " & nRandom)
rV=oBusObj.GetValue("ItemCode",sItemCode) : r=oScript.DebugPrint("ItemCode: " & sItemCode)
If InStr(oSession.StartProgram,"INQUIRY") = 0 Then
nIM2 = oSession.GetObject("IM_ItemWarehouse_bus")
If nIM2 <> 0 Then Set oIM2 = oSession.AsObject(nIM2)
rV = oIM2.SetKeyValue("ItemCode$",sItemCode)
rV = oIM2.SetKeyValue("WarehouseCode$",sWhse)
rK = oIM2.SetKey()
If rK <> 1 Then
sMsg="Error on SetKey of oIM2 key: " & oIM2.LastErrorMsg
r=oScript.DebugPrint(sMsg)
Else
rV = oIM2.SetValue("UDF_RANDOM", nRandom)
If rV <= 0 Then
sMsg = "LastErrorMsg on SetValue of IM2: " & oIM2.LastErrorMsg
r=oScript.DebugPrint(sMsg)
Else
rW = oIM2.Write()
If rW <= 0 Then
sMsg = "LastErrorMsg on Write of IM2: " & oIM2.LastErrorMsg
r=oScript.DebugPrint(sMsg)
End If
End If
End If
If IsObject(oIM2) Then oSession.DropObject nIM2
Else
'StartProgram = UCase("IM_ItemInquiry_ui")
'Remember BOI always run Mas90 style so MsgBox is OK. MessageBox is not possible.
BOICompany = oSession.CompanyCode
BOIuser = "Id like to be under the sea"
BOIpswd = "in an octopus garden in the shade"
BOI_HomePath = "C:\Sage\v2021Std\MAS90\Home\"
Set oPvxScript = CreateObject("ProvideX.Script") 'Equivalent but not same as oScript inside the Launcher
oPvxScript.Init(BOI_HomePath)
' Create and Initialize Session Object
MsgBox "About to NewObject SY_Session"
Set oSS = oPvxScript.NewObject("SY_Session") 'Equivalent but NOT same as oSession inside the Launcher
retVal = oSS.nSetUser(BOIuser, BOIpswd) 'Required
retVal = oSS.nSetCompany(BOICompany) 'Required
MASCurrentDate = oSS.sGetFormattedDate(CStr(CurrentVBDate))
MsgBox "About to nLookupTask on IM_Item_ui"
taskID = oSS.nLookupTask("IM_Item_ui") 'Not set to IM_ItemInquiry_ui on purpose
retVal = oSS.nSetProgram(taskID)
MsgBox "About to NewObject on IM_ItemWarehouse_bus"
Set oIM2 = oPvxScript.NewObject("IM_ItemWarehouse_bus", oSS)
retVal = oSS.nSetDate("I/M", MASCurrentDate)
rV = oIM2.nSetKeyValue("ItemCode$",sItemCode)
rV = oIM2.nSetKeyValue("WarehouseCode$",sWhse)
MsgBox "About to oIM2.nSetKey"
rK = oIM2.nSetKey()
If rK <> 1 Then
sMsg="Error on SetKey of oIM2 key: " & oIM2.sLastErrorMsg
Else
MsgBox "About to oIM2.nSetValue"
rV = oIM2.nSetValue("UDF_RANDOM", nRandom)
If rV <= 0 Then
sMsg = "LastErrorMsg on SetValue of IM2: " & oIM2.sLastErrorMsg
Else
MsgBox "About to oIM2.nWrite"
rW = oIM2.nWrite()
If rW <= 0 Then
sMsg = "LastErrorMsg on Write of IM2: " & oIM2.sLastErrorMsg
Else
MsgBox "About to oIM2.nClear"
rC = oIM2.nClear()
End If
End If
End If
'Important!
MsgBox "About to enter Clean-up"
If IsObject(oIM2) Then oIM2.DropObject()
If IsObject(oSS) = True Then
oSS.nCleanUp()
oSS.DropObject()
End If
End If ' check for UCase("IM_ItemInquiry_ui")
------------------------------
Alnoor Cassim
------------------------------