Sharepoint online : Récupérer les noms de colonnes / champs d'un type de contenu via JSON

%3CLINGO-SUB%20id%3D%22lingo-sub-1036223%22%20slang%3D%22fr-FR%22%3ESharepoint%20online%3A%20Retrieve%20column%2Ffield%20names%20of%20a%20type%20of%20content%20via%20JSON%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1036223%22%20slang%3D%22fr-FR%22%3E%3CP%3EHello%26nbsp%3B%3C%2FP%3E%3CP%3Eto%20put%20it%20simply%20I%20created%20a%20type%20of%20content%20%22myCT%22%20for%20which%20I%20set%20fields%2Fcolumns.%26nbsp%3B%3C%2FP%3E%3CP%3EI%20also%20created%20a%20%22myLib%22%20document%20bookstore%20to%20which%20I%20associated%20the%20type%20of%20content.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20to%20create%20a%20search%20form%20that%20can%20find%20a%20lib%20document%20using%20the%20fields%2Fcolumn%20of%20the%20content%20type.%20For%20that%20I%20created%20a%20WebPart%20component.%20This%20component%20must%20generate%20a%20form%20on%20the%20fly%20(using%20javascript)%20that%20retrieves%20myCT%20data%20and%20can%20search%20for%20myLib...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20to%20recover%3A%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3Ethe%20name%20of%20the%20field%3C%2FLI%3E%3CLI%3EThe%20type%20of%20field%20used%3C%2FLI%3E%3CLI%3Ethe%20values%20given%20(in%20the%20case%20of%20the%20list%20of%20choices)%3C%2FLI%3E%3C%2FUL%3E%3CP%3EI%20discovered%20that%20to%20access%20all%20this%20information%20you%20could%20pass%20via%20an%20API%20remains%20in%20this%20kind%3A%20%3CA%20href%3D%22https%3A%2F%2Fmyappurl.sharepoint.com%2F_api%2Fweb%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FmyAppUrl.sharepoint.com%2F_api%2Fweb%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20concern%20is%20that%20I%20can't%20find%20the%20right%20entry%20point.%20I%20explored%20these%20URLs%20a%20little%20without%20success%3A%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fmyappurl.sharepoint.com%2F_api%2FWeb%2FContentTypes%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FmyAppUrl.sharepoint.com%2F_api%2FWeb%2FContentTypes%3C%2FA%3E%3C%2FLI%3E%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fmyappurl.sharepoint.com%2F_api%2FWeb%2FAvailableContentTypes%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FmyAppUrl.sharepoint.com%2F_api%2FWeb%2FAvailableContentTypes%3C%2FA%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3EI%20also%20tried%20another%20approach%20in%20javascript%20and%20trying%20to%20display%20the%20content%20type%20used%20with%20a%20nice%20script%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22kwd%22%3Efunction%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20getallContentTypes%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E()%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%7B%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3Evar%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20clientContext%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20SP%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EClientContext%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Eget_current%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E()%3B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%20%20%20oContentTypes%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20clientContext%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Eget_web%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E().%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Eget_contentTypes%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E()%3B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%20%20%20clientContext%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Eload%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3EoContentTypes%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E)%3B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%20%20%20clientContext%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3EexecuteQueryAsync%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22typ%22%3EFunction%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3EcreateDelegate%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3Ethis%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22kwd%22%3Efunction%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E()%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%7B%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3Evar%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20ctypesInfo%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22str%22%3E''%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3Evar%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20ctypesEnumerator%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20oContentTypes%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3EgetEnumerator%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E()%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3Ewhile%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3EctypesEnumerator%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3EmoveNext%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E())%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%7B%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3Evar%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20ocontentType%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20ctypesEnumerator%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Eget_current%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E()%3B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ctypesInfo%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2B%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22str%22%3E'%5Cn'%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%2B%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22str%22%3E'ContentType%20Title%3A%20'%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%2B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20ocontentType%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Eget_name%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E()%2B%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'%5Ct'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20ocontentType%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Eget_id%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E()%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22pun%22%3E%7D%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20console%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Elog%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3EctypesInfo%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3EtoString%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E())%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22pun%22%3E%7D)%2C%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22typ%22%3EFunction%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3EcreateDelegate%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3Ethis%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22kwd%22%3Efunction%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E()%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%7B%3CBR%20%2F%3E%20%26nbsp%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Econsole%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Elog%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'failed'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E)%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22pun%22%3E%7D))%3B%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22pun%22%3E%7D%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22kwd%22%3Efunction%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20injectMethod%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E()%7B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%20%20%20getallContentTypes%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E()%3B%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22pun%22%3E%7D%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22typ%22%3EExecuteOrDelayUntilScriptLoaded%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3EinjectMethod%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22str%22%3E%22sp.js%22%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E)%3B%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3EThis%20script%20had%20the%20effect%20of%20displaying%20my%20type%20of%20content%20and%20its%20id.%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CSPAN%3EContentType%20Title%3A%20myCT%200x0101007D18D0E5D0A176498869E2673AD0CA14%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3EI%20assumed%20that%20with%20this%20information%20we%20could%20access%20what%20I%20need%20via%20a%20REST%20claim%20like%20this%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%2F_api%2FWeb%2FContentTypes('0x010100ED0CEB986D733A47AD45D9A995911BAA')%2FFields%3C%2FPRE%3E%3CPRE%3E_api%2Fweb%2FAvailableContentTypes%3F%24select%3DName%2CId%2CStringId%26amp%3B%24filter%3DName%20eq%20'myCT'%3C%2FPRE%3E%3CP%3EUnfortunately%2C%20it%20doesn't%20really%20work.%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20help.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1036223%22%20slang%3D%22fr-FR%22%3E%3CLINGO-LABEL%3ESharePoint%20online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

