More Messing about with Metadata
Because I refuse to give up on managed metadata.
I've got a solution I'm putting together where folks come and request training engagements for our clients. There's a lot to the form, but this is mostly about the managed metadata field serving up a list of classes. When you go select classes, you can select single classes or you can select a block of classes using a parent term. As an example:
- MMS <-- Single Class
- Encryption <-- Single Class
- PPM <-- Block of classes related to PPM
- PPM/Authorization <-- single class under PPM
- PPM/Relationships <-- single class under PPM
I think you get the idea. Basically I wanted to make it where users didn't have to go through one of those big blocks (and some of the parent terms have eighteen or nineteen child terms) and select each individual class in order to sign up for all the classes under that block.
Moving on to the problem. On save, I want to create a list item for each individual class selected for the engagement and assign it to the trainer that goes with that class. To do that, I need to:
- Go through whatever terms were selected in the metadata field;
- Head out to the term store and check if that term is a parent term or a child term;
- If it's a parent term, return a list of all that parent term's children.
- Go out to the map I've created else where and associate an individual term with its trainer.
Here's what I'm doing:
function createTrainingEngagements(){
//Get the selected terms.
var guids = document.getElementById('TrainingSubjects_$input').value.split(';');
//Render them as an array of guids.
guids = guids.map(function(term){
return term.split('|')[1];
});
//Iterate over the guids.
guids.map(function(guid){
getTermInfo(guid);
});
getTermInfo(guids);
}
function getTermInfo(guid){
//Get into the wonky SP JSOM.
var ctx = SP.ClientContext.get_current(),
session = SP.Taxonomy.TaxonomySession.getTaxonomySession(ctx),
stores = session.get_termStores(),
store = stores.getById('71ca97a990894ad5bab1b0ca86491269'),
set = store.getTermSet('ef70d0d5-b9db-48e0-8557-074f7a2a917b'),
term = set.getTerm(guid);
ctx.load(term);
ctx.executeQueryAsync(function(){
console.log(term.get_name());
console.log(term.get_termsCount());
});
}
This works fine for one of the terms. It does not return any information for the second term. I'm sure I'm doing something wrong with the way I'm handling the SP JSOM stuff.
Anyone got any ideas?
Posted Mar 12, 2018, 9:02 PM UTC