Monday, December 17, 2018

Adding Email Signatures with Image Hyperlink

Steps to include images hosted in Portal:
  1.   First Create a Image in a server which is accessible without any authentication.
  2.    If you have portal you can host it there with Admin role, go to the Home page of portal and  in Content Editor, select New à Child file.
  3. Give a Name to the image and browse the image which need to be included in the Email signature and save it. Note the Partial URL, as this will be used to navigate to the image.


4. To use this image as a hyper link in signature, go to home page of portal and select New à Child Page.


      5.  In the General Tab, give the name for Page, note down the Partial URL and select a blank template where image is visible.


            6. Next go to Language Content tab and select the Image icon in Copy section. This is to browse the image created in the previous steps.









7.  Then navigate to the Link tab and give the URL to which the image should link and click on OK.

  8. Image can be observed in Copy section, then save it.
9. Now navigate to the URL of the page created and copy the image.(This is Image with HyperLink)


10.  Now Navigate to Email Signatures in Settings > Templates and select Email Signatures.


11. Click on ‘New’ and give a title to the Email Signature.
12. Paste the image copied in previous steps in Email signature using Ctrl+V.
(Note:Use Internet explorer or Edge browser to copy and paste image in email signature body)

        13. Click on Save button and Set as Default button(optional). Insert Signature can be used on Email if it is not default.
14. After signature is saved and set as default, it will appear when a new email is created as below.


          15. The links can be tested after the email is sent.


NOTE: The images from other URL can be used like above if the image has referenced link without authentication.☺️




Monday, December 10, 2018

Trigger Workflow from CRM Portal


In this blog, you will learn how to trigger a workflow dynamically from a portal

If you have a requirement where workflow need to be triggered for more than one record in the background without entity grid button then this will be helpful.

The built in workflow trigger service lives at [portalUrl]/_services/execute-workflow/[portalscopeid]. You can invoke this service by performing a POST to this URL.

Step1 :  First note down the portalscopeid of your portal. If it is a customer portal then GUID value is 7B138792-1090-45B6-9241-8F8D96D8C372.


Step 2: Get the workflow GUID id which needs to be triggered.

Step 3:Copy the below code in Custom Javascript where workflow needs to be called

// JavaScript source code
var recordid = entityrecordid;// Pass the entity record guid for which workflow needs to be triggered                        
var wsid = portalscopeid; //As mentioned in step 1
var wfid = workflowid;// Workflow Guid value                   
if (typeof (wsid) !== 'undefined'&&wsid.length> 0 && typeof (wfid) !== 'undefined'&& wfid.length> 0)
{
var entity = { LogicalName: "entityname", Id: recordid };
var workflow = { LogicalName: "workflow", Id: wfid };
var payload = { entity: entity, workflow: workflow };
varjsonPayload = JSON.stringify(payload);
shell.ajaxSafePost(
        {
        type: "POST",
contentType: "application/json",
            url: "/_services/execute-workflow/" + wsid,
            data: jsonPayload
        }).done(function (msg)
        {
alert("Workflow executed");
        }).fail(function (msg)
        {
            alert("Danger");
        })
}


Step 4: This will trigger the workflow in the CRM.

The built-in services are hidden gems that could really streamline your customisation efforts. There are built-in support facilities that make invoking them relatively easy. You however need to consider your scenario carefully as these are not documented, and therefore may change without notice.

Below is the screenshot for such services which are defined in the RegisterArea method of the Site.Areas.Portal.PortalAreaRegistration class, which is defined in the file \Areas\Portal\PortalAreaRegistration.cs of the Portal project.


This is very useful when any out of box service need to be triggered from portal. ☺️

Sunday, December 9, 2018

Hide Out of box Delete Button in CRM

The visibility of Ribbon buttons are controlled by its associated command. Commands of these Buttons can be used to control the rules.
Using the Ribbon Workbench, it is easy to customize an 'Out of the Box' command and add a Display Rule  or Enable rule.

The answer to hide a Delete button based on any condition like user roles can be done as follows.

  1.  Load the custom entity of the button into the Ribbon Workbench.
  2. Select the button you want to modify. For example I have taken a DELETE button.


  3. Right click on button and select the “Customise Button” option.
  4. Notice a command is created for the button as Mscrm.DeletePrimaryRecord.
  5. Select that command and click on Add Enable Rule.
  6. In the Add Step select Custom rule for javascript control. Use this kind of rule to call a function in a JavaScript Library that returns a Boolean value.
  7.  Note:
    Custom rules that do not return a value quickly can affect the performance of the ribbon. If you have to perform logic that might take some time to complete, use the following strategy to make your custom rule asynchronous:
    ·         Define a rule that checks for a custom object. You might check for an object such as Window.ContosoCustomObject.RuleIsTrue that you just attach to the Window.
    ·         If that object exists, return it.
    ·         If that object does not exist, define the object and set the value as false.
    ·         Before you return a value, use settimeout to execute an asynchronous callback function to re-set the object. Then return false.
    ·         After the callback function has performed the operations that are required to determine the correct result, it sets the value of the object and uses the refreshRibbon method to refresh the ribbon.
    ·         When the ribbon is refreshed, it detects the object together with the accurate value set and the rule is evaluated.
  8. Give the function name and javascript webresource which evaluates your condition like checks Admin role  to show or hide the button and returns a Boolean value.
  9. When the function returns true the button will be visible on the form else hidden. Below is the code to check whether user is Administrator and returns a Boolean value.

//Javascript code
var roleNameArray = new Array();
var isAdmin= false;
function checkUserRole() {


var currentUserRoles = Xrm.Page.context.getUserRoles();

for (var i = 0; i<currentUserRoles.length; i++) {
var userRoleId = currentUserRoles[i];
getRoleName(userRoleId);

    }

if (roleNameArray.indexOf("System Administrator") > -1)
return true;
else
return false;
}
function getRoleName(userRoleId) {

var query = "name";
SDK.WEBAPI.retrieveRecord(userRoleId, "role", query, null, setRoleBasedSecurity, errorCallback);
}

function setRoleBasedSecurity(data) {

roleNameArray.push(data.name)
}
function hideDeletebn() {
isAdmin = checkUserRole();
return isAdmin;
}


Save and publish the Ribbon work bench.This will hide the Delete button for the users who doesn’t have Admin role.☺️


Show Sitemap Sub areas based on Security Roles

 I came across a requirement where we had to show the Sitemap certain areas only to the Application Admins and hide it from the Users. Yes i...