Wednesday 28 March 2012

Assembly must be registered in isolation

Xrm.Page.ui is null, Xrm.Page.data is null, Xrm.Page.data.entity.getId() is null for navigation subgrid javascript

I was trying to add enable role on ribbon button of a Entity B which is shown when I click on the navigation link of entity A. In the custom javascript I needed the Entity A id, and Xrm.Page.data.entity.getId() was not available,and same was the case with Xrm.Page.data and Xrm.Page.ui.

After doing bit of investigation, I found out that the javascript conext for ribbon bar is running in iframe of entity B, and to access the entity A values I have to use window.parent.Xrm.Page.data.entity.getId()


http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/8cfe6ff6-7569-48e2-b87e-359280204162/

Tuesday 20 March 2012

setting the id value to entity attribute and getting error "can not be null"

This is due to I was setting the attribute to Id rather then the entity reference object.

Thursday 15 March 2012

Update parent entity page

Added a subgrid of related entity on a Entity A form. When opening the related record from child I am updating some values on form and need to update the parent form. On child page add following jscript for custom button


window.parent.opener.parent.location.reload();
Xrm.Page.ui.close();

When sending email getting message "Some error occured"


When sending an email on change of ownership of record, I was getting error "some error occurred", to resolved it set the caller id "on behalf of" as below


            EntityReference callingUser = new EntityReference
            {
                LogicalName = "systemuser",
                Id = localContext.PluginExecutionContext.InitiatingUserId
            };

            OrganizationServiceProxy serviceProxy = (OrganizationServiceProxy)crmService;
            serviceProxy.CallerId = callingUser.Id;

Friday 9 March 2012

Microsoft.Crm.CrmException: The user Id is invalid

I successfully created a new crm organisation system, and when I tried to browse at the org, I was getting following error "Microsoft.Crm.CrmException: The user Id is invalid",

The issue was I was running the CrmAppPool with a domain account which was not the administrator/the user which I used to create crm organisation. As the apppool user was not present initially in the crm org users, I was getting above error, moved the crmapppool to network service, then recreated the org and then added the user and then added the updated the crmapppool user back to domain service/user.

Thursday 8 March 2012

ribbon is disabled when form navigation is used

Xrm.Page.ui.formSelector.items.get(formId).navigate( );

I used the form navigation in different scenarios, and It worked fine, however in the current scenario when I call
Xrm.Page.ui.formSelector.items.get(formId).navigate( ); when the form is reloaded I was getting error on page message, I am not sure about what was causing the issue, the patch I applied was setting the setTimeout function and then called the navigate function from it.

Wednesday 7 March 2012

Crm2011 using rest end point in javascript

I have an entity Subject, and related entity Result. when marks are set in subject. Result entity is reterived and all subjects of Result entities are reterived where subject is not droped. and finally Result entity overall marks are updated.

Add follwoing javascript files to entity on load event.
jquery1.4.1vsdoc, json2, JQueryRESTDataOperationFunctions and finally here is javascript to update related entity value depending on current values.

statuscode on Subject is either selected or droped. On form load call Loaded function and on form save call UpdateResultDetails.
As ajax call are made in order to complete given task select  "pass execution context as first parameter "in order to manually control saving and closing of form.

/// <reference path="jquery1.4.1vsdoc.js" />
/// <reference path="JQueryRESTDataOperationFunctions.js" />

var initialSubjectStatus;
var saveMode;
//used to stop recursive saving
var saveFlag = false; 

//initialises application status
function Loaded() {
    initialSubjectStatus = Xrm.Page.getControl("statuscode").getAttribute().getValue();
}

function UpdateResultDetails(ExecutionObj) {    
    if (Xrm.Page.data.entity.getIsDirty() && !saveFlag) {

        var applicationstaus = Xrm.Page.getControl("statuscode").getAttribute().getValue();

        //checks whether Subject status initially was selected or is currently is selected
        if (initialApplicationStatus == 161820001 || applicationstaus == 161820001) {
            if (ExecutionObj) {
                ExecutionObj.getEventArgs().preventDefault();

                //Save = 1, Save and Close = 2 , Save and New = 59 ...
                saveMode = ExecutionObj.getEventArgs().getSaveMode();
            }
            retrieveResult(Xrm.Page.getControl("publisher_resultid").getAttribute().getValue());
        }
    } else {
        saveFlag = false;
    }
}

