Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Pass the values into the form using Javascript

Posted on by Microsoft Employee

Hi Friends,
             i have posted a code here,

function createquote() {
     debugger;
    try {
        if (Xrm.Page.ui.getFormType() == 2) {
            var data = new XrmServiceToolkit.Soap.BusinessEntity("sss_quoteapp");
            data.attributes["sss_name"] = Xrm.Page.getAttribute("sss_name").getValue();
            if (Xrm.Page.getAttribute("sss_account") != null && Xrm.Page.getAttribute("sss_account").getValue() != null) {
                var sourceLookup = Xrm.Page.getAttribute("sss_account").getValue();
                //get details from source lookup

                var lookupValue = new Array();

                lookupValue[0] = new Object();

                lookupValue[0].id = sourceLookup[0].id;

                lookupValue[0].name = sourceLookup[0].name;

                lookupValue[0].entityType = sourceLookup[0].entityType;

               var e =  Xrm.Page.getAttribute("sss_account").setValue(lookupValue);
            }
            var parameters = {};
            parameters["sss_name"] = Xrm.Page.getAttribute("sss_name").getValue();
            parameters["sss_account"] = Xrm.Page.getAttribute("sss_account").setValue(lookupValue);
            var En = 0;
            En = XrmServiceToolkit.Soap.Create(data);
            Xrm.Utility.openEntityForm("sss_quoteapp", null, parameters);
        }
    }
    catch (e) {
       alter(e.message);
    }
}

In this i cant able to open the entity form 'quoteapp' , i dont Know where the error occurs .

Suggest a solution.

Thanks & regards

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Pass the values into the form using Javascript

    yes , thanks a lot it works bhuvanesh.

  • Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: Pass the values into the form using Javascript

    Hi

    Did you change the code to

    data.attributes["sss_account"].setValue(lookupValue);

    as suggested in my previous post?

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: Pass the values into the form using Javascript

    Did you use

    XrmServiceToolkit.Soap.sCreate(data);

    Please check the code of XrmServiceToolkit library. Do you have Create or sCreate within Soap object..

    (I can see XrmServiceToolkit.Soap.sCreate and XrmServiceToolkit.Rest.createRecord available.

    So, check the library code and use the right function.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Pass the values into the form using Javascript

    Thanks a lot for giving suggestion,

    But i get this error, while enters into create function,

    "The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter schemas.microsoft.com/.../Services:request. The InnerException message was 'Error in line 1 position 860. Element 'schemas.datacontract.org/.../System.Collections.Generic:value&; contains data from a type that maps to the name 'www.w3.org/.../XMLSchema:object&;. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'object' and namespace 'www.w3.org/.../XMLSchema&;.'.  Please see InnerException for more details."

  • joman Profile Picture
    joman 617 on at
    RE: Pass the values into the form using Javascript
     data.attributes["sss_account"]=Xrm.Page.getAttribute("sss_account").setValue(lookupValue);

    What is this code means?

    As i know (https://msdn.microsoft.com/en-us/library/gg334409.aspx#BKMK_setValue ) setValue(lookupValue)

    returns nothing.

    I think you wanted to make this:

    data.attributes["sss_account"]= lookupValue;
    Xrm.Page.getAttribute("sss_account").setValue(lookupValue);
  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: Pass the values into the form using Javascript

    Hi

    What happens when you use (just this line)

    data.attributes["sss_account"].setValue(lookupValue);

    Please check the name of the function in XrmServiceToolkit library (it could be sCreate)

    Use

    XrmServiceToolkit.Soap.sCreate(data);

    instead of

    XrmServiceToolkit.Soap.Create(data);

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Pass the values into the form using Javascript

    But by this code i can get the values  and one thing is i can't create entity.

    function createquote() {

        debugger;

       try {

           if (Xrm.Page.ui.getFormType() == 2) {

               var data = new XrmServiceToolkit.Soap.BusinessEntity("sss_quoteapp");

               data.attributes["sss_name"] = Xrm.Page.getAttribute("sss_name").getValue();

              if (Xrm.Page.getAttribute("sss_account") != null && Xrm.Page.getAttribute("sss_account").getValue() != null) {

                   var sourceLookup = Xrm.Page.getAttribute("sss_account").getValue();

                   //get details from source lookup

                   var lookupValue = new Array();

                   lookupValue[0] = new Object();

                   lookupValue[0].id = sourceLookup[0].id;

                   lookupValue[0].name = sourceLookup[0].name;

                   lookupValue[0].entityType = sourceLookup[0].entityType;

                  data.attributes["sss_account"]=

    Xrm.Page.getAttribute("sss_account").setValue(lookupValue);

               }

               var En = 0;

               En = XrmServiceToolkit.Soap.Create(data);

               Xrm.Utility.openEntityForm("sss_quoteapp", En, e);

           }

       }

       catch (e) {

          alter(e.message);

       }

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Pass the values into the form using Javascript

    "Cannot read property 'setValue' of undefined"

    This is what i get .

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: Pass the values into the form using Javascript

    Hi

    You have to change the following line:

    var e =  Xrm.Page.getAttribute("sss_account").setValue(lookupValue);

    to

    data.attributes["sss_account"].setValue(lookupValue);

    You do not need to pass any parameters, as these two values are already available in the record.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Pass the values into the form using Javascript

    doudt.PNG

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans