Data Providers
...
REST
Create an app using REST APIs

Update customer details (PUT)

8min
scenario add the ability to update a customer's details by pressing on the customer in the list customers (get) docid 1o2k7 ccuvzfbg7x7f4r2 which loads that specific customer's details in a form you can edit the fields and press the update customer button how does this work the customer details are loaded using the customer id as the inputs from the list customer {{jig}} an update function to call the rest apis put operation is configured the function and function parameters are referenced in the execute entity action in the {{jig}} , which will update the customer's details when the update customer button is pressed on the form a post operation is performed in the rest service this code sample builds upon the previous list customers (get) docid 1o2k7 ccuvzfbg7x7f4r2 step, to develop a complete and functional solution rest api rest detail url https //\[your rest service]/api/customers operation/method put function the rest apis put operator is used in a {{jigx}} function with body parameters to specify the exact columns to be updated for the record the inputtransform specifies how the data should be structured or formatted when being sent to the rest service this transformation process ensures that the data adheres to the expected schema or format required by the rest service for processing the request rest update customer jigx provider data provider rest method put #updates data in the rest service url https //\[your rest service]/api/customers #use your rest service url uselocalcall true #direct the function call to use local execution between the mobile device and the rest service format text parameters accesstoken location header required true type string value service oauth #use manage jigx com to define credentials for your solution id type int location body required true firstname type string location body required true lastname type string location body required true companyname type string location body required true address type string location body required false city type string location body required false state type string location body required false zip type string location body required false phone1 type string location body required false phone2 type string location body required false email type string location body required false web type string location body required false region type string location body required false customertype type string location body required false jobtitle type string location body required false \#define the customer data that must be updated in the record in the rest service inputtransform | { "custid" id, "firstname" firstname, "lastname" lastname, "companyname" companyname, "address" address, "city" city, "state" state, "zip" zip, "phone1" phone1, "phone2" phone2, "email" email, "web" web, "region" region, "customertype" customertype, "jobtitle" jobtitle } action (global) create a load data jigx file under the actions folder this file is configured with an action that syncs the data from the rest service, by calling the function, to the local sqlite table the action file is referenced in the index jigx file to load the data when the app is opened or is in focus on the device load data jigx # the sync entities action is used to get the data from the rest data provider using the function \# the global action can be referenced throughout the solution for effieicency and performance \# the data is synced from the rest data provider to a local data provider on the device action type action sync entities options provider data provider rest entities \ entity customers function rest get customers \ entity us states function rest get usstates jig (screen) on the list of customers jig configure an on press action in the swipable left event that adds the view button to the list and links to the update customer {{jig}} add a form component to load the customer details with each field's instanceid containing the same name as the body parameters in the function for the state field configure a dropdrown with an expression to get the list of states for selection configure an initialvalue property for each field in the form using an expression to return the customer data for that field add an execute entity action to call the function that will update the customer record in the local table (using method update ) and in the rest service ( function rest update customer ) use an expression to specify the value for each of the function's parameters note that the customer id already exists and the expression for id uses the inputs again to specifiy the customer record that must be updated update customer jigx 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 \#use static datasource as the data is predefined and will not change 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 \#define the data to use in the jig, the data has been synced by the global action to the local data provider from the rest service 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 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 #action to update the record options title update customer provider data provider rest entity customers method update #update the record in the local sqlite table function rest update customer #update the record in the rest service functionparameters #define the data to be updated for the record 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 onsuccess type action go back list customers jigx title global customers type jig list icon global accelerator 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 \# specify the local datasource ask renier datasources 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, '$ logo') as logo from \[customers] as cus \ order by \ json extract(cus data, '$ companyname') data =@ctx datasources customers item type component list item options title =@ctx current item companyname subtitle =@ctx current item firstname & ' ' & @ctx current item lastname leftelement element avatar text =@ctx current item state uri =@ctx current item logo label title =$uppercase((@ctx current item customertype = 'silver' ? @ctx current item customertype @ctx current item customertype = 'gold' ? @ctx current item customertype '')) color \ when =@ctx current item customertype = 'gold' color color3 \ when =@ctx current item customertype = 'silver' color color14 \# add the onpress event to the customer list to view & update customer details onpress type action go to options linkto update customer parameters customer =@ctx current item \# add the swipeable event to the customer list to delete customer swipeable left \ label delete icon delete 2 color negative onpress type action confirm options isconfirmedautomatically false onconfirmed type action execute entity #action to execute the delete options \#use the rest data provider to call the delete function provider data provider rest entity customers method delete #delete the record from the local sqlite table goback stay function rest delete customer #delete the record from the rest service \#specifiy the function parameters required by the function to delete the customer, in this example custid functionparameters custid =$number(@ctx current item id) #id of customer record to be deleted in rest service data id =@ctx current item id #id of customer to be deleted from local data provider title are you sure? description =('press confirm to permanently delete ' & @ctx current item companyname) index for performance and offline support the data is synced from the rest service as soon as the app is opened or receives focus this is achieved by calling the global action in the onfocus and onload events index jigx name hello rest example title hello rest solution category sales \# onfocus is triggered whenever the jig is displayed the sync entities action in the global action calls the jigx rest function and populates the local sqlite tables on the device with the data returned from rest service onfocus type action execute action options action load data \# onload is triggered when the solution is loaded on the device the sync entities action in the global action calls the jigx rest function and populates the local sqlite tables on the device with the data returned from rest service onload type action execute action options action load data tabs home jigid list customers icon home apps logo