- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
SetKeyValu e/SetKey fails when a key component is numeric?
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-16-2012 05:42 PM - last edited on 01-16-2012 06:47 PM
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_
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?
Re: SetKeyValu e/SetKey fails when a key component is numeric?
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-17-2012 06:40 AM - last edited on 01-17-2012 06:41 AM
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
Re: SetKeyValu e/SetKey fails when a key component is numeric?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-17-2012 08:44 AM
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?
Re: SetKeyValu e/SetKey fails when a key component is numeric?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-17-2012 09:19 AM
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.
Re: SetKeyValu e/SetKey fails when a key component is numeric?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-17-2012 03:05 PM
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
Re: SetKeyValu e/SetKey fails when a key component is numeric?
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-17-2012 03:20 PM - last edited on 01-17-2012 03:32 PM
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.
Re: SetKeyValu e/SetKey fails when a key component is numeric?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-17-2012 03:34 PM
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
Re: SetKeyValu e/SetKey fails when a key component is numeric?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-17-2012 03:38 PM
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
Re: SetKeyValu e/SetKey fails when a key component is numeric?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-17-2012 04:46 PM
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.
Re: SetKeyValu e/SetKey fails when a key component is numeric?
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-17-2012 06:41 PM - last edited on 01-17-2012 06:44 PM
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).


