简体   繁体   中英

CRM Plugin get Title of a page in C#

I am creating a Plugin for CRM Which sets the Title of the page as First Name for Account Entity.

The desired result I have achieved the same by writing a javascript function on formload Event in CRM.

Following is the code

var titlename = Xrm.Page.data.entity.attributes.get("firstname").getValue();  
    var titleSpan = document.getElementById('form_title_div');  
     if(titleSpan) {  
        for(var i = 0;i < titleSpan.children.length;i++) {  
               if(titleSpan.children[i].className == 'ms-crm-Form-Title-Data autoellipsis') {  
                titleSpan.children[i].innerText = titlename;  
                 }  
          }  
     }

But my client don't want any javascript code instead he wants it thru Plugin .

I have written a plugin but don't know how to get and set the Title of the page.

Plugin project is a C# Class library .

Code is below for Plugin

Basically I want C# code for commented(Javascipt) Lines

using (var crm = new XrmServiceContext(service))  
{  
                var account = crm.ContactSet.Where(c => c.AccountId == id).First();  
                var titlename = contact.Crmp_Firstname.ToString();  
                //var titleSpan = document.getElementById('form_title_div');  
                //if(titleSpan) {  
                    //for(var i = 0;i < titleSpan.children.length;i++) {  
                        //if(titleSpan.children[i].className == 'ms-crm-Form-Title-Data autoellipsis') {  
                            //titleSpan.children[i].innerText = titlename;  
               //}  
          //}  
     //}  
}

Thanks in advance for any help

It is not possible to modify the title of an account form by a plugin. This because plugins act server side, instead JavaScript (and your account form) is executed client side. CRM doesn't store the title of the account, but generates it at runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM