Check the value in metadata field

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

20 Apr 2017

I am trying to do a check on managed metadata field, but can't make it work. Please, help me. I am using this code:

function setSSRoles() {
if (fd.field('Facility').control()._el().find('.ms-taxonomy').value() == 'E001 - Corporate') {
alert('Corporate');
}
}
fd.field('Facility').change(setSSRoles);
setSSRoles();

And i tried to put the whole GUID line into value() == as well

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

21 Apr 2017

Hi,
Please, read the thread:
viewtopic.php?f=1&t=615

Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

21 Apr 2017

Yes, I've read it... my alert doesn't come at all: even if the value is already there, not just on change; and I don't know how to check specific value of a field... I'll re-read again, maybe I'm missing something...

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

24 Apr 2017

The code below shows an alert box when a user changes a taxonomy field:

Code: Select all

var container = fd.field('InternalName').control()._el().find('.ms-taxonomy').get(0);
container.JavascriptOnValidation = "alert('Managed metadata changed!')"; 

Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

24 Apr 2017

I don't really need to check it on change: i need to check if a certain text is there -> if the field = X. I don't actually need to check on change as this is on Edit form already.

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

25 Apr 2017

The following code returns all tags with their identifiers. Then you can check if a particular value is there with the indexOf function: https://www.w3schools.com/jsref/jsref_indexof.asp

Code: Select all

var container = fd.field('Tags').control()._el().find('.ms-taxonomy').get(0);
var taxCtlObj = new Microsoft.SharePoint.Taxonomy.ControlObject(container);
var termValue = taxCtlObj.getRawText();
viewtopic.php?f=1&t=615

Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

02 Jun 2017

Sorry, i haven't replied to this: it works fine! Thank you very much!
One thing only - i have it on my edit form and if i make matadata field read only the code stop working....

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests