Text Above Tabs – Content Type

Home Forums Classic DFFS Text Above Tabs – Content Type

Viewing 2 reply threads
  • Author
    Posts
    • #20031
      Carrie Wheeler
      Participant

        I want to display the content type name above tabs in my newform. I have tried using {ContentType} but it shows just as this and not the name of the content type. The field ‘Content Type’ does show in my fields list and ‘ContentType’ does show as the FieldInternalname. Is content type not supported in the Text above tabs? Or perhaps I am using this option incorrectly?

      • #20045
        Alexander Bautz
        Keymaster

          Hi,
          The content type name is not accessible directly in NewForm, but if you are using SP 2013 / 2016 you can add this HTML to the “Show this text above the tabs”:

          <div id="contentTypeName"></div>

          And then add this to your Custom JS

          jQuery.ajax({
              url: _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getById('"+_spPageContextInfo.pageListId+"')/ContentTypes('"+GetUrlKeyValue("ContentTypeId")+"')",
              method: "GET",
              headers: {
                  "accept": "application/json; odata=verbose",
                  "content-type": "application/jsom;odata=verbose",
                  "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value
              },
              success: function (data) {
          	    jQuery("#contentTypeName").html(data.d.Name);		
              },
              error: function (err) {
                  // console.log(err);
              }
          });

          Alexander

        • #20049
          Carrie Wheeler
          Participant

            This code is working perfectly to bring in the name of the content type. It was wrapped in the curly brackets originally but I used your tip on another post to put in the “default” and it is now all sorted out. Thank You!!

        Viewing 2 reply threads
        • You must be logged in to reply to this topic.