Scripting

Expand all | Collapse all

I am trying to figure how to update a CI_Item UDF

Alnoor Cassim

Alnoor Cassim06-27-2017 11:45

  • 1.  I am trying to figure how to update a CI_Item UDF

    Posted 06-22-2017 17:49
    I am trying to figure how to update a CI_Item UDF for Primary Vendor Lead Time that is mapped from the IM_ItemVendor's StandardLeadTime. It works fine when entering a new primary vendor and lead time for the item, but I can't get my script to update the UDF when I make changes to an existing Lead Time and accept out of the Item Vendors screen. I can update it with a Table Post-Read event, but that requires me to accept the item and then go back into it. I'd like to have the new Lead Time written to the CI_Item UDF when I accept out of the Item Vendors screen. Also, I can'r select to Post-Validate on ItemCode...shouldn't that field be there? Am I missing something simple? Here's the script, which is pretty basic: 'Reset Variables sItemCode = """" : sDiv = """" : sVendor = """" : nLeadTime = 0 oItemVendor = 0 : retVal = 0 retVal = oBusObj.GetValue(""ItemCode$"", sItemCode) retVal = oBusObj.GetValue(""PrimaryAPDivisionNo$"", sDiv) retVal = oBusObj.GetValue(""PrimaryVendorNo$"", sVendor) set oItemVendor = oSession.AsObject(oSession.GetObject(""IM_ItemVendor_bus"")) retval = oItemVendor.SetKeyValue(""ItemCode$"", sItemCode) retval = oItemVendor.SetKeyValue(""APDivisionNo$"", sDiv) retval = oItemVendor.SetKeyValue(""VendorNo$"", sVendor) retval = oItemVendor.Find() if retval = 1 then retval = oItemVendor.GetValue(""StandardLeadTime"", nLeadTime) retval = oBusObj.SetValue(""UDF_PRIMARY_VENDOR_LEAD_TIME"", nLeadTime) end if


  • 2.  RE: I am trying to figure how to update a CI_Item UDF

    Posted 06-22-2017 20:14
    If you are on version 2015 or greater, you could use a post-exit script on the dVendors panel in the Item Maintenance library and use the following script. This will be triggered anytime a user exits the Item Vendor panel. It then checks if the task type is a maintenance task. When it writes the value using SetValue, it is written to the same record in memory from the item maintenance object which means if they try to step off the record without saving, they will get the prompt to save the changes. if they hit cancel on the item maintenance screen, then the change will not be saved. --------------------------------------------------------- if oScript.Evaluate(""coSession'Security'TaskType$"") = ""M"" then sRetval = """" nRetval = 0 sPriVend = """" sPriVendDiv = """" sItemCode = """" nLeadTime = 0 set coItem = oSession.AsObject(oScript.Evaluate(""coItem"")) nRetval = coItem.GetValue(""PrimaryVendorNo$"", sPriVend) nRetval = coItem.GetValue(""PrimaryAPDivisionNo$"", sPriVendDiv) nRetval = coItem.GetValue(""ItemCode$"", sItemCode) set coItemVendor = oSession.AsObject(oScript.Evaluate(""_obj'coBusiness"")) nRetval = coItemVendor.SetKeyValue(""ItemCode$"", sItemCode) nRetval = coItemVendor.SetKeyValue(""APDivisionNo$"", sPriVendDiv) nRetval = coItemVendor.SetKeyValue(""VendorNo$"", sPriVend) nRetval = coItemVendor.Find() if nRetval = 1 then nRetval = coItemVendor.GetValue(""StandardLeadTime"", nLeadTime) nRetval = coItem.SetValue(""UDF_PRIMARY_VENDOR_LEAD_TIME"", nLeadTime) end if end if ---------------------------------------------------------


  • 3.  RE: I am trying to figure how to update a CI_Item UDF

    Posted 06-23-2017 01:04
      |   view attached
    Well done Mr S2 your Panel OnExit approach is brilliant! I made a few edits to yours to demo a few points and make the Find() on the Item Vendor table work. Contrary to common sense, for screens with certain types of grids, on a UI script you have to get a 2nd copy of the object.

    Attachment(s)



  • 4.  RE: I am trying to figure how to update a CI_Item UDF

    Posted 06-23-2017 10:32
    Thanks @AlnoorCassim for the tip about the UI object and grids. I also see the benefit in checking the SecurityAccess property too. Great stuff.


  • 5.  RE: I am trying to figure how to update a CI_Item UDF

    Posted 06-26-2017 21:07
    Thank you both! I will be looking at this tomorrow when I am back in the office to see if I can understand what each of you did so that I can learn the new functions rather than just copying and pasting.


  • 6.  RE: I am trying to figure how to update a CI_Item UDF

    Posted 06-27-2017 08:26
    I'm not sure if I am going to get the terminology correct, but this oScript.Evaluate....how can it be set to ""itself""? How can set coItem = Evaluate(""coItem"")? Can I assume this is like GetObject and is reaching out to find a match from the CI_ItemCode or ""parent"" table? Is ""coItem"" a user-defined label or an existing object name? And what does (""_obj'coBusiness"") mean? Is that the current object or panel that the user is accessing? Sorry if these are dumb questions, but I'm still a novice :)


  • 7.  RE: I am trying to figure how to update a CI_Item UDF

    Posted 06-27-2017 09:42
    Evaluate() and Execute() are intermediate/advanced concepts. Evaluate() means to get the value from a ProvideX variable. In this case, David knows that for Item Vendor screen (or any child screen of Item Maintenance) the internal object variable (not script variable) that points back to Item Maintenance, back to CI_Item is called coItem. By Evaluate(""coItem"") he does not have to do a GetObject or GetChildHandle because coItem (think of it as oItem) is already pointing back to the ItemCode you started from. In fact he could have said: Set oItem = oSession.AsObject(oScript.Evaluate(""coItem"")) Set means your assigning a VB object. David just happened to use the same coItem but oItem might make more sense for you. It could have been Set oPrudy ya know. Also in my version I substituted the _obj'coBusiness for the coBusiness that's passed into the script. Since your script starts out in Item Vendor Maintenance that's the object is referring to.


  • 8.  RE: I am trying to figure how to update a CI_Item UDF

    Posted 06-27-2017 09:45
    You beat me to it Alnoor ""coItem"" and ""_obj"" are the variable names for the objects at the ProvideX level. Typically, ""_obj"" is the same object handle as ""oBusObj"" in VBScript when you are running table or field event scripts. When the script is running on a UI event, it refers to the UI object, in this case, ""IM_ItemVendor_UI"". ""coBusiness"" is a local property of the UI object that points to the bus object associated with the UI object, in this case, ""IM_ItemVendor_Bus"". However, as Alnoor pointed out, it is better to get a new ""SVC"" handle to ""IM_ItemVendor"" instead because of the issue with the grid associated with the bus object. Although it worked in my testing on v2015, If Alnoor says there could be a problem, then I'm going to believe him. The ""Evaluate"" and ""Execute"" methods of the ""oScript"" object allow you to run ProvideX code. ""Execute"" simply executes the command whereas ""Evaluate"" will return the result of the ProvideX command. There are some properties and methods of objects that are ""Private"". These are only available to the object and can't be referenced in VBScript. Since the item is already in edit mode in this session of item maintenance, I thought it best to avoid getting a new handle to ""CI_ItemCode_Bus"" and writing a value to it since it may result in your changes in item maintenance not being saved. In other words, if you open item maintenance twice, load the same item in each, make a change in one, accept it. then try to make a change in the other and accept it, you should get a message saying the record has been changed by another user and the changes will not be saved. Because of that, it was necessary to the get object handle in memory that was pointing to the item code in item maintenance and the only way to do that I could think of was to use oScript.Evaluate since ""coItem"" is a local property of ""IM_ItemVendor_UI"". I hope this makes sense.


  • 9.  RE: I am trying to figure how to update a CI_Item UDF

    Posted 06-27-2017 09:58
    Thank you both so much for the time and effort to provide a working script but also to teach me how to use it!! Your attention is very much appreciated!


  • 10.  RE: I am trying to figure how to update a CI_Item UDF

    Posted 06-27-2017 11:45
    Good explanation David!


  • 11.  RE: I am trying to figure how to update a CI_Item UDF

    Posted 06-27-2017 20:02
    So does oSecurity.TaskType = ""M"" test for a Maintenance session? Where are these documented?


  • 12.  RE: I am trying to figure how to update a CI_Item UDF

    Posted 06-27-2017 20:22
    Yes. Open the SU.CHM and search on Sy_Task or Task Type in quotes. Or it could be under that heading in the Object Reference CHM the material that comes with the Sage BOI course. I can copy / paste here if you don't find.


  • 13.  RE: I am trying to figure how to update a CI_Item UDF

    Posted 06-27-2017 20:42
    i found it documented in the built in help > file layouts and program information > object reference > base system > sy_secuirty