Scripting

Expand all | Collapse all

Looking to set a new Extended Description based on

Dana Young

Dana Young12-04-2018 13:17

David Speck II

David Speck II12-04-2018 13:22

David Speck II

David Speck II12-04-2018 13:22

  • 1.  Looking to set a new Extended Description based on

    Posted 12-04-2018 12:50
    Looking to set a new Extended Description based on multiple UDFs. I have the description built, it populates ItemCodeDesc & will also populate ExtendedDescriptionText as long as there was one there before so the key is found. If the key is NULL, how do I create the new key, populate that in CI_Item & CI_ExtendedDescription? After I have my description built, this is what I have that is populating now: retVal = oBusObj.GetValue(""ExtendedDescriptionKey$"",sExtDesc) retVal = oBusObj.SetValue(""ItemCodeDesc$"",sBuildDesc) retVal = oBusObj.Write() oExtDesc = oSession.GetObject(""CI_ExtendedDescription_bus"") If oExtDesc <> 0 Then Set oExtDesc = oSession.AsObject(oExtDesc) End If retVal = oExtDesc.SetKeyValue(""ExtendedDescriptionKey$"",sExtDesc) retSetKey = oExtDesc.SetKey() retVal = oExtDesc.SetValue(""ExtendedDescriptionText$"",sBuildDesc) retVal = oExtDesc.Write() TIA!


  • 2.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 12:52
    Just set the description. The business object should handle the Extended Description considerations for you.


  • 3.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 12:54
    It doesn't. If we do a new item, it only sets the short description. If we take one that is there, back the extended out, it doesn't replace it. It only replaces it if there is text in the extended description already.


  • 4.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 12:55
    Haven't had to do this before so just guessing here but doesn't VI automatically handle the extended description if you set CI_Item.ItemCodeDesc to something greater than 30 characters? If it does, I'm not sure if that is handled by VI exception logic or if the CI_ItemCode_Bus handles it. If the bus object handles it, then you should only have to worry about setting CI_Item.ItemCodeDesc. Have you tried just the following? ``` retVal = oBusObj.SetValue(""ItemCodeDesc$"",""This is a really, really, really, really, really, long item code description"") retVal = oBusObj.Write() ```


  • 5.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 12:57
    Yes. As I was building this, I populated just the ItemCodeDesc$ first & it worked, but kept cutting off at the 30 mark. So, then I added the part that called out the ExtendedDescription object & it worked. Then, during testing we realized if we backed out the extended description already there or started a new item, it doesn't work.


  • 6.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 12:57
    Odd... I was assuming since VI handled it automatically that this was done in the business object.


  • 7.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 13:00
    Unless I am setting the ItemCodeDesc wrong?


  • 8.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 13:01
      |   view attached
    Also, you should not have to use `oExtDesc = oSession.GetObject(""CI_ExtendedDescription_bus"")`. Look at the attached images, there should already be a handle for you to use, I think you could also use `oExtDesc = oBusObj.GetChildHandle(""ExtendedDescriptionKey"")`


  • 9.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 13:03
    Is my way just longer or could it be causing the issue?


  • 10.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 13:05
      |   view attached
    How long? can't it handle up to 4k? Anyway, I just did this test. The SetValue method returned -1 which is a warning, so i displayed the LastErrorMsg$ and got the message seen in the attached file. So it should be handled by the bus object.


  • 11.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 13:07
    I took the the last section out & left just the retVal = oBusObj.SetValue(""ItemCodeDesc$"",sBuildDesc) retVal = oBusObj.Write() and when I go to create a new item, I click Accept & it just kills my screen & doesn't write the record.


  • 12.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 13:16
    What's the trigger? You shouldn't need the Write() when dealing with oBusObj.


  • 13.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 13:17
    Table - Post-Write


  • 14.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 13:20
    And, if I manually edit the extended description, when I click Accept, the screen locks up & has to be killed using task manager. It doesn't like me messing with this business object...


  • 15.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 13:21
    Been a while since i messed with a post write, but i believe you have to put the object into an edit state in the post write, you can't just call Write(), you then would need to disable the post-write event when you call Write() and enable it afterwards. But it sounds like this would be better off in a pre-write event anyway.


  • 16.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 13:22
    Try a pre-write event and get rid of Write().


  • 17.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 13:22
    i think you are causing a loop...


  • 18.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 13:27
    So, a pre-write will write the Description, but not the Extended Description, on both a new item or one already existing. If it had an extended already, it overwrites it with just the first 30 characters.


  • 19.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 14:18
    Post on SageCity and Elliott may chime in with working code (or record it in his list for fixing...).


  • 20.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 18:27
    Elliott or Alnoor might have a better response but what i found is if the script is running from Item Maintenance then it will not create or update the record in CI_ExtendedDescription. The only way i could get it work within Item Maintenance was with the following. This must be on the Pre-Write event. ``` sExtendedDescriptionKey = """" : oBusObj.GetValue ""ExtendedDescriptionKey$"", sExtendedDescriptionKey If sExtendedDescriptionKey = """" Or sExtendedDescriptionKey = ""0000000000"" Then sItemCodeDesc = """" : oBusObj.GetValue ""ItemCodeDesc$"", sItemCodeDesc Else sItemCodeDesc = """" : oSession.AsObject(oBusObj.ExtendedDescriptionBusiness).GetValue ""ExtendedDescriptionText$"", sItemCodeDesc End If sItemCodeDesc = sItemCodeDesc & "" - "" & sItemCodeDesc oBusObj.SetValue ""ItemCodeDesc$"", Left(sItemCodeDesc, 30) If Len(sItemCodeDesc) > 30 Then oSession.AsObject(oBusObj.ExtendedDescriptionBusiness).WriteExtendedDescription sExtendedDescriptionKey, sItemCodeDesc sExtendedDescriptionKey = """" : sExtendedDescriptionKey = oSession.AsObject(oBusObj.ExtendedDescriptionBusiness).GetKey() oBusObj.SetValueNoValidate ""ExtendedDescriptionKey$"", sExtendedDescriptionKey End If ``` It starts by checking the current ExtendedDescriptionKey value to determine whether to grab the description from CI_Item or CI_ExtendedDescription. It then simply adds the description to itself, this was done purely for testing, i know you will be forming the description using your UDFs so modify as needed. It then sets ItemCodeDesc using only the first 30 characters and then checks if length is greater than 30, it will then use the WriteExtendedDescription method passing whatever the value is from ExtendedDescriptionKey, if it is blank or ""0000000000"", then it will create a new record with the next available key. It then retrieves that key with GetKey and uses SetValueNoValidate to set it in CI_Item. I really prefer not to use SetValueNoValidate but i could not find and methods or properties or flags to get it to accept the key returned after WriteExtendedDescription. I'm not an MD so i don't have access to UI class for Item Maintenance, wish i knew what it was doing in there.


  • 21.  RE: Looking to set a new Extended Description based on

    Posted 12-04-2018 18:51
    Had a revelation that although the bus object attached to the UI object behaves the way it does, it doesn't mean you can't get a new handle to CI_ItemCode_Bus in a Post-Write event. You can try this too. The prior script must be on the Pre-Write. This one must be on the Post-Write. ``` sItemCode = """" : oBusObj.GetValue ""ItemCode$"", sItemCode sExtendedDescriptionKey = """" : oBusObj.GetValue ""ExtendedDescriptionKey$"", sExtendedDescriptionKey If sExtendedDescriptionKey = """" Or sExtendedDescriptionKey = ""0000000000"" Then sItemCodeDesc = """" : oBusObj.GetValue ""ItemCodeDesc$"", sItemCodeDesc ElseIf oBusObj.ExtendedDescriptionBusiness <> 0 Then sItemCodeDesc = """" : oSession.AsObject(oBusObj.ExtendedDescriptionBusiness).GetValue ""ExtendedDescriptionText$"", sItemCodeDesc End If sItemCodeDesc = sItemCodeDesc & "" - "" & sItemCodeDesc nItemBus = 0 : nItemBus = oSession.NewObject(""CI_ItemCode_Bus"") If nItemBus <> 0 Then Set oItemBus = oSession.AsObject(nItemBus) oSession.AsObject(oItemBus.ScriptObject).DeactivateProcedure ""*ALL*"" If oItemBus.SetKey(sItemCode) = 1 Then oItemBus.SetValue ""ItemCodeDesc$"", sItemCodeDesc oItemBus.Write End If oSession.AsObject(oItemBus.ScriptObject).ActivateProcedure ""*ALL*"" oSession.DropObject nItemBus Set oItemBus = Nothing End If ```


  • 22.  RE: Looking to set a new Extended Description based on

    Posted 12-05-2018 06:16
    I will try this tomorrow. Thanks for taking another look!