Search This Blog

Thursday, August 13, 2015

CRM integration: Change Folder Name in Sharepoint and CRM integration

If you have any doubt in the post please post comments. I will try to solve your problem.

When you add a document in sharepoint usually it pop up do you want to create a folder and save the file inside.
 If you click ok then folder will be create by the name of guid of the current record entity.
It is not user-friendly how to change the folder name?

By default there is no out of box feature to configure the folder. 

Solution:
When we open the document in the quote we are going to create folder name with quote id.

In the CRM website go to Tools\DocumentManagement. Open the areas.aspx file. In this file only folder will be create in the sharepoint.

 Mscrm.DocumentLocationHelper.autoCreateLocation(siteCollectionUrl, defaultLocationUrl, defaultLocationId, defaultLocationType, entityLogicalName, entityDisplayName, folderName, entityCentricPrimaryName, entityCentricEntityName, entityCentricPrimaryId, entityCentricEntityType);

The above mentioned method will going to create folder in sharepoint by default. In that method we are going to change the value of folderName parameter.

The red color code is the extra lines of code added in the existing method.

  <script type="text/javascript">
        function getParameterByName(name) {

            name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
            var regex = new RegExp("[\\?&]" + name + "=([^as&#]*)"),
                results = regex.exec(location.search);
            return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
        }

        function CreateOrSelectDocumentLocation() {
            debugger;

            if(typeof(autocreatelocation) != "undefined" && autocreatelocation)
            {
                document.getElementById("showProgress").style.display = "inline";

                if (typeof(defaultLocationUrl) != "string" || isNullOrEmptyString(defaultLocationUrl))
                {
                    Mscrm.DocumentLocationHelper.showNotification("LOCID_DOCM_SPLOC_INVALIDPARENT", "");
                }
                else
                {
                    //oId=Current record GUID
                    var strId=getParameterByName("oId");
                    strId=strId.slice(1,-1);
                    var strEntity="";

                    var strFilter="";
                    if(entityLogicalName=="quote")
                    {
                        strEntity="QuoteSet";
                        strFilter="$filter=QuoteId eq (guid'" + strId + "')";
                    }
                  //Get the quote number and assign in the folder name variable
                    XrmServiceToolkit.Rest.RetrieveMultiple(
                             strEntity,
                             strFilter,
                             function(result) {
                                 if (result != null && result.length > 0) {
                                     if(entityLogicalName=="quote")
                                         folderName = result[0].QuoteNumber;
                                 }
                             },
                             function() {},
                             function onReturn() {

                             },
                             false
                         );
                    Mscrm.DocumentLocationHelper.autoCreateLocation(siteCollectionUrl, defaultLocationUrl, defaultLocationId, defaultLocationType, entityLogicalName, entityDisplayName, folderName, entityCentricPrimaryName, entityCentricEntityName, entityCentricPrimaryId, entityCentricEntityType);
                }
            }
            else
            {
                var _locationId = <%= Microsoft.Crm.CrmEncodeDecode.CrmJavaScriptEncode(_locationId) %>;
                if (!IsNull(_locationId) && _locationId != "") {
                    var locationSelectorControl = $find("documentsGrid_DocumentLocationSelector");
                    locationSelectorControl.setSelectedLocationItemInMenu(_locationId);
                }
                else if(typeof(errorMessage) != "undefined")
                {
                    Mscrm.DocumentLocationHelper.showNotification(errorMessage, "");
                }
                else
                {
                    document.getElementById("errorMessageArea").style.display = "inline";
                }
            }
            
            if(document.getElementById("showProgress").style.display != "none")
            {
                var gridProgress=parent.document.getElementById("progress");
                if(!IsNull(gridProgress))
                {
                    gridProgress.style.display="none";
                }
            }
        }
</script>

2 comments:

  1. CRM Integration – Are you looking for best CRM integration services? If yes then we offer high quality and affordable CRM integration services all over the world. You can call us or mail us anytime 24x7.

    ReplyDelete

Note: Only a member of this blog may post a comment.