Re: Is it possible to fire a script when creating a SO using a Repeating order

mmneal,

 

Yes it should be possible.  Where does the UDF live?  In the Sales Order Detail? or in the original Repeating Sales Order?

 

You can use the value of the repeating order stored in the header from within a lines script.

 

rptgOrder = ""

retVal = oHeaderObj.GetValue("MasterRepeatingOrderNo$", rptgOrder)

 

You can then use it to make decisions:

 

If rptgOrder<>"" Then

   

   ' you would have to further decide if this is a master order or repeating order if that is important to you.

   Set oSOChild = oSession.AsObject(oHeaderObj.GetChildHandle("MasterRepeatingOrderNo"))

 

   retVal = oSOChild.Find(rptgOrder)

   If retVal<>0 Then 

      type = ""

      retVal =oSOChild.GetValue("OrderType$", type)

      If type<>"R" Then

         rptgOrder = ""

     End If

   End If

   

   If rptgOrder<>"" Then

      ' calculate whatever date

   End If 

End If

 

 

Hope that helps.

Elliott

  • Hi Elloitt,

     

    I was going to have the UDF reside in the SO Detail. 

     

    I have been playing with the events for the SO Detail script with no luck.  Which type of event do you recommend for this type of script?

     

    thank you

    mmneal

  • Hi Elloitt,

     

    I was going to have the UDF reside in the SO Detail. 

     

    I have been playing with the events for the SO Detail script with no luck.  Which type of event do you recommend for this type of script?

     

    thank you

    mmneal

  • Here is the script that I am using.  I tested and yes the script fires when I create a sales order from a repeating order.  I used the Pre-Write Event.  Now the issue I am having is looping.   

     

    If I remove the line of code that is bold and underlined then my script runs.  If I have a repeating sales order that has multiple lines it only gives me the Days data from Inventory for the last item on the sales order.  The date still calculates for each item however the first item the date is 05-08-2013, and the date for the next item is correct.    How do I do the loop correctly to acquire the days from the inventory item?

     

    Thank you

     

    Dim sDays

    Dim rptgOrder

     

     

     

    retVal = oHeaderObj.GetValue("MasterRepeatingOrderNo$", rptgOrder)

    msgBox(rptgOrder)

     

     

    Set oLines = oBusObj.AsObject(oBusObj.Lines)

    oLines.MoveFirst

     

    Set oChild=oBusObj.AsObject(oBusObj.getChildHandle("ItemCode"))

     

    retVal=oChild.getValue("UDF_DAYS$",sDays)

     

    msgBox(sDays)

     

    oLines.MoveNext

     

     

     

    tmpDate = ""

    retVal = 0

     

    If rptgOrder>0 then

     

    retVal = oSession.FormatDate(oSession.ModuleDate, tmpDate, "%M/%D/%Y")

     

     

     tmpDate = DateAdd("d", sDays, tmpDate)

     

     tmpDate = oSession.GetFormattedDate(CStr(tmpDate))

     

     retVal = oBusObj.SetValue("UDF_SELL_BY_DATE$", tmpDate)

     

     

    exit sub

     

    end if

  • Hi mmneal,

     

    Just a few questions to isolate the intended purpose for this script.

     

    1) You want to calculate a date (UDF_SELL_BY_DATE$) for each line item, based on a # of days (UDF_DAYS) from the item file?

    2) You only want to calculate #1 if the order was created from a Repeating order?

    3) You only want to do this calculation when the order is created?

    4) If additional lines are added do we want this calculation performed?

     

    From your script it appears there could be some scope issues.  (When do I use oHeaderObj vs oBusObj vs oLines)  Unless this script is incomplete and I'm missing something.

     

    So, using the assumptions of: 

    • Script attached to the PRE-Write event of a Sales Order Line
    • Has to be from a Repeating order
    • Has to be only upon order creation

    Hope that makes sense.

    Elliott

     

     

    ' PRE-Write for SO_SalesOrderDetail_bus (Lines)
    
    Dim sDays
    Dim rptgOrder
    
    ' get repeating order number from the HEADER object 
    retVal = oHeaderObj.GetValue("MasterRepeatingOrderNo$", rptgOrder)
    
    msgBox(rptgOrder)
    
    If rptgOrder<>"" AND oBusObj.EditState = 2 Then ' oBusObj.EditState = 2 means we are ADDING a new line
    
        ' you would have to further decide if this is a master order or repeating order if that is important to you.
        ' get MasterRepeatingORder child handle from the HEADER object to lookup to see if order # is Mast/Rptg
        Set oSOChild = oSession.AsObject(oHeaderObj.GetChildHandle("MasterRepeatingOrderNo"))
     
        retVal = oSOChild.Find(rptgOrder)
        If retVal<>0 Then 
          orderType = ""
          retVal =oSOChild.GetValue("OrderType$", orderType)
          If orderType<>"R" Then ' NOT a repeating order
             rptgOrder = ""
          End If
        End If 
     
        If rptgOrder<>"" Then ' only need to do the rest if we have a repeating order
    
           ' Set oLines = oBusObj.AsObject(oBusObj.Lines)  'Commented out as we are working at the DETAIL level already
           ' oLines.MoveFirst
        
           ' Get child handle for the Item so we can retrieve # of days
           Set oItemChild=oBusObj.AsObject(oBusObj.getChildHandle("ItemCode"))
           retVal = oItemChild.GetValue("UDF_DAYS$",sDays)
     
           msgBox(sDays)
     
           ' oLines.MoveNext ' Comment out as we are already working at the DETAIL level
     
           tmpDate = ""
           retVal = 0
     
           ' If rptgOrder>0 then ' Commented out as above we made the decision we are already have a rptg order
     
           retVal = oSession.FormatDate(oSession.ModuleDate, tmpDate, "%M/%D/%Y")
           tmpDate = DateAdd("d", sDays, tmpDate)
           tmpDate = oSession.GetFormattedDate(CStr(tmpDate))
     
           retVal = oBusObj.SetValue("UDF_SELL_BY_DATE$", tmpDate) ' Set the value of our DETAIL LINE UDF
     
    end if