Search on Different Font/Format of Text within UDF

SOLVED

I am attempting to search for certain phrases and maybe date formats within an UDF on the SO Header in order to populate separate UDF's.  I've had trouble before with the scripts not picking up the phrase if it is all capitalized and vise versa.  Is there a way to account for this or do you have to script for each possible variation. 

Example: I want to search for "New Hire" in the UDF_SHIPPINGMESSAGE and if found check off my UDF_NEWHIRE check box.  If a user types "NEW HIRE" then the script doesn't recognize the phrase.

Part two of the question: Date formats, is there a way to get the date from the UDF_SHIPPINGMESSAGE to populate a UDF Date field and account for all the different ways a user can enter a date format?

The data populating the UDF"s I am searching in is coming from an eCommerce free text field, that is why I can't standardize it.

Parents
  • 0

    Hi  

    For the UDF_ShippingMessage new hire part you should be able to use the UCase() function in your script.  Retrieve the value and then convert to uppercase, then you know you can check for "NEW  HIRE" regardless of how it was entered.  With the date portion it might be more difficult and you're likely going to have to search for multiple things, and I don't think VB has many mask search functions but I may be wrong.

    Do you have any control of the eCommerce site?  If you do, perhaps you could at least have some sort of help on the screen that indicates the format you want the date typed in?  If you don't have any control of the site, then you'll likely have to parse the string for separators such as "/" "-" and/or look for key words like "Jan", "Feb".  The other complication is if you have interntional folks typing in this date as well, because us Canadians usually use DD/MM/YY vs MM/DD/YY. 

    E

  • 0 in reply to jepritch

    For the UCase() function, would this be how you use in a script? I assume not because in my test it didnt work, the udf contained "NEW HIRE" but failed to check off the check box.

    rVal = 0
    sNewHire = ""
    searchString = "New Hire"
    
    rVal = oBusObj.GetValue("UDF_SHIPPINGMESSAGE$", sNewHire)
    
    If InStr(sNewHire, UCase(searchString)) then	
    	rVal = oHeaderObj.SetValue("UDF_NEWHIRE$", "Y")
    
    End If

  • 0 in reply to David Speck

    Still didn't get a correct output, this is the UDF field I am trying to check off, and used script exactly as David posted;

    Here is the raw data in JSON format

    "UDF_CoreOrderNumber": "8089972",
            "UDF_ExtraOrderInformation": "",
            "UDF_ShippingMessage": "NEW HIRE",
            "UDF_EXTCUSTPO": "",
            "PointsAmount": "0.00",
            "PoAmount": "259.35",
  • 0 in reply to jland47
    SUGGESTED

     what event do you have this attached too?  Are both the UDF_NewHire and UDF_ShippingMessage in the same table?  

    I just noticed you are using oBusObj.GetValue() to retrieve the value of UDF_ShippingMessage, but using oHeaderObj.SetValue() to update the UDF_NewHire.   This would indicate to me that this is attached to a SO Lines event (Pre-Write?) or something?  And the header has the UDF_NewHire.  Is that correct?

    E

  • 0 in reply to jepritch

    I have it set on the Sales Order Detail with a table-prewrite.  I think I see now, I was using other scripts I have as a guide but those scripts are looking on the SO details,  both of these fields are in the header.  Let me fix script/event trigger and see if that works

  • 0 in reply to jland47
    SUGGESTED

    If both fields are in the header table then the SetValue should use oBusObj. and not oHeaderObj.

  • 0 in reply to jepritch

    Ok, I am stumped, I've tried to place the trigger on both UDF's with column post/pre validate and even tried Table pre-write.  I've double checked spelling and used the fields from the add field to script button.

  • 0 in reply to jland47

    Still searching for answer, would any other script interfere with this, these other scripts work fine and I have no issues.

    .

  • 0 in reply to jland47

    Don't use the same priority for the same trigger.  That merges those scripts (and could cause unintended logic).

  • 0 in reply to jland47

    have you checked for results within your script?

    • does the script fire at all?  (do you have 'Allow External Access' set within Company maintenance)
    • does sNewHire have a value after retrieving it from the UDF_SHIPPINGMESSAGE$ field?
    • does the logic get to the SetValue() in your script?  (btw - hope you changed the oHeaderObj to oBusObj)
    • does the rVal return value on the SetValue() pass?  (should equal 1)
  • 0 in reply to jepritch

    Allow Ext Access is turned on and yes I have edited the script to use oBusObj.  I'll have to ask this question because I couldn't find the answer through browsing, how do you check the results of the script?  Is it a message box after each step or is there a log?

  • 0 in reply to jland47

    You can use message boxes to track progress through the script and print out variables used in the script.

    retVal = oSession.AsObject(oSession.UI).MessageBox("stuff")

    The above is the syntax for that.  You can put variables or expressions where "stuff" is, such as sNewHire etc.

