Sage MAS 90 and 200 Sage MAS 500 blogs Product Feedback Support Training
Reply
Sage MAS Partner
TomTarget
Posts: 1,752
Registered: 11-02-2008
0

Writing to IM_ItemCost

I have a client having some difficulties with quantities committed to work orders.   This is not the committed numbers you see when you go to inventory maintenance but and underlying field in IM_ItemCost that appears to be populated when you enter transactions in work order and should be cleared when the transactions are posted.

 

Unfortunately they appear to have 100's of these items throughout the inventory which keeps them from using cost layers.  It's possible to clear them with DFDM, but it's going to take hours and hours to do it, so I'm trying to find a better way to fix it.

 

Rebuild sort files on inventory maintenance with a clear committed does not affect it.

Visiual integrator does not allow access to these fields.

 

So now I'm at the point where I'm trying to write a button script that can run through IM_ItemCost,  identify the the bad layers and simply zero out the values in this field.    Sounds simple, except that I can't seem to write back to the file.  Is it possible that setvalue on these fields  is somehow disabled in the IM_ItemCost_bus?

 

'declare variables
xdebug = 1
tmpStr = ""
tmpNum = 0

rec = ""

 

oCostLayers = oSession.GetObject("IM_ItemCost_bus") 

if oCostLayers <> 0 then
 Set oCostLayers = oSession.AsObject(oCostLayers)
else
 retval = oSession.AsObject(oSession.UI).Messagebox( "","oCostLayers failed")
 ' needs to exit here
end if

retval = oCostLayers.MoveFirst()   'go to first record

 

do until cBool(oCostLayers.Eof)   'loop through the file

  retval = oCostLayers.GetRecord(rec, tmpStr)
  retval = oCostLayers.GetValue("CostCalcQtyCommitted",ccqc)           'look at the Committed fields and decide whether this record needs fixing
  retval = oCostLayers.GetValue("CostCalcCostCommitted",cccc)

  if ccqc <> 0 or cccc <> 0 then
 subDisplayDialog(rec)                     ' display the record found  -  code ommitted

 msgbox "edit state " &  oCostLayers.EditState       'this returns a 1 suggesting that the record is found

 

 'following section was just added to try and go directly to a known bad record and write - not in my original code
 retval = oCostLayers.SetKeyValue("ItemCode","BOARD-004320-33")
 retval = OcostLayers.SetKeyValue("WarehouseCode","000" )
 retval = oCostLayers.SetKeyValue("TierType","4")
 retval = oCostLayers.SetKeyValue("GroupSort","1000302")
 retval = oCostLayers.SetKey()

 retval = oCostLayers.SetValue("CostCalcQtyCommitted",0)   'zero out the values
 msgbox retval  & oBusObj.LastErrorMsg     ' LastErrorMsg   returns  "The is invalid"   


 retval = oCostLayers.SetValue("CostCalcCostCommitted",0)   ' retval is 0 suggesting an error
 
 msgbox retval  & oBusObj.LastErrorMsg      ' LastErrorMsg   returns  "The is invalid"    


 retval = oCostLayers.Write()
 if retVal <> 1 then msgbox("Write Failed") end if          'this does not fail

  end if 

retval = oCostLayers.MoveNext()


loop

retval = Osession.DropObject("IM_ItemCost_bus")

 

 

 

Thomas H. Rogers, C.P.A.
Target System Technology, Inc. - Spokane, WA -
The best solution often comes not from answering the question asked, but understanding WHY the question was asked.
Moderator
Natasha
Posts: 180
Registered: 07-15-2009
0

Re: Writing to IM_ItemCost

Tom,

 

Need $ in "ItemCode$", "WarehouseCode$", "TierType$", and "GroupSort$."

 

Natasha Chang
Sr. Software Engineer
Sage 100 ERP
Sage MAS Partner
TomTarget
Posts: 1,752
Registered: 11-02-2008
0

Re: Writing to IM_ItemCost

Thanks Natasha

 

You are correct on the $.

 

However it still flakes out when you get to the Setvalues.   The return value is a 0 indicating the setvalue is failing.  

 

Seems to suggest that the exposed interface does allow changing the values for costcalcQtyCommitted and costcalcCostCommitted.

 

