title: Update Customer
type: jig.default
header:
type: component.jig-header
options:
height: small
children:
type: component.image
options:
source:
uri: https://www.dropbox.com/scl/fi/ha9zh6wnixblrbubrfg3e/business-5475661_640.jpg?rlkey=anemjh5c9qsspvzt5ri0i9hva&raw=1
datasources:
region:
type: datasource.static
options:
data:
- id: 1
region: US Central
- id: 2
region: US East
- id: 3
region: US West
customerType:
type: datasource.static
options:
data:
- id: 1
type: New
value:
- id: 2
type: Gold
value: Gold
- id: 3
type: Silver
value: Silver
customers:
type: datasource.sqlite
options:
provider: DATA_PROVIDER_LOCAL
entities:
- entity: customers
query: |
SELECT
cus.id AS id,
json_extract(cus.data, '$.firstName') AS firstName,
json_extract(cus.data, '$.lastName') AS lastName,
json_extract(cus.data, '$.companyName') AS companyName,
json_extract(cus.data, '$.address') AS address,
json_extract(cus.data, '$.city') AS city,
json_extract(cus.data, '$.state') AS state,
json_extract(cus.data, '$.zip') AS zip,
json_extract(cus.data, '$.phone1') AS phone1,
json_extract(cus.data, '$.phone2') AS phone2,
json_extract(cus.data, '$.email') AS email,
json_extract(cus.data, '$.web') AS web,
json_extract(cus.data, '$.customerType') AS customerType,
json_extract(cus.data, '$.jobTitle') AS jobTitle,
json_extract(cus.data, '$.region') AS region
FROM
[customers] AS cus
WHERE id = @custId
queryParameters:
custId: =@ctx.jig.inputs.customer.id
isDocument: true
children:
- type: component.form
instanceId: customer
options:
isDiscardChangesAlertEnabled: false
children:
- type: component.text-field
instanceId: companyName
options:
label: Company Name
initialValue: =@ctx.datasources.customers.companyName
- type: component.field-row
options:
children:
- type: component.text-field
instanceId: firstName
options:
label: First Name
initialValue: =@ctx.datasources.customers.firstName
- type: component.text-field
instanceId: lastName
options:
label: Last Name
initialValue: =@ctx.datasources.customers.lastName
- type: component.text-field
instanceId: jobTitle
options:
label: Job Title
initialValue: =@ctx.datasources.customers.jobTitle
- type: component.text-field
instanceId: email
options:
label: Email
initialValue: =@ctx.datasources.customers.email
- type: component.text-field
instanceId: phone1
options:
label: Mobile
initialValue: =@ctx.datasources.customers.phone1
- type: component.text-field
instanceId: web
options:
label: Web
initialValue: =@ctx.datasources.customers.web
- type: component.text-field
instanceId: address
options:
label: Street
initialValue: =@ctx.datasources.customers.address
- type: component.text-field
instanceId: city
options:
label: City
initialValue: =@ctx.datasources.customers.city
- type: component.field-row
options:
children:
- type: component.text-field
instanceId: state
options:
label: State
initialValue: =@ctx.datasources.customers.state
- type: component.text-field
instanceId: zip
options:
label: ZIP
initialValue: =@ctx.datasources.customers.zip
- type: component.field-row
options:
children:
- type: component.dropdown
instanceId: region
options:
label: Region
data: =@ctx.datasources.region
initialValue: =@ctx.datasources.customers.region
item:
type: component.dropdown-item
options:
title: =@ctx.current.item.region
value: =@ctx.current.item.region
- type: component.dropdown
instanceId: customerType
options:
label: Customer Type
data: =@ctx.datasources.customerType
initialValue: =@ctx.datasources.customers.customerType
item:
type: component.dropdown-item
options:
title: =@ctx.current.item.type
value: =@ctx.current.item.value
actions:
- children:
- type: action.execute-entity
# The best way to tell if a record has a temp ID is to use the following function
# =$isTempId(@ctx.jig.inputs.customer.id). If you have a record on the queue with
# a temp ID, you need to replace it with a new item that will be placed on the queue.
when: =$isTempId(@ctx.jig.inputs.customer.id)
options:
title: Update Customer
provider: DATA_PROVIDER_REST
entity: customers
method: create
goBack: previous
function: rest-create-customer
# Replace current create on the queue
queueOperation: replace
# Replace requires an id, if no id is specified in the parameter,
# use the data property to specify the id.
data:
id: =@ctx.jig.inputs.customer.id
firstName: =@ctx.components.firstName.state.value
lastName: =@ctx.components.lastName.state.value
companyName: =@ctx.components.companyName.state.value
address: =@ctx.components.address.state.value
city: =@ctx.components.city.state.value
customerType: =@ctx.components.customerType.state.value
email: =$lowercase(@ctx.components.email.state.value)
jobTitle: =@ctx.components.jobTitle.state.value
phone1: =@ctx.components.phone1.state.value
phone2: =@ctx.components.phone1.state.value
region: =@ctx.components.region.state.value
state: =@ctx.components.state.state.value
web: =$lowercase(@ctx.components.web.state.value)
zip: =@ctx.components.zip.state.value
parameters:
firstName: =@ctx.components.firstName.state.value
lastName: =@ctx.components.lastName.state.value
companyName: =@ctx.components.companyName.state.value
address: =@ctx.components.address.state.value
city: =@ctx.components.city.state.value
customerType: =@ctx.components.customerType.state.value
email: =$lowercase(@ctx.components.email.state.value)
jobTitle: =@ctx.components.jobTitle.state.value
phone1: =@ctx.components.phone1.state.value
phone2: =@ctx.components.phone1.state.value
region: =@ctx.components.region.state.value
state: =@ctx.components.state.state.value
web: =$lowercase(@ctx.components.web.state.value)
zip: =@ctx.components.zip.state.value
- type: action.execute-entity
when: =$not($isTempId(@ctx.jig.inputs.customer.id))
options:
title: Update Customer
provider: DATA_PROVIDER_REST
entity: customers
method: update
goBack: previous
queueOperation: replace
function: rest-update-customer
parameters:
id: =@ctx.jig.inputs.customer.id
firstName: =@ctx.components.firstName.state.value
lastName: =@ctx.components.lastName.state.value
companyName: =@ctx.components.companyName.state.value
address: =@ctx.components.address.state.value
city: =@ctx.components.city.state.value
customerType: =@ctx.components.customerType.state.value
email: =$lowercase(@ctx.components.email.state.value)
jobTitle: =@ctx.components.jobTitle.state.value
phone1: =@ctx.components.phone1.state.value
phone2: =@ctx.components.phone1.state.value
region: =@ctx.components.region.state.value
state: =@ctx.components.state.state.value
web: =$lowercase(@ctx.components.web.state.value)
zip: =@ctx.components.zip.state.value
data:
id: =@ctx.jig.inputs.customer.id
firstName: =@ctx.components.firstName.state.value
lastName: =@ctx.components.lastName.state.value
companyName: =@ctx.components.companyName.state.value
address: =@ctx.components.address.state.value
city: =@ctx.components.city.state.value
customerType: =@ctx.components.customerType.state.value
email: =$lowercase(@ctx.components.email.state.value)
jobTitle: =@ctx.components.jobTitle.state.value
phone1: =@ctx.components.phone1.state.value
phone2: =@ctx.components.phone1.state.value
region: =@ctx.components.region.state.value
state: =@ctx.components.state.state.value
web: =$lowercase(@ctx.components.web.state.value)
zip: =@ctx.components.zip.state.value