How to update and delete items from another list?
Last Update: June 22, 2018
In this scenario, we will describe how to update and delete items from a list named "States" from within "Countries" list. Here are the steps on how to do that:
- Open the form in
design mode.
- Press on Auto Populate icon in the View Group in the Form Ribbon.
- Add a Repeater control to the form design workspace.
- Add 2 labels, 3 textboxes and 2 buttons controls inside the repeater as appear in the following screenshot:
- Select an empty space in the form design workspace to add a new Form Rule.
- In the
Rules pane, click on the Add icon to add a new rule, the
Rule Manager dialog will open.
- Add a new rule as follows:
A. Update the
Rule Name as desired.
B. Change the
Rule Type to Action.
C. Keep the
Event Type onLoad.
D. In the
Action section, type the following script:
populateRepeaterFromList(Repeater1, '/', 'State', "<Query><Where><Eq><FieldRef Name='CountryCode'/>
<Value Type='Text'>" + getValue(txtCountryCode) +"</Value></Eq></Where></Query>",
['ID', 'CountryCode', 'StateCode', 'StateName'], ['txtStateID', 'txtCountryCode', 'txtStateCode', 'txtStateName']);
E. Click on the
Save button to save the rule.
Note: You can use
Assistance Panel to help you adding functions and related parameters, form variables and form controls to
Conditions and/or
Actions sections. - Select the btnDeleteState button control.
- In the
Rules pane, click on the Add icon to add a new rule, the
Rule Manager dialog will open.
- Add a new rule as follows:
A. Update the
Rule Name if desired.
B. Change the
Rule Type to Action.
C. Change the
Event Type to onClick.
D. In the
Condition section, type the following:
getValue(txtStateID) != ''
E. In the Action section, type the following script:
var status = deleteListItems('/', 'State',
"<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + getValue(txtStateID) +"</Value></Eq></Where></Query>" )
if (status == true){
alert('The item has been deleted successfully')
}
F. Click on the
Save button to save the rule. - Select the btnUpdateState button control.
- In the
Rules pane, click on the Add icon to add a new rule, the
Rule Manager dialog will open.
- 13. Add a new rule as follows:
A. Update the Rule Name if desired.
B. Change the Rule Type to Action.
C. Change the Event Type to onClick.
D. In the Condition section, type the following:
getValue(txtStateID) != ''
E. In the Action section, type the following script:
var status = updateListItems('/', 'State',
"<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + getValue(txtStateID) +"</Value></Eq></Where> </Query>",['StateCode', 'StateName', 'CountryCode'], [getValue(txtStateCode), getValue(txtStateName), getValue(txtCountCode)])
if (status == true){
alert('The item has been updated successfully')
}
F. Click on the Save button to save the rule. - Publish the form by clicking on the Publish button in the Publishing Group in the Form Ribbon.
- Test the form by clicking on an existing item in the list.
Related Resources:
These resources may not reflect the same exact case steps.
https://www.youtube.com/embed/8ckDRORV3gQ