Also noted that my test record was for a serialized item and changed it to be a FIFO type item.  That did not help either.

 

Really hope I can figure out a way to do this.   This is probably a 6 to 10 hour correction if we have to do it by DFDM.

Thomas H. Rogers, C.P.A.
Target System Technology, Inc. - Spokane, WA -
The best solution often comes not from answering the question asked, but understanding WHY the question was asked.
Moderator
Natasha
Posts: 180
Registered: 07-15-2009
0

Re: Writing to IM_ItemCost

Tom,

 

All numeric fields in IM_ItemCost are set to Read Only in the dictionary.  That's why you can't import them or change them in your script.   I guess we must not want people messing with them.

 

Natasha Chang
Sr. Software Engineer
Sage 100 ERP
Sage MAS Partner
TomTarget
Posts: 1,752
Registered: 11-02-2008
0

Re: Writing to IM_ItemCost

Was afraid of that.   Makes sense to do that as someone mucking around in there can cause a lot of problems if they aren't careful. 

 

I've registered a case with Tech Support to see if they can come up with a solution.

 

One way or another,  we need to figure out why this is happening in the first place and keep it from recurring.

Thomas H. Rogers, C.P.A.
Target System Technology, Inc. - Spokane, WA -
The best solution often comes not from answering the question asked, but understanding WHY the question was asked.
Super Contributor
connex
Posts: 791
Registered: 10-29-2008
0

Re: Writing to IM_ItemCost

[ Edited ]

I am seeing that writes to a UDF string field does not work for this table either.  I get a return code of 1, but nothing changes. Can you confirm this Natasha or Tom?

 

	Set oItemCost = oSession.AsObject(oSession.GetObject("IM_ItemCost_bus"))
	retVal1 = oItemCost.SetKeyValue("ItemCode$", sItemCode)
	retVal2 = oItemCost.SetKeyValue("WarehouseCode$", WAREHOUSE)
	retVal3 = oItemCost.SetKeyValue("TierType$", "3")
	retVal4 = oItemCost.SetKeyValue("GroupSort$", sLotSerialNumber)
	retVal = oItemCost.SetKey()
	retVal = oItemCost.GetValue("UDF_LOCATION", sLocation)         ' retVal = 1 and Works!
	retVal = oItemCost.SetValue("UDF_LOCATION", sLotSerialNumber)  ' retVal = 1 but doesn't work

 

 

Dan

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

Re: Writing to IM_ItemCost

Hi Dan,

 

In your example is the "UDF_Location" a string or a numeric?  You are trying to return the numeric variable UDF_Location, and store a string variable into it.

 

 

retVal = oItemCost.SetValue("UDF_Location$", sLotSerialNumber)

 

Give that a try.

 

Elliott

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

Re: Writing to IM_ItemCost

Elliott,

 

Thanks for the reply, but there is acually a $ in the code it was a typo in this post. I had used a constant in the actual code:

 

Const LOCATION = "UDF_LOCATION$"

...

retVal = oItemCost.SetValue(LOCATION, sLotSerialNumber)

 

I was just trying to abbreviate and take out all of the debugging code. The UDF is definitely a string. I can set it in DFD&M and retrieve it with a GetValue.

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

Re: Writing to IM_ItemCost

I'm sure you have verified this, but:

 

Did you declare sLotSerialNumber  as a string?  Does it have a value?    Strange, after you do the Write() it's not in the file?

 

Can you try a hard-coded string, and then retrieve it right after?

 

retVal = oItemCost.SetValue("UDF_Location$", "ABC")

tmpVar = ""

 

retVal = oItemCost.GetValue("UDF_Location$", tmpVar)

 

I'll set something up here and see if I can reproduce this.

 

Elliott

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

Re: Writing to IM_ItemCost

Yes, I have my string variables initialized to an empty string and I have also set a value into UDF_Location via DFD&M which is not changing.

 

WOW though! I tried as you suggested and did a

 

tmpVar = ""

retVal = oItemCost.SetValue("UDF_Location$", "ABC")

retVal = oItemCost.GetValue("UDF_Location$", tmpVar)

 

AND THE tmpVar is set to "ABC", but the field in the table is NOT altered. Weird. Someone must be able to explain this.

Dan Burleson
Sage Authorized Consultant - Ask me about advanced scripting!
e-mail me here