Wednesday, October 26, 2011

Open CRM Process Dialog using Javascript

Here, one of important thing is Process Dialog Id doesn't change if you export the solution to any environment.

Step 1
Include the below function to onLoad in the form

function RunMembershipPaidProcessDialog()
{
    //Set the process dialog Id below
    var dialogID = "%7b706886CB-FFAB-4ECC-967E-B457CBE8C2C1%7d";
 
    //Set the entity logical name
    var entityName = Xrm.Page.data.entity.getEntityName();

    //Get the current record Id
    var recordId = Xrm.Page.data.entity.getId();
    
    //Set the Process Dialog width & height
    var width = "550";
    var height = "450";
 
    LoadProcessDialog(dialogID, entityName, recordId, width, height);
}
Step 2 Create a Common Javascript resource file (if you havn't create yet) so you can add all the common javascript function in this web resource. and add the below function
function LoadProcessDialog(dialogID, entityName, recordId, width, height)
{
    var context = Xrm.Page.context;
    var sUrl = window.parent.location.href;
    sUrl = sUrl.substring(0, sUrl.indexOf('/main.aspx'));

    var fullUrl = sUrl + "/cs/dialog/rundialog.aspx?DialogId=" + dialogID + "&EntityName=" + entityName + "&ObjectId=" + recordId;

    ShowPopUpWindow(fullUrl, "newWindow", width, height);
}


function ShowPopUpWindow(url, title, w, h)
{
    var left = (screen.width/2)-(w/2);
    var top = (screen.height/2)-(h/2);
    var targetWin = window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);    
}

Monday, October 24, 2011

Custom width for columns in CRM Views

When you want to change width of a column in CRM view, CRM lets you to select the width from parameter set. These are the values you get.

25px, 50px, 75px, 100px, 125px, 150px, 200px, 300px

But sometimes, you have to give your own width.
Ex.
1.If there are only one or two columns in your width, you may need to give may be 500px for one column.
2. If you want to show many columns and if you are not like to show the horizontal scroll bar, instead of 200px and 300px, you may need to give 250px.

There is a solution for this.

Steps.
1. Publish your CRM solution.
2. Export the unmanaged solution.
3. Unzip the solution.
4. Open the Custermization.xml file (using XML viewable editor ex. Visual Studio).
5. Navigate to your entity Entities -> Entity -> SavedQueries -> savedqueries.
6. Find your view from the savedqueries.
7. Navigate to layoutxml -> grid
8. Now you can give any custom width to your columns
(
cell width="125" name="accountnumber"
cell width="500" name="name"
)

9. Save the Xml File

10. Zip the package

11. Import the solution

Tuesday, October 18, 2011

Creating a record using OData Service & JQuery

If you search in the net, you may find many examples of createing a record using OData Service & JQuery.
But in all these examples, you can see, that string values added to the entity object.
But how you are going to create a record which has a Lookup (Entity Refernce) value.

You can use following code


var entity = new Object();
entity.Subject = "subject goes here";
//Entity Reference (Also called as Lookup)
entity.RegardingObjectId = {
            Id: Xrm.Page.data.entity.getId(), 
            LogicalName: Xrm.Page.data.entity.getEntityName()
};

createRecord(
entity,
"new_entityNameSet",
 createAuditActionCompleted,
errorOnAuditCreate
);