سؤال

I have created the list with fields like Title(single line text), URL(multiline text).I want to set custom url validation for URL column. how to achive this in powershell

هل كانت مفيدة؟

المحلول

Sorry to be the bearer of bad news but what you're asking to do is impossible given the current state of SP code.

The SP.FieldMultiLineText does not support server side validation. So while both ValidationFormula and ValidationMessage are RW according to SP REST documentation, and in theory could be set via Powershell, SP tosses the attached error when you try to set the value:

"This field type does not support validation formulas."

Error message

To test this, reference jQuery on a page and modify/paste the following JS into the console to update both the ValidationFormula & ValidationMessage properties:

$.ajax({
  url: "https://TENANTNAME.sharepoint.com/_api/Web/Lists(guid'XXLISTGUIDXX')/Fields(guid'XXURLFIELDGUIDXX')",
  type: "POST",
  data: "{ '__metadata': { 'type': 'SP.FieldMultiLineText' }, 'ValidationFormula': '=LEN(Title) > 2', 'ValidationMessage': 'The title field must be longer than 2 characters' }",
  headers: {
    "X-RequestDigest": $('#__REQUESTDIGEST').val(),
    "content-type": "application/json;odata=verbose",
    "content-length": 166,
    "X-HTTP-Method": "MERGE"
  },
  success: function(){alert("been done did well man");},
  error: function(a,b){alert("error");debugger;}
});

The debugger statement will be triggered and you can inspect the result.

I'd do this using a JSLink on the field (which you could modify the above script to append). The JSLink would run client side and validate the field on your behalf. Here is a decent reference for you: http://julieturner.net/2015/08/jslink-validation-from-basic-to-advanced/

As the server is guaranteed not to validate the request, you could also use workflows if absolutely necessary (retro validation) but IMO a crazy solution.

Best of luck.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top