Wednesday, June 8, 2016

Error: 400: Bad Request in MS CRM

Error: 400: Bad Request: Error processing request stream. The property name 'field_Name' specified for type 

'Microsoft.Crm.Sdk.Data.Services.field_Name' is not valid.

I had forgotten that I needed to specify the Schema name of the attribute and this is Case Sensitive. Once I had the case correct everything worked 

well again.

Error processing request stream. The property name 'new_Email' specified for type 'Microsoft.Crm.Sdk.Data.Services.Incident' is not valid.
check the field name in this. Check the Letters CASE

Validate Business Process Flow using Javascript

function AddStageHandlers() {
    Xrm.Page.data.process.addOnStageChange(StageChangedHandler);
}

function StageChangedHandler() {
    var activeStage = Xrm.Page.data.process.getActiveStage();
    var stageid = Xrm.Page.getAttribute("stageid").getValue();
    var peocessid = Xrm.Page.getAttribute("processid").getValue();
    var stageName = activeStage.getName();
    if (stageName == "BPF Stage Name") {
        if (Xrm.Page.getAttribute("optionsetattributename").getText() == "Yes") {
            if (Xrm.Page.getAttribute("attributename").getValue() == null) {
                //Previous stage ID
                Xrm.Page.data.process.movePrevious(function () { Xrm.Page.data.process.setActiveStage('stageid'); alert("All fields are Mandatory"); });
            }
            else {
                //Next stage ID
                Xrm.Page.data.process.moveNext(function () { Xrm.Page.data.process.setActiveStage('stageid'); alert("All fields are Mandatory"); });
            }
        }

        else {
            //Next stage ID
            Xrm.Page.data.process.moveNext(function () { Xrm.Page.data.process.setActiveStage('stageid'); alert("All fields are Mandatory"); });
        }
    };
}

How to set Optionset Valueby Text

function setOptionSetValueByText() {
    var optionText = Xrm.Page.getAttribute("statuscode").getText();
    var options = Xrm.Page.getAttribute("new_status").getOptions();
    for (i = 0; i < options.length; i++) {
        if (options[i].text == optionText) {
            Xrm.Page.getAttribute("new_status").setValue(options[i].value);
        }
    }
}

Fetch Child records in MS CRM

function fetchChildRecord() {
    var GUIDvalue = Xrm.Page.data.entity.getId();
    if (GUIDvalue != null) {
        //alert(GUIDvalue);
        var childRec = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                            "<entity name='contact'>" +
                            " <attribute name='fullname' />" +
                            " <attribute name='parentcustomerid' />" +
                            " <attribute name='telephone1' />" +
                            " <order attribute='fullname' descending='false' />" +
                            " <filter type='and'>" +
                            " <condition attribute='parentcustomerid' operator='eq'  value='" + GUIDvalue + "' />" +
                            " </filter>" +
                            "</entity>" +
                            "</fetch> ";

        var childRecords = XrmServiceToolkit.Soap.Fetch(childRec);
        if (childRecords.length > 0) {
            if (childRecords[0].attributes.status != undefined) {
                var StatusValue = childRecords[0].attributes.fullname.value;
                alert(childRecords[0].attributes.fullname.value);
                //return StatusValue;
            }
        }
    }
}

//Have to add the XrmServiceToolkit.js file 
//links to download the file xrmservicetoolkit/xrmservicetoolkit