function retrieveResult(idObj) {
    if (!idObj) {
        return;
    }

    retrieveRecord(idObj[0].id, "publisher_resultSet", retrieveResultCompleted, null);
}

//reterive subjects for specified result id
function retrieveSubjects(resultId) {

    if (Xrm.Page.data.entity.getId() == null) {
        //subject is selected
        retrieveMultiple("publisher_subjectSet", "?$filter=publisher_resultId/Id eq (guid'" + resultId + "')  and (statuscode/Value eq 161820001)", retrieveSubjectsCompleted, null);
     } else {
        //subject status is selected
        retrieveMultiple("cnova_subjectSet", "?$filter=publisher_resultId/Id eq (guid'" + resultId + "')  and (statuscode/Value eq 161820001) and not (publisher_subjectId eq (guid'" + Xrm.Page.data.entity.getId() + "'))", retrieveSubjectsCompleted, null);
    }
}

var vacancy;

function updateResult(numberOfSubjectsSelected) {
    if (!subject.publisher_TotalNumberOfSelectedSubjects) {
        return;
    }
    var remainingsubjects = subject.publisher_TotalNumberOfSelectedSubjects - numberOfSelectedSubjects;

    var applicationstaus = Xrm.Page.getControl("statuscode").getAttribute().getValue();
    if (applicationstaus == 161820001) {
        remainingsubjects--;
    }

    if (remainingsubjects < 0) {
        remainingsubjects = 0;
    }

    var changes = new Object();
    changes.publisher_RemainingNumberOfSubjects = remainingpositions;

    if (remainingsubjects > subject.publisher_TotalNumberOfSelectedSubjects) {
     subject.publisher_TotalNumberOfSelectedSubjects = remainingpositions;
    }

    updateRecord(result.publisher_resultId, changes, "cnova_resultSet", ResultUpdated, null);
}

function retrieveSubjectsCompleted(data, textStatus, XmlHttpRequest) {
    updateResult(data.length);
}

function retrieveResultCompleted(data, textStatus, XmlHttpRequest) {
    result = data;
    retrieveSubjects(result.publisher_resultId);
}

function ResultUpdated() {
    saveFlag = true;

    if (saveMode == 1) {
        Xrm.Page.data.entity.save(null);
    }
    else if (saveMode == 2) {
        Xrm.Page.data.entity.save("saveandclose");
    }
    else if (saveMode == 59) {
        Xrm.Page.data.entity.save("saveandnew");
    }
}


Hiding a Ribbon Button

Monday 5 March 2012

CRM Development Toolkit deploy error


Error 1 Error registering plugins and/or workflows. The resource string "ErrorSerializingRegFile" for the "RegisterPlugin" task cannot be found. Confirm that the resource name "ErrorSerializingRegFile" is correctly spelled, and the resource exists in the task's assembly. C:\Program Files (x86)\MSBuild\Microsoft\CRM\Microsoft.CrmDeveloperTools.CrmClient.targets 176 4 CrmPackage

Solution:
RegisterFile.crmregister file is checked in, Check out file manually.

Ignore a code block while debugging


[DebuggerStepThrough]

Friday 2 March 2012

add existing file in visual studio

To add an existing file in Visual Studio project however don't want to have a local copy of it, then select "Add existing file/item" and then select file, and select add as a link button

http://support.microsoft.com/kb/306234

base64


 public static string EncodeToBase64(string value)
        {
            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(value);

            return Convert.ToBase64String(bytes);
        }

        public static string DecodeFromBase64(string value)
        {
            byte[] bytes = Convert.FromBase64String(value)
            return System.Text.Encoding.ASCII.GetString(bytes);
        }

http://stackoverflow.com/questions/3355407/validate-string-is-base64-format-using-regex