1

I have a custom form on a SharePoint page that is intended to add and update list items. I want to validate values before updating. I found both the SP.ListItem.validateUpdateListItem and the SP.Field.validateSetValue functions, but they validate and update simultaneously. If I'm calling SP.ListItem.validateUpdateListItem on a set of SP.ListItemFormUpdateValues, even if any fail validation, the field values that passed validation have updated on the list item.

Is there any way to just validate without updating?

0

if you are using custom form to add/ update list item why don't you go with custom JSOM function like

function onBtnClick(){
 if(validate){
 updateListItem(itemId);
}

}
function validate(){
  //your validation logic
  return true;

}

function updateListItem(itemId) {

var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('My List');

this.oListItem = oList.getItemById(itemId);

oListItem.set_item('MyField', 'My Updated Field Value');

oListItem.update();

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {

alert('Item updated!');
}

function onQueryFailed(sender, args) {

alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
  • Thanks for your suggestion, but this approach would require me to duplicate all validation logic that is specified in list settings, and hardcode it into the javascript. This is problematic because I want this to work for multiple lists and automatically work when columns or validation rules on the lists change. I just want to use the API to validate, but not update any field if validation fails on anything. – broken-e Oct 18 '17 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.