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

  • What is this column used for? Could you use a Hyperlink or Picture column instead? It has a default URL validation – Gintas K Feb 23 '17 at 10:00
  • yes you can use Hyperlink or Picture type. Explicitly if you want to use other text column. you better use single line of text and keep column validation for it for multi line text box you cannot keep validation by out of box feature instead you have to go for event recievers to keep the validation – Suresh Bolineni Feb 23 '17 at 10:30
  • normal URL column type accepts only 255 characters. If the URL exceeds more than 255 characters it throws an error so I have changed URL type to multiline text – Jeeva Jeyapaul Feb 24 '17 at 12:04
  • This won't help much but I was demo'd the Infowise Ultimate Forms this past week and it does stuff like this ... enhance text field support for email, phone, url etc... Reasonable licensing albeit not cheap :) – thastark Feb 24 '17 at 20:12

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:

  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.

| improve this answer | |

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.