Bonjour, 

pour faire simple j'ai créée un type de contenu "myCT" pour lequel j'ai défini des champs / colonnes. 

J'ai aussi créée un librairie de document "myLib" à laquelle j'ai associé le type de contenu. 

 

Je dois créer un formulaire de recherche qui puisse trouver les documents d'une lib en utilisant les champs / colonne du type de contenu. Pour ça j'ai créée un composant WebPart. Ce composant doit générer un formulaire à la volée (en utilisant javascript) qui récupère les datas de myCT et qui puisse effectuer une recherche sur myLib...

 

J'ai besoin de récupérer : 

  • le nom du champ
  • le type de champ utilisé
  • les valeurs données (dans le cas de liste de choix)

J'ai découvert que pour accéder à toutes ces informations on pouvait passer via un API rest dans ce genre là : https://myAppUrl.sharepoint.com/_api/web/

 

Mon soucis est que je n'arrive pas à trouver le bon point d'entrée. J'ai un peu exploré ces URL sans succès : 

J'ai tenté aussi une autre approche en javascript et en cherchant à afficher les content type utilisés avec un script sympathique : 

 

function getallContentTypes() {
    var clientContext = SP.ClientContext.get_current();    oContentTypes = clientContext.get_web().get_contentTypes();    clientContext.load(oContentTypes);    clientContext.executeQueryAsync(
        Function.createDelegate(this, function() {
            var ctypesInfo = '';
            var ctypesEnumerator = oContentTypes.getEnumerator();
            while (ctypesEnumerator.moveNext()) {
                var ocontentType = ctypesEnumerator.get_current(); 
ctypesInfo
+= '\n' + 'ContentType Title: ' + ocontentType.get_name()+'\t'+ ocontentType.get_id(); }
console.log(ctypesInfo.toString()); }), Function.createDelegate(this, function() {
 
console.log('failed'); })); } function injectMethod(){ getallContentTypes(); } ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");

Ce script a eu pour effet d'afficher mon type de contenu et son id. 

ContentType Title: myCT 0x0101007D18D0E5D0A176498869E2673AD0CA14

J'ai présumé qu'on pouvait avec ces informations là accéder à ce dont j'ai besoin via une requete REST dans ce genre : 

 

/_api/Web/ContentTypes('0x010100ED0CEB986D733A47AD45D9A995911BAA')/Fields
_api/web/AvailableContentTypes?$select=Name,Id,StringId&$filter=Name eq 'myCT'

Malheurement tout cela ne fonctionne pas vraiment. 

Merci pour votre aide. 

0 Replies