Page 1 of 1

Set Invoice Date

Posted: Thu Jun 21, 2018 11:05 am
by bdutil
Can't get this to work if the field it's looking to is blank. Should just run default rule but it's returning an 'Expected Int64, got NoneType' Error.

def Invoice_Date_Value(args):

invoice = args.Context
order = args.Context.Root

if not invoice:
return

# Get the value for the Custom Fields
AddRevDate = Date(IOrderItem.GetProperty(invoice, 'AddlRevDate_#'))


if IOrderItem.GetProperty(invoice, 'AddlRevDate_#') is not None:
args.Value = AddRevDate

else:
args.RunDefaultRule()

Re: Set Invoice Date

Posted: Fri Jun 22, 2018 10:37 am
by BobRichards
The part generating the error was passing a None to Date(...). You got the AddRevDate from the custom field and that is what should have been in the if expression. Also, you never need to check if the Context is None - it can never be None.

Code: Select all

def Invoice_Date_Value(args):

    # Get the date from the Custom Field
    invoice = args.Context
    AddRevDate = IOrderItem.GetProperty(invoice, 'AddlRevDate_#')
    
    # If we got a date, use it.  Otherwise run Select rules.
    if AddRevDate is not None:
        args.Value = Date(AddRevDate)
    else:
        args.RunDefaultRule())