Reply
  • 0 in reply to jland47

    You can use message boxes to track progress through the script and print out variables used in the script.

    retVal = oSession.AsObject(oSession.UI).MessageBox("stuff")

    The above is the syntax for that.  You can put variables or expressions where "stuff" is, such as sNewHire etc.

Children
  • 0 in reply to jepritch

    Not sure what happened but now that I put the message box on the script, the script works but I am not getting a message box.

    rVal = 0
    snewHire = ""
    searchString = "NEW HIRE"
    
    rVal = oBusObj.GetValue("UDF_SHIPPINGMESSAGE$", snewHire)
    rVal= oUI.MessageBox("",snewHire)
    
    If InStr(UCase(snewHire), UCase(searchString)) > 0 then
    		rVal = oBusObj.SetValue("UDF_NEWHIRE$", "Y")
    	
    End If

  • 0 in reply to jland47

    retVal = oSession.AsObject(oSession.UI).MessageBox("",snewHire)

  • 0 in reply to jepritch

    Would the message box be suppressed when a sales order is imported (through Insynch) into Sage? 

  • 0 in reply to jland47

    Not automatically.  Wrap your MessageBox in a filter to ensure it doesn't pop-up when you don't want it to.  For example:

    MAS_UI = False
    if oSession.UI <> 0 and oBusObj.FromScanForce <> 1 then
    	MAS_UI = True
    end if
    
    ...
    
    if MAS_UI then
    	retVal = oSession.AsObject(oSession.UI).MessageBox("","Words:  " & sStringVar)
    end if

    I'm not sure if the oSession.UI check works with Insynch, but you can test that.

  • 0 in reply to Kevin M

    If Insynch is using BOI, you should be able to check the ObjectInterface property of oSession.  

    If oSession.UI <> 0 And oSession.ObjectInterface = 0 Then 
        ' Safe to display message box. 
        oSession.AsObject(oSession.UI).MessageBox "", "Your message here." 
    End If 

  • 0 in reply to David Speck

    Another twist to this script, tried looking for a new text string, same script just different variables.  This started to cause Insynch to error, our orders wouldn't import because when sage would try to set the value of the field the script would fail.  According to ROI, the script is broken.

  • 0 in reply to jland47
    • Did you get the original script for the new hire string in the shipping message UDF working?
      • If not, can you confirm that all of the UDFs are on the header table?
        • If yes, then the script should be on the pre-write event of SO_SalesOrderHeader.
        • If no, it would help to know which UDFs are in which tables.
      • If yes and your latest reply is indeed for other scripts, I would check all scripts on SO_SalesOrderHeader and SO_SalesOrderDetail to see if you are using any MsgBox (should never be used by the way), MessageBox, or oScript.SetError in any of them without first checking that it is safe to do so.  SetError in a event beginning with "pre" will cause the action to fail without whatever message was passed to it.  MessageBox could be halting their process whenever the message box line is processed.
  • 0 in reply to David Speck

    It was working until we had the issue with Insynch, so I had to go and delete the script, also removed some scripts that had MsgBox on the SOHeader (they were tied to the salesperson field on the header).  Now I am back to testing every event to see if it works, so strange because it seems like a simple script.  The 2 UDF's are both on the Header table.  Only scripts on the Header now are SetValues, column post/pre validate, fields CustomerNo, ShipVia, UDF_DATE_ALLOCATED.

    rVal = 0
    snewHire = ""
    searchString = "new hire"
    
    rVal = oBusObj.GetValue("UDF_SHIPPINGMESSAGE$", snewHire)
    
    If InStr(UCase(snewHire), UCase(searchString)) then
    		rVal = oBusObj.SetValue("UDF_NEWHIRE$", "Y")
    	
    End If

  • 0 in reply to jland47

    As David said, never use VBScript's MsgBox command... always use the Sage MessageBox method.

    I don't think ROI has a flag you can test for, but wrapping your MessageBox in a simple StartProgram check might work.

    If oSession.StartProgram = "SO_SALESORDER_UI" Then

    ' your pop-up message here.

    End If