Sage MAS 90 and 200 Sage MAS 500 blogs Product Feedback Support Training
Reply
Super Contributor
connex
Posts: 791
Registered: 10-29-2008
0

SetKeyValue/SetKey fails when a key component is numeric?

[ Edited ]

I am finding that SetKey for the KPRIMARY key of IM_ItemCost fails using SetKeyValues for each segment as shown below when an existing key's GroupSort value consists of a numeric string.

 

Easy to check in the ABC company I/M Maintenance for item 2480-8-50 (this is a button script)

 

Set oItemCost = oSession.AsObject(oSession.GetObject("IM_ItemCost_bus")) 

retVal = oItemCost.SetKeyValue("ItemCode$", "2480-8-50")
retVal = oItemCost.SetKeyValue("WarehouseCode$", "000")
retVal = oItemCost.SetKeyValue("TierType$", "3")
retVal = oItemCost.SetKeyValue("GroupSort$", "101")
retVal = oItemCost.SetKey()  

 

Works (retVal=1) with Lot No's JAN10, MAR10, but fails (retVal=0) on 101 and 10210.  If I duplicate lot 10210 as A0210 it also works.

 

How does one force the construction of this key to use the given string for GroupSort?

Dan Burleson
Sage Authorized Consultant - Ask me about advanced scripting!
e-mail me here
Moderator
khmackall
Posts: 222
Registered: 10-16-2008
0

Re: SetKeyValue/SetKey fails when a key component is numeric?

[ Edited ]

Dan,

 

I just did a quick test and am able to call the SetKeyValue() method with all the values in your example including using SetkeyValue("GroupSort$","101") and have it set the key value and then call SetKey().  If the SetKeyValue() method is failing when setting the GroupSort$, then what is the value of oItemCost.sLastErrorMsg when it fails?


Thanks,

Kent

Sage MAS 90 Customer
rolandc
Posts: 95
Registered: 06-10-2010
0

Re: SetKeyValue/SetKey fails when a key component is numeric?

Using MAS 200 4.40 PU5. Upon inspection of GetKey(), I noticed GroupSort was getting left-padded with zeros. Apart from building the key the "long" way with null characters Chr(0), is there any way to disable the padding for numerics?

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

Re: SetKeyValue/SetKey fails when a key component is numeric?

Kent,

 

I get a retVal = 1 on the SetKeyValue of GroupSort$ to "101" and .LastErrorMsg is "Cannot add records to IM_ItemCost".

 

I get a RetVal=0 on the SetKey and the .LastErrorMsg is the same.

Dan Burleson
Sage Authorized Consultant - Ask me about advanced scripting!
e-mail me here
Moderator
khmackall
Posts: 222
Registered: 10-16-2008
0

Re: SetKeyValue/SetKey fails when a key component is numeric?

Dan,

 

That is correct.  In my test earlier, the key I was building and using in the SetKey call already existed in the IM_ItemCost Table so I was able to set the key without error.  The message you are getting indicates that the key you are attempting to set is not on file (i.e. it is a new key) and IM_ItemCost_bus does not allow for the creation of new records.  In order to add records to IM_ItemCost you need to update an Inventory transaction of some kind

 

The next question is what are you trying to do with IM_ItemCost? If you are trying to add a record, then you likely want to do this through an Inventory Receipt transaction.

Thanks,

Kent

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

Re: SetKeyValue/SetKey fails when a key component is numeric?

[ Edited ]

Ken, The point is - that the record already exists in my ABC company data! Therefore the message is bogus or my key isn't being set.

 

I not only can verify by looking at the standard ABC company data with DFD&M, but if I use instructions to scan for it (.MoveNext and GetValue) I can read in the record with "101" as the GroupSort field. It just cannot be found with SetKeyValue and SetKey. This is MAS 90 4.40.006. This also behaves the same way on my client's system ABC data. It works fine for alpanumeric keys and fails for all numberic keys - not just "101".

 

I'm not trying to add records, only update a UDF in IM_ItemCost.

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: SetKeyValue/SetKey fails when a key component is numeric?

Hi Dan,

 

Can you check after each SetKeyValue() to see if any of those are failing?  I just copied your script and ran it from a button and it worked okay for me in the demo ABC company.     If any of the first 3 or so failed, this may cause it to think it's creating a new record.

 

Elliott

 

Sage Employee
jepritch
Posts: 233
Registered: 08-25-2009
0

Re: SetKeyValue/SetKey fails when a key component is numeric?

Just had a thought (of course right after my reply).  Where are you running this script from?  I'm wondering if the module code is causing you grief.  As you know the ItemCodes can be selectively used by module, and maybe if you are running this script from A/R or A/P, the validation on the Item is failing because you are not in one of the modules allowed to use 2480-8-50.

 

I know this is fixed in later versions (4.5?)  If not you may have to do a oSession.SetModule() around the rest of the calls.

 

Hope this helps.

 

Elliott

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

Re: SetKeyValue/SetKey fails when a key component is numeric?

All SetKeyValue's return 1 even the last one for GroupSort$. The SetKey returns 0.

 

I am running this I/M Maintenance so the module shouldn't be an issue.  I tested this on 4.50 and it works as one would expect.

 

Is that the version that you have been testing? 

 

I was wondering why you said "I know this is fixed in later versions (4.5)" if you were not seeing the problem.

Dan Burleson
Sage Authorized Consultant - Ask me about advanced scripting!
e-mail me here
Sage MAS 90 Customer
rolandc
Posts: 95
Registered: 06-10-2010
0

Re: SetKeyValue/SetKey fails when a key component is numeric?

[ Edited ]

Hey, I think I was not clear in my earlier post. The problem appears to be due to GroupSort$ getting padded as "0000000000000101" to its max length of 16, the same way it treats numerics such as SalesOrderNo. So SetKey() is trying to create a record where the key is "2480-8-50 000 3 0000000000000101" instead of "2480-8-50 000 3 101" (without the spaces). Maybe there is a way to disable that padding in 4.40 which appears to be fixed in 4.50 according to Dan. If the key is built into a string and properly padded with null characters, it will work (although the hard way).