Access taxonomyclientservice.asmx from Javascript

This article describes how to access taxonomyclientservice.asmx from Javascript

1. Get the term set Guidby the follow powershell script

#Get the Site Collection
$SiteCollection = Get-SPSite http://Moss  #Change to you site URL
 
#Get the Term Store ID
$TaxSession = Get-SPTaxonomySession -Site $SiteCollection
$TermStore = $TaxSession.TermStores["Managed Metadata Service"] #Change to your service name
$TermStore.Id
#Get the Term Set ID
$TermStoreGroup = $TermStore.Groups["Corporate Taxonomy"] #Change to your Terms Store name
$TermSet = $TermStoreGroup.TermSets["Department"] #Change to your term set name
$TermSet.Id


 

2.  Create the soap Envelope for methodGetChildTermsInTermSet:

function CreateEnvelopeForTemsInTermset(sspId, lcid, termSetId) {
			        var soapXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
				"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
				"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
				"xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">" +
				"<soap12:Body>" +
				"<GetChildTermsInTermSet xmlns=\"http://schemas.microsoft.com/sharepoint/taxonomy/soap/\">" +
				"<sspId>" + sspId + "</sspId>" +
				"<lcid>" + lcid + "</lcid>" +
				"<termSetId>" + termSetId + "</termSetId>" +
				"</GetChildTermsInTermSet>" +
				"</soap12:Body>" +
				"</soap12:Envelope>";

			        return soapXml;
			    };


3.  Call the taxonomyclientservice.asmx

// first GUID is the $TermSet.Id, the second GUID is $TermStore.Id
			        var soapxml = CreateEnvelopeForTemsInTermset("48631c02-5c23-4021-b2d3-0b506d6e5649", 1033, "ae0bce8c-5251-402a-aa9a-344d73473459");
			        $.ajax({
			           url: "http://moss/_vti_bin/taxonomyclientservice.asmx",
			            type: "POST",
			            dataType: "xml",
			            data: soapxml,
			            complete: processResult,
			            contentType: "text/xml; charset=\"utf-8\""
			        });


4. Process the responseText which return from taxonomyclientservice.asmx

function processResult(xData, status) {

			        var strA32 = xData.responseText.split('T a9=');
			        var count = strA32.length;
			        var terms = new Array(count - 1);
			        for (var i = 1; i < count; i++) {
			           // get a32 , a31, a31 is ture means the lable is the default one
			            var splitA32 = strA32[i].split('a32');
			            for (var j = 1; j < splitA32.length; j++) {
			                var temp = splitA32[j].split('a31');
			                terms[i - 1] = temp[0].replace('=', '');
			                terms[i - 1] = terms[i - 1].replace('\"', '');
			                terms[i - 1] = terms[i - 1].replace('"', '');
			                terms[i - 1] = trim(terms[i - 1]);

			                // Get the value for a31
			                var a31Value = temp[1].substring(0, 8);
			                if (a31Value.indexOf('true') != -1) {
			                    break;
			                }
			            }
			        }
			        
			    }


 

5. Get data from custom list

context = new SP.ClientContext.get_current();
			            var currentSite = context.get_site();
			            context.load(currentSite);
			            web = currentSite.openWeb('web');
			            context.load(web);

var sList = web.get_lists().getByTitle('listName');
			                var sQuery = "<View><Query><Where><Eq><FieldRef Name=\"_ModerationStatus\" /><Value Type=\"ModStat\">0</Value></Eq></Where></Query></View>";

			                var sCamlQuery = new SP.CamlQuery();
			                sCamlQuery.set_viewXml(sQuery);

			                this.sponsorshipsCollection = sList.getItems(sCamlQuery);
			                context.load(this.sponsorshipsCollection, 'Include(ID,filedName1,filedName2,filedName3,filedName4,filedName5)');
			                context.executeQueryAsync(Function.createDelegate(this, this.CallBack), Function.createDelegate(this, this.fail));


 

 

 

你可能感兴趣的:(JavaScript,service,Access,SOAP,encoding,powershell)