Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

Setting field values onload error.

$
0
0

Hi 

I'm cloning a record when a ribbon button is clicked. when the new form is open, Onload i'm setting field values. I was able to set lookup values but it doesn't work for text fields and optionset fields. I'm sure I did everything correct. please advice. 

Ribbon button code.

function OpenOption(PrimaryItemIds) {

    var urlParams = Xrm.Page.context.getQueryStringParameters();
    var windowOptions = {
        openInNewWindow: true
    };

    var parameters = {};
    var loadForm = false;
    parameters["new_cloneid"] = PrimaryItemIds;
    Xrm.Utility.openEntityForm("new_doc", null, parameters, windowOptions);

}


Onload: 

function fnOnLoadCopy()
{

    if (Xrm.Page.ui.getFormType() == 1 && (Xrm.Page.getAttribute("new_cloneid").getValue() != null)) {
        var urlParams = Xrm.Page.context.getQueryStringParameters();

        var windowOptions = {
            openInNewWindow: true
        };


        SDK.REST.retrieveRecord(
                             urlParams.new_cloneid,
                            "new_aisdocument",
                            null, null,
                            function (new_aisdocument) {
                                setFields(new_doc);

                            },
                              function () {
                                  alert("ERROR:new_doc
"); } ); //Xrm.Page.getAttribute(arg).setSubmitMode() Xrm.Page.data.entity.attributes.forEach( function (attribute, index) { Xrm.Page.getAttribute(attribute.getName()).setSubmitMode("always"); }); } }


For setting fields:

function setFormFields(new_doc) {
    debugger;


    if (new_doc) {
        var lookup = new Array();
        lookup[0] = new Object();
        lookup[0].id = new_doc.new_docId;
        lookup[0].name = new_doc.new_name;
        lookup[0].entityType = "new_doc";
        Xrm.Page.getAttribute("new_cloneid").setValue(lookup);


        //lookup fields
        if (new_doc.new_producttechnologyid != null && new_doc.new_producttechnologyid.Id != null) {
            lookup = new Array();
            lookup[0] = new Object();
            lookup[0].id = new_doc.new_producttechnologyid;
            lookup[0].name = new_doc.new_producttechnologyid.Name;
            lookup[0].entityType = "new_doc";
            Xrm.Page.getAttribute("new_producttechnologyid").setValue(lookup);
        }

        if (new_doc.new_opportunityId != null && new_doc.new_opportunityId.Id != null) {
            var lookup = new Array();
            lookup[0] = new Object();
            lookup[0].id = new_doc.new_opportunityId.Id;
            lookup[0].name = new_doc.new_opportunityId.Name;
            lookup[0].entityType = "opportunity";
            Xrm.Page.getAttribute("new_opportunityid").setValue(lookup);
        }

//text fields

        Xrm.Page.getAttribute("new_details").setValue(new_doc.new_details);
        Xrm.Page.getAttribute("new_specification").setValue(new_doc.new_specification);


        //OptionSet fields

        if (new_doc.new_docversion!= null) {
            Xrm.Page.getAttribute("new_docversion").setValue(new_doc.new_docversion.Value);     //OptionSet
        }

        if (new_doc.new_docvariance!= null) {
            Xrm.Page.getAttribute("new_docvariance").setValue(new_doc.new_docvariance.Value);     //OptionSet
        }
}
}


The lookup fields works good but the text and option set values won't populate. Please suggest. 

And there is a second issue : When I try to save the form an error is thrown, following is the log file: 

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.FormatException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #FEB0C267Detail:<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts"><ActivityId>26b43c06-b2f8-4659-a7ce-93ba6301b72f</ActivityId><ErrorCode>-2147220970</ErrorCode><ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" /><Message>System.FormatException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #FEB0C267</Message><Timestamp>2017-10-12T19:03:32.4749368Z</Timestamp><ExceptionRetriable>false</ExceptionRetriable><ExceptionSource i:nil="true" /><InnerFault i:nil="true" /><OriginalException i:nil="true" /><TraceText i:nil="true" /></OrganizationServiceFault>



Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images