ecitsolutions / Autotask

A PowerShell module for Autotask Web Services API
MIT License
65 stars 18 forks source link

going a little nuts #88

Closed aciesler closed 4 years ago

aciesler commented 4 years ago

I'm not working with this correctly. I'm trying to work with UDF values. Say I've got a UDF called 'Location' for a contact and I want to set the UDF of Location to a specific UDF ID (get-atwsuserdefinedfieldlistitem -All)

set-atwscontact -lastname [name] -userdefinedfields ????

I honestly have looked for a couple days and I can't figure this one out. How do I set the user defined fields? Yes, I did get-command set-atwscontact -syntax and have been working with [-UserDefinedFields <UserDefinedField[]>] but it's kicking my butt.

bjowol commented 4 years ago

Hey,

UDF's are a bit of a pain. Ive had issues previously regarding setting multiple UDF values at the same time, so i had to apply one at a time. Not an issue right now though.

You can do this to create an item (or set) with multiple UDF values:

$Now = Get-Date

$Parms = @{
    StartDate                              = Get-Date -Day 1 -Month $Now.Month -Year $Now.Year -Hour 0 -Minute 0 -Second 0 -Millisecond 0
    EndDate                                = Get-Date -Day 1 -Month $Now.Month -Year ($Now.Year + 3) -Hour 0 -Minute 0 -Second 0 -Millisecond 0
    AccountID                              = $Group.Group[0].AccountID
    ContractName                           = 'TJENESTER - {0}' -f $Tag #{0} -f $group.Group[0].displayName
    ContractType                           = 'Recurring Service' #7
    Status                                 = 'Active'
    Description                            = 'asdfasfd.'
    ContractPeriodType                     = 'Monthly'
    ServiceLevelAgreementID                = 'Responstid 8 timer'
    BusinessDivisionSubdivisionIDasdfasf  = 15
    UserDefinedFields                      = [Autotask.UserDefinedField]@{Name = 'Kontraktsbeskrivelse'; Value = 'TJENESTER' }, [Autotask.UserDefinedField]@{Name = 'Firma'; Value = 'ESO' }
    TimeReportingRequiresStartAndStopTimes = 'false'
    SetupFee                               = '0'
}
$NewContract = New-AtwsContract @Parms

` When you set an UDF you can input an array of [Autotask.UserDefinedField], like above. I do believe the Name='x' is case sensetive.

bjowol commented 4 years ago

@aciesler Got it working? If not, feel free to write back.